http://git-wip-us.apache.org/repos/asf/atlas/blob/a1fd4068/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveBuilder.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveBuilder.java b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveBuilder.java index ab2b2f6..72f37f0 100644 --- a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveBuilder.java +++ b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveBuilder.java @@ -19,9 +19,13 @@ package org.apache.atlas.omrs.archivemanager; import org.apache.atlas.omrs.archivemanager.properties.*; +import org.apache.atlas.omrs.ffdc.OMRSErrorCode; +import org.apache.atlas.omrs.ffdc.exception.OMRSLogicErrorException; import org.apache.atlas.omrs.metadatacollection.properties.instances.EntityDetail; import org.apache.atlas.omrs.metadatacollection.properties.instances.Relationship; import org.apache.atlas.omrs.metadatacollection.properties.typedefs.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; @@ -39,15 +43,29 @@ public class OMRSArchiveBuilder /* * Hash maps for accumulating TypeDefs and instances as the content of the archive is built up. */ - private Map<String, PrimitiveDef> primitiveDefMap = new HashMap<>(); - private Map<String, CollectionDef> collectionDefMap = new HashMap<>(); - private Map<String, EnumDef> enumDefMap = new HashMap<>(); - private Map<String, ClassificationDef> classificationDefMap = new HashMap<>(); - private Map<String, EntityDef> entityDefMap = new HashMap<>(); - private Map<String, RelationshipDef> relationshipDefMap = new HashMap<>(); - private Map<String, TypeDefPatch> typeDefPatchMap = new HashMap<>(); - private Map<String, EntityDetail> entityDetailMap = new HashMap<>(); - private Map<String, Relationship> relationshipMap = new HashMap<>(); + private Map<String, PrimitiveDef> primitiveDefMap = new HashMap<>(); + private ArrayList<PrimitiveDef> primitiveDefList = new ArrayList<>(); + private Map<String, EnumDef> enumDefMap = new HashMap<>(); + private ArrayList<EnumDef> enumDefList = new ArrayList<>(); + private Map<String, CollectionDef> collectionDefMap = new HashMap<>(); + private ArrayList<CollectionDef> collectionDefList = new ArrayList<>(); + private Map<String, ClassificationDef> classificationDefMap = new HashMap<>(); + private ArrayList<ClassificationDef> classificationDefList = new ArrayList<>(); + private Map<String, EntityDef> entityDefMap = new HashMap<>(); + private ArrayList<EntityDef> entityDefList = new ArrayList<>(); + private Map<String, RelationshipDef> relationshipDefMap = new HashMap<>(); + private ArrayList<RelationshipDef> relationshipDefList = new ArrayList<>(); + private Map<String, TypeDefPatch> typeDefPatchMap = new HashMap<>(); + private ArrayList<TypeDefPatch> typeDefPatchList = new ArrayList<>(); + private Map<String, EntityDetail> entityDetailMap = new HashMap<>(); + private ArrayList<EntityDetail> entityDetailList = new ArrayList<>(); + private Map<String, Relationship> relationshipMap = new HashMap<>(); + private ArrayList<Relationship> relationshipList = new ArrayList<>(); + private Map<String, Object> guidMap = new HashMap<>(); + private Map<String, Object> nameMap = new HashMap<>(); + + + private static final Logger log = LoggerFactory.getLogger(OMRSArchiveBuilder.class); /** @@ -84,13 +102,126 @@ public class OMRSArchiveBuilder /** * Add a new PrimitiveDef to the archive. * - * @param primitiveDef - type to add + * @param primitiveDef - type to add - nulls are ignored */ public void addPrimitiveDef(PrimitiveDef primitiveDef) { + final String methodName = "addPrimitiveDef()"; + if (primitiveDef != null) { - primitiveDefMap.put(primitiveDef.getName(), primitiveDef); + if (log.isDebugEnabled()) + { + log.debug("Adding PrimitiveDef: " + primitiveDef.toString()); + } + + PrimitiveDef duplicateElement = primitiveDefMap.put(primitiveDef.getName(), primitiveDef); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(primitiveDef.getName(), + AttributeTypeDefCategory.PRIMITIVE.getTypeName(), + duplicateElement.toString(), + primitiveDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(primitiveDef.getGUID(), primitiveDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(primitiveDef.getGUID(), + duplicateGUID.toString(), + primitiveDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(primitiveDef.getName(), primitiveDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(primitiveDef.getGUID(), + duplicateName.toString(), + primitiveDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + primitiveDefList.add(primitiveDef); + } + } + + + /** + * Retrieve a PrimitiveDef from the archive. + * + * @param primitiveDefName - primitive to retrieve + */ + public PrimitiveDef getPrimitiveDef(String primitiveDefName) + { + final String methodName = "getPrimitiveDef()"; + + if (log.isDebugEnabled()) + { + log.debug("Retrieving PrimitiveDef: " + primitiveDefName); + } + + if (primitiveDefName != null) + { + PrimitiveDef primitiveDef = primitiveDefMap.get(primitiveDefName); + + if (primitiveDef == null) + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(primitiveDefName, + AttributeTypeDefCategory.PRIMITIVE.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + return primitiveDef; + } + else + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_NAME_FOR_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(AttributeTypeDefCategory.PRIMITIVE.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } } @@ -102,9 +233,122 @@ public class OMRSArchiveBuilder */ public void addCollectionDef(CollectionDef collectionDef) { + final String methodName = "addCollectionDef()"; + if (collectionDef != null) { - collectionDefMap.put(collectionDef.getName(), collectionDef); + if (log.isDebugEnabled()) + { + log.debug("Adding CollectionDef: " + collectionDef.toString()); + } + + CollectionDef duplicateElement = collectionDefMap.put(collectionDef.getName(), collectionDef); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(collectionDef.getName(), + AttributeTypeDefCategory.COLLECTION.getTypeName(), + duplicateElement.toString(), + collectionDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(collectionDef.getGUID(), collectionDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(collectionDef.getGUID(), + duplicateGUID.toString(), + collectionDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(collectionDef.getName(), collectionDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(collectionDef.getGUID(), + duplicateName.toString(), + collectionDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + collectionDefList.add(collectionDef); + } + } + + + /** + * Retrieve a CollectionDef from the archive. + * + * @param collectionDefName - type to retrieve + */ + public CollectionDef getCollectionDef(String collectionDefName) + { + final String methodName = "getCollectionDef()"; + + if (log.isDebugEnabled()) + { + log.debug("Retrieving CollectionDef: " + collectionDefName); + } + + if (collectionDefName != null) + { + CollectionDef collectionDef = collectionDefMap.get(collectionDefName); + + if (collectionDef == null) + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(collectionDefName, + AttributeTypeDefCategory.COLLECTION.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + return collectionDef; + } + else + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_NAME_FOR_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(AttributeTypeDefCategory.COLLECTION.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } } @@ -116,9 +360,123 @@ public class OMRSArchiveBuilder */ public void addEnumDef(EnumDef enumDef) { + final String methodName = "addEnumDef()"; + if (enumDef != null) { - enumDefMap.put(enumDef.getName(), enumDef); + if (log.isDebugEnabled()) + { + log.debug("Adding EnumDef: " + enumDef.toString()); + } + + EnumDef duplicateElement = enumDefMap.put(enumDef.getName(), enumDef); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(enumDef.getName(), + AttributeTypeDefCategory.ENUM_DEF.getTypeName(), + duplicateElement.toString(), + enumDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(enumDef.getGUID(), enumDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(enumDef.getGUID(), + duplicateGUID.toString(), + enumDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(enumDef.getName(), enumDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(enumDef.getGUID(), + duplicateName.toString(), + enumDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + enumDefList.add(enumDef); + } + } + + + /** + * Get an existing EnumDef from the archive. + * + * @param enumDefName - type to retrieve + * @return EnumDef object + */ + public EnumDef getEnumDef(String enumDefName) + { + final String methodName = "getEnumDef()"; + + if (log.isDebugEnabled()) + { + log.debug("Retrieving EnumDef: " + enumDefName); + } + + if (enumDefName != null) + { + EnumDef enumDef = enumDefMap.get(enumDefName); + + if (enumDef == null) + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(enumDefName, + AttributeTypeDefCategory.ENUM_DEF.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + return enumDef; + } + else + { + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_NAME_FOR_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(AttributeTypeDefCategory.ENUM_DEF.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } } @@ -130,9 +488,71 @@ public class OMRSArchiveBuilder */ public void addClassificationDef(ClassificationDef classificationDef) { + final String methodName = "addClassificationDef()"; + if (classificationDef != null) { - classificationDefMap.put(classificationDef.getName(), classificationDef); + if (log.isDebugEnabled()) + { + log.debug("Adding ClassificationDef: " + classificationDef.toString()); + } + + ClassificationDef duplicateElement = classificationDefMap.put(classificationDef.getName(), classificationDef); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(classificationDef.getName(), + TypeDefCategory.CLASSIFICATION_DEF.getTypeName(), + duplicateElement.toString(), + classificationDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(classificationDef.getGUID(), classificationDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(classificationDef.getGUID(), + duplicateGUID.toString(), + classificationDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(classificationDef.getName(), classificationDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(classificationDef.getName(), + duplicateName.toString(), + classificationDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + classificationDefList.add(classificationDef); } } @@ -144,14 +564,71 @@ public class OMRSArchiveBuilder */ public void addEntityDef(EntityDef entityDef) { + final String methodName = "addEntityDef()"; + if (entityDef != null) { - EntityDef previousDef = entityDefMap.put(entityDef.getName(), entityDef); + if (log.isDebugEnabled()) + { + log.debug("Adding EntityDef: " + entityDef.toString()); + } - if (previousDef != null) + EntityDef duplicateElement = entityDefMap.put(entityDef.getName(), entityDef); + + if (duplicateElement != null) { - // TODO log a duplicate + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(entityDef.getName(), + TypeDefCategory.ENTITY_DEF.getTypeName(), + duplicateElement.toString(), + entityDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } + + Object duplicateGUID = guidMap.put(entityDef.getGUID(), entityDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(entityDef.getGUID(), + duplicateGUID.toString(), + entityDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(entityDef.getName(), entityDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(entityDef.getName(), + duplicateName.toString(), + entityDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + entityDefList.add(entityDef); } } @@ -164,23 +641,46 @@ public class OMRSArchiveBuilder */ public EntityDef getEntityDef(String entityDefName) { + final String methodName = "getEntityDef()"; + + if (log.isDebugEnabled()) + { + log.debug("Retrieving EntityDef: " + entityDefName); + } + if (entityDefName != null) { EntityDef retrievedEntityDef = entityDefMap.get(entityDefName); - if (retrievedEntityDef != null) + if (retrievedEntityDef == null) { - return retrievedEntityDef; - } - else - { - // TODO Throw exception - return null; /* temporary */ + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(entityDefName, + TypeDefCategory.ENTITY_DEF.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } + + return retrievedEntityDef; } else { - return null; + OMRSErrorCode errorCode = OMRSErrorCode.MISSING_NAME_FOR_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(TypeDefCategory.ENTITY_DEF.getTypeName()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); } } @@ -192,9 +692,71 @@ public class OMRSArchiveBuilder */ public void addRelationshipDef(RelationshipDef relationshipDef) { + final String methodName = "addRelationshipDef()"; + if (relationshipDef != null) { - relationshipDefMap.put(relationshipDef.getName(), relationshipDef); + if (log.isDebugEnabled()) + { + log.debug("Adding RelationshipDef: " + relationshipDef.toString()); + } + + RelationshipDef duplicateElement = relationshipDefMap.put(relationshipDef.getName(), relationshipDef); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(relationshipDef.getName(), + TypeDefCategory.RELATIONSHIP_DEF.getTypeName(), + duplicateElement.toString(), + relationshipDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(relationshipDef.getGUID(), relationshipDef); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(relationshipDef.getGUID(), + duplicateGUID.toString(), + relationshipDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateName = nameMap.put(relationshipDef.getName(), relationshipDef); + + if (duplicateName != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(relationshipDef.getName(), + duplicateName.toString(), + relationshipDef.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + relationshipDefList.add(relationshipDef); } } @@ -206,9 +768,53 @@ public class OMRSArchiveBuilder */ public void addEntity(EntityDetail entity) { + final String methodName = "addEntity()"; + if (entity != null) { - entityDetailMap.put(entity.getGUID(), entity); + if (log.isDebugEnabled()) + { + log.debug("Adding Entity: " + entity.toString()); + } + + EntityDetail duplicateElement = entityDetailMap.put(entity.getGUID(), entity); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_INSTANCE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(TypeDefCategory.ENTITY_DEF.getTypeName(), + entity.getGUID(), + duplicateElement.toString(), + entity.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(entity.getGUID(), entity); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(entity.getGUID(), + duplicateGUID.toString(), + entity.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + entityDetailList.add(entity); } } @@ -220,9 +826,53 @@ public class OMRSArchiveBuilder */ public void addRelationship(Relationship relationship) { + final String methodName = "addRelationship()"; + if (relationship != null) { - relationshipMap.put(relationship.getGUID(), relationship); + if (log.isDebugEnabled()) + { + log.debug("Adding Relationship: " + relationship.toString()); + } + + Relationship duplicateElement = relationshipMap.put(relationship.getGUID(), relationship); + + if (duplicateElement != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_INSTANCE_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(TypeDefCategory.ENTITY_DEF.getTypeName(), + relationship.getGUID(), + duplicateElement.toString(), + relationship.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + Object duplicateGUID = guidMap.put(relationship.getGUID(), relationship); + + if (duplicateGUID != null) + { + OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_GUID_IN_ARCHIVE; + String errorMessage = errorCode.getErrorMessageId() + + errorCode.getFormattedErrorMessage(relationship.getGUID(), + duplicateGUID.toString(), + relationship.toString()); + + throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), + this.getClass().getName(), + methodName, + errorMessage, + errorCode.getSystemAction(), + errorCode.getUserAction()); + } + + relationshipList.add(relationship); } } @@ -234,6 +884,13 @@ public class OMRSArchiveBuilder */ public OpenMetadataArchive getOpenMetadataArchive() { + final String methodName = "getOpenMetadataArchive()"; + + if (log.isDebugEnabled()) + { + log.debug("Retrieving Open Metadata Archive: " + archiveProperties.getArchiveName()); + } + OpenMetadataArchive archive = new OpenMetadataArchive(); /* @@ -244,41 +901,41 @@ public class OMRSArchiveBuilder /* * Set up the TypeStore. The types are added in a strict order to ensure that the dependencies are resolved. */ - ArrayList<AttributeTypeDef> attributeTypeDefs = null; + ArrayList<AttributeTypeDef> attributeTypeDefs = new ArrayList<>(); ArrayList<TypeDef> typeDefs = new ArrayList<>(); ArrayList<TypeDefPatch> typeDefPatches = new ArrayList<>(); - if (! primitiveDefMap.isEmpty()) + if (! primitiveDefList.isEmpty()) { - attributeTypeDefs.addAll(primitiveDefMap.values()); + attributeTypeDefs.addAll(primitiveDefList); } - if (! collectionDefMap.isEmpty()) + if (! collectionDefList.isEmpty()) { - attributeTypeDefs.addAll(collectionDefMap.values()); + attributeTypeDefs.addAll(collectionDefList); } - if (! enumDefMap.isEmpty()) + if (! enumDefList.isEmpty()) { - attributeTypeDefs.addAll(enumDefMap.values()); + attributeTypeDefs.addAll(enumDefList); } - if (! entityDefMap.isEmpty()) + if (! entityDefList.isEmpty()) { - typeDefs.addAll(entityDefMap.values()); + typeDefs.addAll(entityDefList); } - if (! classificationDefMap.isEmpty()) + if (! classificationDefList.isEmpty()) { - typeDefs.addAll(classificationDefMap.values()); + typeDefs.addAll(classificationDefList); } - if (! relationshipDefMap.isEmpty()) + if (! relationshipDefList.isEmpty()) { - typeDefs.addAll(relationshipDefMap.values()); + typeDefs.addAll(relationshipDefList); } - if (! typeDefPatchMap.isEmpty()) + if (! typeDefPatchList.isEmpty()) { - typeDefPatches.addAll(typeDefPatchMap.values()); + typeDefPatches.addAll(typeDefPatchList); } - if ((! typeDefs.isEmpty()) || (! typeDefPatches.isEmpty())) + if ((! typeDefs.isEmpty()) || (! typeDefPatches.isEmpty()) || (! attributeTypeDefs.isEmpty())) { OpenMetadataArchiveTypeStore typeStore = new OpenMetadataArchiveTypeStore(); @@ -307,13 +964,13 @@ public class OMRSArchiveBuilder ArrayList<EntityDetail> entities = new ArrayList<>(); ArrayList<Relationship> relationships = new ArrayList<>(); - if (! entityDetailMap.isEmpty()) + if (! entityDetailList.isEmpty()) { - entities.addAll(entityDetailMap.values()); + entities.addAll(entityDetailList); } - if (! relationshipMap.isEmpty()) + if (! relationshipList.isEmpty()) { - relationships.addAll(relationshipMap.values()); + relationships.addAll(relationshipList); } if ((! entities.isEmpty()) || (! relationships.isEmpty()))
http://git-wip-us.apache.org/repos/asf/atlas/blob/a1fd4068/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java new file mode 100644 index 0000000..8a834ee --- /dev/null +++ b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java @@ -0,0 +1,617 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.omrs.archivemanager; + +import org.apache.atlas.omrs.metadatacollection.properties.instances.InstanceStatus; +import org.apache.atlas.omrs.metadatacollection.properties.typedefs.*; + +import java.util.ArrayList; +import java.util.Date; + +/** + * OMRSArchiveHelper provides utility methods to help in the construction of open metadata archives. + */ +public class OMRSArchiveHelper +{ + private OMRSArchiveBuilder archiveBuilder; + private String archiveGUID; + private String originatorName; + private Date creationDate; + private long versionNumber; + private String versionName; + + + /** + * Constructor receives information about the archive being built. + * + * @param archiveBuilder - archive builder with the archive contents in it. + * @param archiveGUID - unique identifier for the archive. + * @param originatorName - name of the person / process creating the archive. + * @param creationDate - date that the archive was first built. + * @param versionNumber - version number of the archive. + * @param versionName - version name for the archive. + */ + public OMRSArchiveHelper(OMRSArchiveBuilder archiveBuilder, + String archiveGUID, + String originatorName, + Date creationDate, + long versionNumber, + String versionName) + { + this.archiveBuilder = archiveBuilder; + this.archiveGUID = archiveGUID; + this.originatorName = originatorName; + this.creationDate = creationDate; + this.versionNumber = versionNumber; + this.versionName = versionName; + } + + + /** + * Set up an individual primitive definition + * + * @param primitiveDefCategory - category of the primitive def defines the unique + * information about this primitive type. + * @return initialized PrimitiveDef object ready for the archive + */ + public PrimitiveDef getPrimitiveDef(PrimitiveDefCategory primitiveDefCategory) + { + PrimitiveDef primitiveDef = new PrimitiveDef(primitiveDefCategory); + + primitiveDef.setGUID(primitiveDefCategory.getGUID()); + primitiveDef.setName(primitiveDefCategory.getName()); + primitiveDef.setVersion(versionNumber); + primitiveDef.setVersionName(versionName); + + return primitiveDef; + } + + + /** + * Create a CollectionDef for an Array. A new CollectionDef is required for each combination of primitive types + * used to initialize the collection. Each CollectionDef has its own unique identifier (guid) and + * its name is a combination of the collection type and the primitives use to initialize it. + * + * @param guid - unique identifier for the CollectionDef + * @param description - short default description of the enum type + * @param descriptionGUID - guid of the glossary term describing this collection type + * @return Filled out CollectionDef + */ + public CollectionDef getArrayCollectionDef(String guid, + String description, + String descriptionGUID, + PrimitiveDefCategory arrayType) + { + CollectionDef collectionDef = new CollectionDef(CollectionDefCategory.OM_COLLECTION_ARRAY); + + collectionDef.setGUID(guid); + collectionDef.setName("array<" + arrayType.getName() + ">"); + collectionDef.setDescription(description); + collectionDef.setDescriptionGUID(descriptionGUID); + + ArrayList<PrimitiveDefCategory> argumentList = new ArrayList<>(); + argumentList.add(arrayType); + collectionDef.setArgumentTypes(argumentList); + + return collectionDef; + } + + + /** + * Create a CollectionDef for a map. A new CollectionDef is required for each combination of primitive types + * used to initialize the collection. Each CollectionDef has its own unique identifier (guid) and + * its name is a combination of the collection type and the primitives use to initialize it. + * + * @param guid - unique identifier for the CollectionDef + * @param description - short default description of the enum type + * @param descriptionGUID - guid of the glossary term describing this collection type + * @param propertyKeyType - type of the key for the map. + * @return Filled out CollectionDef + */ + public CollectionDef getMapCollectionDef(String guid, + String description, + String descriptionGUID, + PrimitiveDefCategory propertyKeyType, + PrimitiveDefCategory propertyValueType) + { + CollectionDef collectionDef = new CollectionDef(CollectionDefCategory.OM_COLLECTION_MAP); + + collectionDef.setGUID(guid); + collectionDef.setName("map<" + propertyKeyType.getName() + ", " + propertyValueType.getName() + ">"); + collectionDef.setDescription(description); + collectionDef.setDescriptionGUID(descriptionGUID); + collectionDef.setVersion(versionNumber); + collectionDef.setVersionName(versionName); + + ArrayList<PrimitiveDefCategory> argumentList = new ArrayList<>(); + argumentList.add(propertyKeyType); + argumentList.add(propertyValueType); + collectionDef.setArgumentTypes(argumentList); + + return collectionDef; + } + + + /** + * Create an EnumDef that has no valid values defined. These are added by the caller. + * + * @param guid - unique identifier for the CollectionDef + * @param name - unique name for the CollectionDef + * @param description - short default description of the enum type + * @param descriptionGUID - guid of the glossary term describing this enum type + * @return basic EnumDef without valid values + */ + public EnumDef getEmptyEnumDef(String guid, + String name, + String description, + String descriptionGUID) + { + EnumDef enumDef = new EnumDef(); + + enumDef.setGUID(guid); + enumDef.setName(name); + enumDef.setDescription(description); + enumDef.setDescriptionGUID(descriptionGUID); + enumDef.setDefaultValue(null); + enumDef.setVersion(versionNumber); + enumDef.setVersionName(versionName); + + return enumDef; + } + + + /** + * Create an EnumElementDef that carries one of the valid values for an Enum. + * + * @param ordinal - code number + * @param value - name + * @param description - short description + * @param descriptionGUID - guid of the glossary term describing this enum element + * @return Fully filled out EnumElementDef + */ + public EnumElementDef getEnumElementDef(int ordinal, + String value, + String description, + String descriptionGUID) + { + EnumElementDef enumElementDef = new EnumElementDef(); + + enumElementDef.setOrdinal(ordinal); + enumElementDef.setValue(value); + enumElementDef.setDescription(description); + enumElementDef.setDescriptionGUID(descriptionGUID); + + return enumElementDef; + } + + + /** + * Sets up a default EntityDef. Calling methods can override the default values. This EntityDef + * has no attribute defined. + * + * @param guid - unique identifier for the entity + * @param name - name of the entity + * @param superType - Super type for this entity (null for top-level) + * @param description - short description of the entity + * @param descriptionGUID - guid of the glossary term describing this entity type + * @return Initialized EntityDef + */ + public EntityDef getDefaultEntityDef(String guid, + String name, + TypeDefLink superType, + String description, + String descriptionGUID) + { + EntityDef entityDef = new EntityDef(); + + /* + * Set up the parameters supplied by the caller. + */ + entityDef.setGUID(guid); + entityDef.setName(name); + entityDef.setSuperType(superType); + entityDef.setDescription(description); + entityDef.setDescriptionGUID(descriptionGUID); + + /* + * Set up the defaults + */ + entityDef.setOrigin(archiveGUID); + entityDef.setCreatedBy(originatorName); + entityDef.setCreateTime(creationDate); + entityDef.setVersion(versionNumber); + entityDef.setVersionName(versionName); + + /* + * Set default valid instance statuses + */ + ArrayList<InstanceStatus> validInstanceStatusList = new ArrayList<>(); + validInstanceStatusList.add(InstanceStatus.ACTIVE); + validInstanceStatusList.add(InstanceStatus.DELETED); + entityDef.setValidInstanceStatusList(validInstanceStatusList); + + return entityDef; + } + + + /** + * Return an attribute with the supplied name and description that is of type String. It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getStringTypeDefAttribute(String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getPrimitiveDef(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_STRING.getName())); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Return an attribute with the supplied name and description that is of type int. It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getIntTypeDefAttribute(String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getPrimitiveDef(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_INT.getName())); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Return an attribute with the supplied name and description that is of type date. It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getDateTypeDefAttribute(String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getPrimitiveDef(PrimitiveDefCategory.OM_PRIMITIVE_TYPE_DATE.getName())); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Return an attribute with the supplied name and description that is of type "array<string>". + * It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getArrayStringTypeDefAttribute(String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getCollectionDef("array<string>")); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Return an attribute with the supplied name and description that is of type "map<string, string>". + * It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getMapStringStringTypeDefAttribute(String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getCollectionDef("map<string, string>")); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Return an attribute with the supplied name, type and description. It is set up to be optional, + * indexable (useful for searches) but the value does not need to be unique. + * These are the typical values used for most open metadata attribute. + * They can be changed by the caller once the TypeDefAttribute is returned. + * + * @param enumTypeName - name of the enum type for this attribute + * @param attributeName - name of the attribute + * @param attributeDescription - short description for the attribute + * @param attributeDescriptionGUID - guid of the glossary term that describes this attribute. + * @return TypeDefAttribute of type string + */ + public TypeDefAttribute getEnumTypeDefAttribute(String enumTypeName, + String attributeName, + String attributeDescription, + String attributeDescriptionGUID) + { + TypeDefAttribute attribute = new TypeDefAttribute(); + + attribute.setAttributeName(attributeName); + attribute.setAttributeDescription(attributeDescription); + attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); + attribute.setAttributeType(this.archiveBuilder.getEnumDef(enumTypeName)); + attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE); + attribute.setValuesMinCount(0); + attribute.setValuesMaxCount(1); + attribute.setIndexable(true); + attribute.setUnique(false); + attribute.setDefaultValue(null); + attribute.setExternalStandardMappings(null); + + return attribute; + } + + + /** + * Returns a basic RelationshipDef without any attributes or ends set up. + * The caller is responsible for adding the attributes and ends definition. + * + * @param guid - unique identifier for the relationship + * @param name - name of the relationship + * @param superType - Super type for this relationship (null for top-level) + * @param description - short default description of the relationship + * @param descriptionGUID - guid of the glossary term that describes this relationship + * @param relationshipCategory - is this an association, aggregation or composition? + * @param propagationRule - should classifications propagate over this relationship? + * @return RelationshipDef with no ends defined. + */ + public RelationshipDef getBasicRelationshipDef(String guid, + String name, + TypeDefLink superType, + String description, + String descriptionGUID, + RelationshipCategory relationshipCategory, + ClassificationPropagationRule propagationRule) + { + RelationshipDef relationshipDef = new RelationshipDef(); + + /* + * Set up the parameters supplied by the caller. + */ + relationshipDef.setGUID(guid); + relationshipDef.setName(name); + relationshipDef.setSuperType(superType); + relationshipDef.setDescription(description); + relationshipDef.setDescriptionGUID(descriptionGUID); + + /* + * Set up the defaults + */ + relationshipDef.setOrigin(archiveGUID); + relationshipDef.setCreatedBy(originatorName); + relationshipDef.setCreateTime(creationDate); + relationshipDef.setVersion(versionNumber); + relationshipDef.setVersionName(versionName); + + /* + * Set default valid instance statuses + */ + ArrayList<InstanceStatus> validInstanceStatusList = new ArrayList<>(); + validInstanceStatusList.add(InstanceStatus.ACTIVE); + validInstanceStatusList.add(InstanceStatus.DELETED); + relationshipDef.setValidInstanceStatusList(validInstanceStatusList); + + /* + * Set up the category of relationship + */ + relationshipDef.setRelationshipCategory(relationshipCategory); + + if ((relationshipCategory == RelationshipCategory.AGGREGATION) || + (relationshipCategory == RelationshipCategory.COMPOSITION)) + { + /* + * By convention, end 1 is the container end in the open metadata model. + */ + relationshipDef.setRelationshipContainerEnd(RelationshipContainerEnd.END1); + } + else + { + relationshipDef.setRelationshipContainerEnd(RelationshipContainerEnd.NOT_APPLICABLE); + } + + /* + * Use the supplied propagation rule. + */ + relationshipDef.setPropagationRule(propagationRule); + + return relationshipDef; + } + + + /** + * Returns a RelationshipEndDef object that sets up details of an entity at one end of a relationship. + * + * @param entityType - details of the type of entity connected to this end. + * @param attributeName - name of the attribute that the entity at the other end uses to refer to this entity. + * @param attributeDescription - description of this attribute + * @param attributeDescriptionGUID - unique identifier of the glossary term describing this attribute. + * @param attributeCardinality - cardinality of this end of the relationship. + * @return the definition of one end of a Relationship. + */ + public RelationshipEndDef getRelationshipEndDef(TypeDefLink entityType, + String attributeName, + String attributeDescription, + String attributeDescriptionGUID, + AttributeCardinality attributeCardinality) + { + RelationshipEndDef relationshipEndDef = new RelationshipEndDef(); + + relationshipEndDef.setEntityType(entityType); + relationshipEndDef.setAttributeName(attributeName); + relationshipEndDef.setAttributeDescription(attributeDescription); + relationshipEndDef.setAttributeDescriptionGUID(attributeDescriptionGUID); + relationshipEndDef.setAttributeCardinality(attributeCardinality); + + return relationshipEndDef; + } + + + /** + * Returns a basic ClassificationDef without any attributes. The caller is responsible for adding the + * attribute definitions. + * + * @param guid - unique identifier for the classification + * @param name - name of the classification + * @param superType - Super type for this classification (null for top-level) + * @param description - short description of the classification + * @param descriptionGUID - unique identifier of the glossary term that describes this classification. + * @param validEntityDef - which entities can this classification be linked to. + * @param propagatable - can the classification propagate over relationships? + * @return ClassificationDef with no attributes defined. + */ + public ClassificationDef getClassificationDef(String guid, + String name, + TypeDefLink superType, + String description, + String descriptionGUID, + TypeDefLink validEntityDef, + boolean propagatable) + { + ClassificationDef classificationDef = new ClassificationDef(); + + /* + * Set up the parameters supplied by the caller. + */ + classificationDef.setGUID(guid); + classificationDef.setName(name); + classificationDef.setSuperType(superType); + classificationDef.setDescription(description); + classificationDef.setDescriptionGUID(descriptionGUID); + + /* + * Set up the defaults + */ + classificationDef.setOrigin(archiveGUID); + classificationDef.setCreatedBy(originatorName); + classificationDef.setCreateTime(creationDate); + classificationDef.setVersion(versionNumber); + classificationDef.setVersionName(versionName); + + /* + * Set default valid instance statuses + */ + ArrayList<InstanceStatus> validInstanceStatusList = new ArrayList<>(); + validInstanceStatusList.add(InstanceStatus.ACTIVE); + validInstanceStatusList.add(InstanceStatus.DELETED); + classificationDef.setValidInstanceStatusList(validInstanceStatusList); + + /* + * Set up the supplied validEntityTypes and propagatable flag. + */ + ArrayList<TypeDefLink> validEntityDefs = new ArrayList<>(); + validEntityDefs.add(validEntityDef); + classificationDef.setValidEntityDefs(validEntityDefs); + classificationDef.setPropagatable(propagatable); + + return classificationDef; + } +}