String name = meta.getName(); String parent = meta.getParent(); IMetadataService metadataService = meta.getMetadataService(); MetaOption options = meta.getOptions(); Map<String, MetaField> fieldNameIndex = meta.getFieldNameIndex(); String repository = meta.getRepository(); if (existingMetadata == null || !existingMetadata.getName().equals(name)) { throw new MetaClassNotExistsException(repository, name); Boolean isEmbed = meta.getEmbed(); if (isEmbed == null) { isEmbed = existingMetadata.getEmbed(); Boolean isInner = meta.getInner(); if (isInner == null) { isInner = existingMetadata.getInner(); fieldNames.addAll(existingMetadata.getFieldNames()); meta.setupAncestors(metadataService, metas); String fieldName = newField.getName(); newFieldNames.add(fieldName); MetaField existingField = existingMetadata.getFieldByName(fieldName); MetaField parentField = null; if (!StringUtils.isNullOrEmpty(parent)) { parentField = metadataService.getMetaClass(parent).getFieldByName(fieldName);
@Override public void processAttribute(IEntity currentEntity, IEntity existingEntity, MetaField metaField) { MetaClass metaClass = currentEntity.getMetaClass(); Collection<MetaField> metaFields = metaClass.getFields(); for (MetaField field : metaFields) { String fieldName = field.getName(); if (CardinalityEnum.Many.equals(field.getCardinality()) && !metaClass.getIndexesOnField(fieldName).isEmpty()) { int indexedArraySize = currentEntity.getFieldValues(fieldName).size(); if (indexedArraySize > maxIndexedArraySize) { String errorMessage = String.format("Exceed max indexed array size on metafield %s of metaclass %s! Max is %d, Actual is %d", fieldName, metaClass.getName(), maxIndexedArraySize, indexedArraySize); throw new CmsDalException(DalErrCodeEnum.EXCEED_MAX_INDEXED_ARRAY_SIZE, errorMessage); } } } }
public MetaClass newClass(String repoName, String metaType){ MetaClass metaClass = new MetaClass(); metaClass.setRepository(repoName); metaClass.setName(metaType); metaService.createMetaClass(metaClass, new MetadataContext()); return metaClass; }
private void setupParentVersion(MetaClass metaClass) { // update the parentVersion if existing. String parent = metaClass.getParent(); if (parent != null) { MetaClass parentMeta = metaClass.getParentMetaClass(); if (parentMeta != null) { metaClass.setParentVersion(parentMeta.getVersion()); } else { metaClass.setParentVersion(0); } } }
private void checkMetaClassVersion(MetaClass metaClass) { MetaClass existingMeta = getMetaClass(metaClass.getName()); if (existingMeta == null) { throw new MetaClassNotExistsException(metaClass.getRepository(), metaClass.getName()); } if (metaClass.getVersion() > 0 && metaClass.getVersion() != existingMeta.getVersion()) { throw new MetaDataException(MetaErrCodeEnum.VERSION_CONFLICTED, "MetaClass version conflict: " + metaClass.getName()); } metaClass.setVersion(existingMeta.getVersion()); }
private MetaField findMetaField(MetaClass metadata, String fieldName) { MetaField metaField = metadata.getFieldByName(fieldName); if (metaField == null) { throw new QueryParseException(QueryErrCodeEnum.METAFIELD_NOT_FOUND, "Can't find field {" + fieldName + "} in metadata " + metadata.getName()); } return metaField; }
private MetaClass createMetaClassWithIndex(String metaclassName, String idxName, IMetadataService metaService) { MetaClass metaClass = new MetaClass(); metaClass.setName(metaclassName); metaClass.setRepository(RAPTOR_REPO); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo(idxName); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); MetaClass createMeta = metaService.createMetaClass(metaClass, new MetadataContext()); Assert.assertNotNull(metaService.getMetaClass(metaClass.getName())); List<MetaClass> metas = new ArrayList<MetaClass>(); metas.add(createMeta); persistenceService.ensureIndex(metas, raptorContext, true); return createMeta; }
@Test public void testUpdateAddIndex() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionAddIndex"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName3"); newIndex.getKeyList().add(attribute.getName()); newIndex.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.ADD); metaService.updateMetaOption(metaClass.getName(), newOption, context); MetaClass getMeta = metaService.getMetaClass(metaClass.getName()); Assert.assertEquals(4, getMeta.getIndexes().size()); Assert.assertTrue(getMeta.getIndexNames().contains(newIndex.getIndexName())); Assert.assertEquals(1, getMeta.getVersion()); }
@Test public void testUpdateChangeIndex() { MetaClass metaClass = createMetaClass(); metaClass.setName("updateOptionChangeIndex"); MetaAttribute attribute = new MetaAttribute(); attribute.setName("attr_Name2"); attribute.setDataType(DataTypeEnum.STRING); metaClass.addField(attribute); IndexInfo index = new IndexInfo("indexName2"); index.getKeyList().add(attribute.getName()); metaClass.addIndex(index); IMetadataService metaService = repositoryService.getRepository(repoName).getMetadataService(); metaService.createMetaClass(metaClass, new MetadataContext()); MetaOption newOption = new MetaOption(); IndexInfo newIndex = new IndexInfo("indexName2"); newIndex.getKeyList().add(attribute.getName()); newIndex.addOption(IndexOptionEnum.unique); newOption.addIndex(newIndex); MetadataContext context = new MetadataContext(); context.setSourceIp("127.0.0.1"); context.setOptionChangeMode(UpdateOptionMode.UPDATE); metaService.updateMetaOption(metaClass.getName(), newOption, context); MetaClass getMeta = metaService.getMetaClass(metaClass.getName()); Assert.assertEquals(3, getMeta.getIndexes().size());// check no new index added Assert.assertTrue(getMeta.getIndexByName(index.getIndexName()).getIndexOptions().size() == 1); Assert.assertTrue(getMeta.getIndexByName(index.getIndexName()).getIndexOptions().get(0) == IndexOptionEnum.unique); }
@Test(expected = IllegalMetaClassException.class) public void testValidateForUpdateField_metaClassName1() { MetaClass mClass = new MetaClass(); String metaClassName = " "; mClass.setName(metaClassName); mClass.setRepository(RAPTOR_PAAS); mClass.setParent("Employee"); MetaAttribute a1 = new MetaAttribute(); String fieldName = "title"; a1.setName(fieldName); a1.setDataType(DataTypeEnum.ENUM); List<String> enumValues = new ArrayList<String>(3); enumValues.add("junior"); enumValues.add("staff"); a1.setEnumValues(enumValues); mClass.addField(a1); Map<String, MetaClass> metas = new HashMap<String, MetaClass>(); metas.put(metaClassName, mClass); // mClass.validateForUpdateField(metas, fieldName); validator.validateForUpdateField(mClass, metas, fieldName); }
@Test(expected=IllegalMetaClassException.class) public void testCreateValidation_ref2() { IMetadataService ms = repositoryService.getRepository(repoName).getMetadataService(); MetaClass m1 = createMetaClass(); MetaRelationship r1 = new MetaRelationship(); r1.setRelationType(RelationTypeEnum.Reference); r1.setName("name1Ref"); r1.setRefDataType("metaclass2"); m1.addField(r1); ms.createMetaClass(m1, new MetadataContext()); MetaClass getMeta = ms.getMetaClass(m1.getName()); Assert.assertNotNull(getMeta); Assert.assertTrue(getMeta.getFields().size() > 1); Assert.assertNotNull(getMeta.getIndexes()); Assert.assertTrue(getMeta.getIndexes().size() == 2); Assert.assertEquals(1, getMeta.getIndexesOnField("name1Ref").size()); }
@Test public void test01AddCrossReference() { MetaRelationship relation = new MetaRelationship(); String fieldName = "crossRepoRef"; relation.setName(fieldName); relation.setRelationType(RelationTypeEnum.CrossRepository); relation.setRefDataType("Manifest"); relation.setRefRepository("software-deployment"); MetaClass metadata = new MetaClass(); metadata.setRepository(RAPTOR_PAAS); metadata.setName("NewReference"); metadata.addField(relation); MetaClass createdMeta = raptorMetaService.createMetaClass(metadata, new MetadataContext()); Assert.assertNotNull(createdMeta.getFieldByName(fieldName)); Assert.assertTrue(createdMeta.getFieldByName(fieldName).getDataType() == DataTypeEnum.RELATIONSHIP); }
private void rewriteCriteria(PersistenceContext context) { if (!metadata.isEmbed()) { // add type criteria MetaField typeMetaField = metadata.getFieldByName(InternalFieldEnum.TYPE.getName()); SearchCriteria typeCriteria = new FieldSearchCriteria(typeMetaField, strategy, FieldOperatorEnum.EQ, metadata.getName()); appendSearchCriteria(typeCriteria); // add additional criteria List<SearchCriteria> criterias = context.getAdditionalCriteria().get(metadata.getName()); if (criterias != null) { for (SearchCriteria criteria : criterias) { appendSearchCriteria(criteria); } } } }
@Override public boolean containsParameter(String name) { MetaClass metadata = inputEntity.getMetaClass(); return metadata.getFieldByName(name) != null; }
private void checkNotInheritedFromEmbededClass(MetaClass meta, Map<String, MetaClass> metas) { String parentClassName = meta.getParent(); if (!org.apache.commons.lang.StringUtils.isEmpty(parentClassName)) { MetaClass parentClass = metas.get(parentClassName); if (parentClass == null) { parentClass = meta.getMetadataService().getMetaClass(parentClassName); } if (parentClass != null && parentClass.isEmbed()) { throw new IllegalMetaClassException(String.format("meta class %s should not be inherited from an embeded class %s", meta.getName(), parentClass.getName())); } } }
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); }
@Override public List<MetaClass> getMetaClasses(MetadataContext context) { List<MetaClass> allMetas = delegate.getMetaClasses(context); Map<String, MetaClass> metaMap = new HashMap<String, MetaClass>(); for (MetaClass mc : allMetas) { metaMap.put(mc.getName(), mc); } metaMap.putAll(nameCache); return new ArrayList<MetaClass>(metaMap.values()); }
@Test public void testMetaClassCreation_embed() { MetaClass metaClass = createMetaClass(); metaClass.setName("EmbedMetaClass"); metaClass.setEmbed(true); IMetadataService ms = repositoryService.getRepository(repoName).getMetadataService(); MetaClass nm = ms.getMetaClass(metaClass.getName()); Assert.assertNull(nm); ms.createMetaClass(metaClass, new MetadataContext()); nm = ms.getMetaClass(metaClass.getName()); Assert.assertEquals(metaClass.getName(), nm.getName()); Assert.assertEquals(true, nm.isEmbed()); }
MetaAttribute empAgeAttr = (MetaAttribute)empMeta.getFieldByName("age"); Assert.assertNull(empAgeAttr.getDefaultValue()); Assert.assertFalse(empAgeAttr.isMandatory()); int fieldLen = empMeta.getFields().size(); IndexInfo empNameInfo = empMeta.getIndexByName("nameIndex"); List<String> empNamekeys = empNameInfo.getKeyList(); Assert.assertEquals(1, empNamekeys.size()); IndexInfo empAgeTitleInfo = empMeta.getIndexByName("ageTitleIndex"); List<String> empAgeTitleKeys = empAgeTitleInfo.getKeyList(); Assert.assertEquals(2, empAgeTitleKeys.size()); MetaAttribute workerAgeAttr = (MetaAttribute)workerMeta.getFieldByName("age"); Assert.assertEquals("28", workerAgeAttr.getDefaultValue()); Assert.assertTrue(workerAgeAttr.isMandatory()); Collection<MetaField> workerFields = workerMeta.getFields(); Assert.assertEquals(fieldLen, workerFields.size()); IndexInfo workerNameInfo = workerMeta.getIndexByName("nameIndex"); List<String> workerKeys = workerNameInfo.getKeyList(); Assert.assertEquals(1, workerKeys.size()); MetaAttribute engAgeAttr = (MetaAttribute)engMeta.getFieldByName("age"); Assert.assertEquals("34", engAgeAttr.getDefaultValue()); Assert.assertTrue(engAgeAttr.isMandatory());
CheckConditions.checkNotNull(meta, "Miss meta class"); CheckConditions.checkNotNull(operType, "Miss operation type"); String repoName = meta.getRepository(); String sourceIp = context.getSourceIp(); CheckConditions.checkNotNull(repoName, "Miss repository name"); historyEntity.setLastModified(new Date()); historyEntity.setStatus(StatusEnum.ACTIVE); historyEntity.addFieldValue(HistoryMetaClass.EntityId, meta.getName()); historyEntity.addFieldValue(HistoryMetaClass.EntityVersion, meta.getVersion()); historyEntity.addFieldValue(HistoryMetaClass.EntityParentVersion, meta.getParentVersion()); historyEntity.addFieldValue(HistoryMetaClass.SourceIp, sourceIp); historyEntity.addFieldValue(HistoryMetaClass.OperType, operType);