private void checkIndexName() { CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(indexName) && !StringUtils.isNullOrEmpty(indexName.trim()), new IllegalIndexException("index name can not be empty")); CheckConditions.checkCondition(indexName.length() < CMSConsts.MAX_LENGTH_OF_INDEX_NAME, new IllegalIndexException("The length of index name can not be exceed " + CMSConsts.MAX_LENGTH_OF_INDEX_NAME)); CheckConditions.checkCondition(PATTERN.matcher(getIndexName()).matches(), new IllegalIndexException( "index name must be characters of [A-Za-z0-9_]*!")); }
private void checkMetaClassName(String name) { CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(name), new IllegalMetaClassException("meta class name can not be empty")); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(name.trim()), new IllegalMetaClassException("meta class name can not be empty")); CheckConditions.checkCondition(!(isSystem(name)), new IllegalMetaClassException("meta class name cannot begin with 'system.' prefix")); CheckConditions.checkCondition(containsValidCharacters(name,CMSConsts.INVALID_META_CLASS_NAME_CHARACTERS), new IllegalMetaClassException("meta class name cannot contains invalid characters: " + Arrays.toString(CMSConsts.INVALID_META_CLASS_NAME_CHARACTERS))); }
public void validate() { CheckConditions.checkCondition(!RESERVED_FIELD_NAME.contains(getName()), new IllegalMetaClassException(String.format("Reserved meta field name %s!", getName()))); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(getName()), new IllegalMetaClassException("meta field name can not be empty")); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(getName().trim()), new IllegalMetaClassException("meta field name can not be empty")); CheckConditions.checkCondition(org.apache.commons.lang.StringUtils.containsNone(getName(),CMSConsts.INVALID_META_FIELD_NAME_CHARACTERS), new IllegalMetaClassException("meta field " + name + " cannot contains invalid characters: " + Arrays.toString(CMSConsts.INVALID_META_FIELD_NAME_CHARACTERS))); if(!isInternal()) { CheckConditions.checkCondition(!INVALID_PATTERN.matcher(getName()).matches(), new IllegalMetaClassException("meta field name can not start with regex _[A-Za-z0-9]: " + getName())); } }
public void validate() { checkIndexName(); CheckConditions.checkCondition(keyList.size() < CMSConsts.MAX_FIELDS_OF_COMPOUND_INDEX, new IllegalIndexException("The number of fields in a compound index can not be exceed " + CMSConsts.MAX_FIELDS_OF_COMPOUND_INDEX)); for (String key : keyList) { if (!PATTERN.matcher(key).matches()) { throw new IllegalIndexException("key name must be valid attribute name characters of [A-Za-z0-9_]*!"); } } // hashed index validation // "You may not create compound indexes that have hashed index fields or specify a unique constraint on a hashed index" // (see http://docs.mongodb.org/manual/core/indexes/#index-type-hashed) if (options.contains(IndexOptionEnum.hashed)) { if (options.contains(IndexOptionEnum.unique)) { throw new IllegalIndexException("Currently hashed indexes cannot guarantee uniqueness!"); } if (keyList.size() > 1) { throw new IllegalIndexException("Currently only single field hashed index supported!"); } } }
public void setupAncestors(MetaClass meta, IMetadataService metadataService, Map<String, MetaClass> metas) { if (meta.getParent() == null) { return; } ArrayList<String> ancestorList = new ArrayList<String>(); String p = meta.getParent(); while(!StringUtils.isNullOrEmpty(p)) { ancestorList.add(p); MetaClass m = metadataService.getMetaClass(p); if (m == null) { m = metas.get(p); } CheckConditions.checkCondition(m != null, new IllegalMetaClassException("can not get metaclass: " + p + " while setup ancestors for " + meta.getName())); p = m.getParent(); CheckConditions.checkCondition(p == null || !p.equals(meta.getName()), new IllegalMetaClassException("circle found for metaclass inherent")); } meta.setAncestors(ancestorList); // this.ancestors = ancestorList; }
private void validate(MetaClass meta, Map<String, MetaClass> metas, MetaClassGraph tempGraph) { String name = meta.getName(); checkMetaClassName(name); checkNotInheritedFromEmbededClass(meta, metas); CheckConditions.checkCondition(!(meta.isEmbed() && meta.isInner()), new IllegalMetaClassException("meta class " + name + " cannot be embed and inner")); CheckConditions.checkCondition(meta.getId() == null, new IllegalMetaClassException("id should not be set for creation and update")); CheckConditions.checkCondition(meta.getAncestors() == null, new IllegalMetaClassException("ancestors should not be set for creation and update")); validateFields(meta, metas, false); validateIndex(meta, metas, tempGraph); }
@Test public void test() { RuntimeException ex = new RuntimeException(); CheckConditions.checkCondition(true, ex); try { CheckConditions.checkCondition(false, ex); Assert.fail(); } catch (RuntimeException e) { Assert.assertEquals(ex, e); } CheckConditions.checkNotNull(this, ex); try { CheckConditions.checkNotNull(null, ex); Assert.fail(); } catch (RuntimeException e) { Assert.assertEquals(ex, e); } } }
CheckConditions.checkCondition(fieldNames.contains(idxField), new MetaDataException(MetaErrCodeEnum.META_FIELD_NOT_EXISTS, MessageFormat.format("index {0} has field {1} that doesn''t exsiting", idx.getIndexName(), idxField)));
CheckConditions.checkCondition(!(isEmbed && isInner), new IllegalMetaClassException("meta class " + name + " cannot be embed and inner"));