Repository: atlas
Updated Branches:
  refs/heads/master e7aec3354 -> 20d4f4d8b


ATLAS2604 Minor fixups to open metadata archive types

Signed-off-by: Graham Wallis <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/20d4f4d8
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/20d4f4d8
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/20d4f4d8

Branch: refs/heads/master
Commit: 20d4f4d8b3089be1922d15a4254ef6ce502cb384
Parents: e7aec33
Author: David Radley <[email protected]>
Authored: Thu Apr 26 15:16:17 2018 +0100
Committer: Graham Wallis <[email protected]>
Committed: Tue May 1 14:40:24 2018 +0100

----------------------------------------------------------------------
 .../omrs/archivemanager/OMRSArchiveBuilder.java | 302 ++++++++++++++++-
 .../omrs/archivemanager/OMRSArchiveHelper.java  |   4 +-
 .../opentypes/OpenMetadataTypesArchive.java     |  28 +-
 .../apache/atlas/omrs/ffdc/OMRSErrorCode.java   |  24 ++
 .../opentypes/TestOpenMetadataTypesArchive.java |  47 +++
 .../store/TestOMRSArchiveBuilder.java           | 339 +++++++++++++++++++
 6 files changed, 718 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/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 5902c42..e44fd1f 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
@@ -63,6 +63,10 @@ public class OMRSArchiveBuilder
     private ArrayList<Relationship>        relationshipList      = new 
ArrayList<>();
     private Map<String, Object>            guidMap               = new 
HashMap<>();
     private Map<String, Object>            nameMap               = new 
HashMap<>();
+    /*
+     * map to keep track of all the AttributeDef names including relationship 
end names per EntityDef name.
+     */
+    private Map<String,Set<String>> entityAttributeMap = new HashMap();
 
 
     private static final Logger log = 
LoggerFactory.getLogger(OMRSArchiveBuilder.class);
@@ -114,6 +118,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding PrimitiveDef: " + primitiveDef.toString());
             }
+            this.checkForBlanksInTypeName(primitiveDef.getName());
 
             PrimitiveDef duplicateElement = 
primitiveDefMap.put(primitiveDef.getName(), primitiveDef);
 
@@ -242,6 +247,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding CollectionDef: " + collectionDef.toString());
             }
+            this.checkForBlanksInTypeName(collectionDef.getName());
 
             CollectionDef duplicateElement = 
collectionDefMap.put(collectionDef.getName(), collectionDef);
 
@@ -370,6 +376,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding EnumDef: " + enumDef.toString());
             }
+            this.checkForBlanksInTypeName(enumDef.getName());
 
             EnumDef duplicateElement = enumDefMap.put(enumDef.getName(), 
enumDef);
 
@@ -498,6 +505,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding ClassificationDef: " + 
classificationDef.toString());
             }
+            this.checkForBlanksInTypeName(classificationDef.getName());
 
             ClassificationDef duplicateElement = 
classificationDefMap.put(classificationDef.getName(), classificationDef);
 
@@ -553,6 +561,33 @@ public class OMRSArchiveBuilder
                                                   errorCode.getSystemAction(),
                                                   errorCode.getUserAction());
             }
+            if (classificationDef.getPropertiesDefinition()!=null)
+            {
+                Set<String> attrSet = new HashSet();
+
+                for (TypeDefAttribute typeDefAttr 
:classificationDef.getPropertiesDefinition())
+                {
+                    String duplicateAttributeName = 
typeDefAttr.getAttributeName();
+                    if (attrSet.contains(duplicateAttributeName))
+                    {
+                        // relationship duplicate attribute name
+                        OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_CLASSIFICATION_ATTR_IN_ARCHIVE;
+                        String errorMessage = errorCode.getErrorMessageId()
+                                + errorCode.getFormattedErrorMessage(
+                                duplicateAttributeName,
+                                classificationDef.getName()
+                        );
+
+                        throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                                this.getClass().getName(),
+                                methodName,
+                                errorMessage,
+                                errorCode.getSystemAction(),
+                                errorCode.getUserAction());
+                    }
+                    attrSet.add(duplicateAttributeName);
+                }
+            }
 
             classificationDefList.add(classificationDef);
         }
@@ -574,6 +609,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding EntityDef: " + entityDef.toString());
             }
+            this.checkForBlanksInTypeName(entityDef.getName());
 
             EntityDef duplicateElement = entityDefMap.put(entityDef.getName(), 
entityDef);
 
@@ -629,7 +665,33 @@ public class OMRSArchiveBuilder
                                                   errorCode.getSystemAction(),
                                                   errorCode.getUserAction());
             }
-
+            if (entityDef.getPropertiesDefinition()!=null)
+            {
+                Set<String> attrSet = new HashSet();
+
+                for (TypeDefAttribute typeDefAttr 
:entityDef.getPropertiesDefinition())
+                {
+                    String duplicateAttributeName = 
typeDefAttr.getAttributeName();
+                    if (attrSet.contains(duplicateAttributeName))
+                    {
+                        // relationship duplicate attribute name
+                        OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENTITY_ATTR_IN_ARCHIVE;
+                        String errorMessage = errorCode.getErrorMessageId()
+                                + errorCode.getFormattedErrorMessage(
+                                duplicateAttributeName,
+                                entityDef.getName()
+                        );
+
+                        throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                                this.getClass().getName(),
+                                methodName,
+                                errorMessage,
+                                errorCode.getSystemAction(),
+                                errorCode.getUserAction());
+                    }
+                    attrSet.add(duplicateAttributeName);
+                }
+            }
             entityDefList.add(entityDef);
         }
     }
@@ -702,7 +764,7 @@ public class OMRSArchiveBuilder
             {
                 log.debug("Adding RelationshipDef: " + 
relationshipDef.toString());
             }
-
+            this.checkForBlanksInTypeName(relationshipDef.getName());
             RelationshipDef duplicateElement = 
relationshipDefMap.put(relationshipDef.getName(), relationshipDef);
 
             if (duplicateElement != null)
@@ -746,22 +808,224 @@ public class OMRSArchiveBuilder
             {
                 OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE;
                 String        errorMessage = errorCode.getErrorMessageId()
-                                           + 
errorCode.getFormattedErrorMessage(relationshipDef.getName(),
-                                                                               
 duplicateName.toString(),
-                                                                               
 relationshipDef.toString());
+                        + 
errorCode.getFormattedErrorMessage(relationshipDef.getName(),
+                        duplicateName.toString(),
+                        relationshipDef.toString());
 
                 throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
-                                                  this.getClass().getName(),
-                                                  methodName,
-                                                  errorMessage,
-                                                  errorCode.getSystemAction(),
-                                                  errorCode.getUserAction());
+                        this.getClass().getName(),
+                        methodName,
+                        errorMessage,
+                        errorCode.getSystemAction(),
+                        errorCode.getUserAction());
             }
+            this.checkRelationshipDefDuplicateAttributes(relationshipDef);
 
+            if (relationshipDef.getPropertiesDefinition()!=null)
+            {
+                Set<String> attrSet = new HashSet();
+                for (TypeDefAttribute typeDefAttr 
:relationshipDef.getPropertiesDefinition())
+                {
+                    String duplicateAttributeName = 
typeDefAttr.getAttributeName();
+                    if (attrSet.contains(duplicateAttributeName))
+                    {
+                        // relationship duplicate attribute name
+                        OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_RELATIONSHIP_ATTR_IN_ARCHIVE;
+                        String errorMessage = errorCode.getErrorMessageId()
+                                + errorCode.getFormattedErrorMessage(
+                                duplicateAttributeName,
+                                relationshipDef.getName()
+                        );
+
+                        throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                                this.getClass().getName(),
+                                methodName,
+                                errorMessage,
+                                errorCode.getSystemAction(),
+                                errorCode.getUserAction());
+                    }
+                    attrSet.add(duplicateAttributeName);
+                }
+            }
             relationshipDefList.add(relationshipDef);
         }
     }
 
+    /**
+     * Check whether the relationshipDef supplies any attributes that already 
exist.
+     * @param relationshipDef
+     * @throws OMRSLogicErrorException
+     */
+    protected void checkRelationshipDefDuplicateAttributes(RelationshipDef 
relationshipDef) throws OMRSLogicErrorException
+    {
+        final String methodName = "checkRelationshipDefDuplicateAttributes()";
+        // check whether the end2 type already has an attribute called 
end1name already exists locally or in any of its relationships
+        String relationshipName = relationshipDef.getName();
+
+        RelationshipEndDef end1 = relationshipDef.getEndDef1();
+        RelationshipEndDef end2 = relationshipDef.getEndDef2();
+
+        String end1Name = end1.getAttributeName();
+        String end1Type = end1.getEntityType().getName();
+
+        String end2Name = end2.getAttributeName();
+        String end2Type = end2.getEntityType().getName();
+
+        if (end1Name.equals(end2Name) && end1Type.equals(end2Type))
+        {
+
+            if (entityAttributeMap.get(end1Type) == null)
+            {
+                // we have not seen this entity before
+                Set<String> attrSet = new HashSet();
+                attrSet.add(end1Name);
+                entityAttributeMap.put(end1Type, attrSet);
+            } else {
+                Set<String> attrset = entityAttributeMap.get(end1Type);
+                // this attribute name should not already be defined for this 
entity
+
+                if (attrset.contains(end2Name))
+                {
+                    OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENDDEF2_NAME_IN_ARCHIVE;
+                    String errorMessage = errorCode.getErrorMessageId()
+                            + errorCode.getFormattedErrorMessage(
+                            end1Type,
+                            end2Name,
+                            relationshipDef.getName()
+                    );
+
+                    throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                            this.getClass().getName(),
+                            methodName,
+                            errorMessage,
+                            errorCode.getSystemAction(),
+                            errorCode.getUserAction());
+                }
+                attrset.add(end1Name);
+            }
+        } else
+        {
+            if (entityAttributeMap.get(end1Type) == null)
+            {
+                // we have not seen this entity before
+                Set<String> attrSet = new HashSet();
+                attrSet.add(end2Name);
+                entityAttributeMap.put(end1Type, attrSet);
+            } else
+            {
+                Set<String> attrset = entityAttributeMap.get(end1Type);
+                // this attribute name should not already be defined for this 
entity
+                if (attrset.contains(end2Name)){
+                    OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENDDEF2_NAME_IN_ARCHIVE;
+                    String errorMessage = errorCode.getErrorMessageId()
+                            + errorCode.getFormattedErrorMessage(
+                            end1Type,
+                            end2Name,
+                            relationshipDef.getName()
+                    );
+
+                    throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                            this.getClass().getName(),
+                            methodName,
+                            errorMessage,
+                            errorCode.getSystemAction(),
+                            errorCode.getUserAction());
+                }
+                attrset.add(end2Name);
+            }
+
+            if (entityAttributeMap.get(end2Type) == null)
+            {
+                // we have not seen this entity before
+                Set<String> attrSet = new HashSet();
+                attrSet.add(end1Name);
+                entityAttributeMap.put(end2Type, attrSet);
+            } else
+                {
+                Set<String> attrset = entityAttributeMap.get(end2Type);
+                // this attribute name should not already be defined for this 
entity
+                if (attrset.contains(end1Name))
+                {
+                    OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENDDEF1_NAME_IN_ARCHIVE;
+                    String errorMessage = errorCode.getErrorMessageId()
+                            + errorCode.getFormattedErrorMessage(
+                            end2Type,
+                            end1Name,
+                            relationshipDef.getName()
+                    );
+
+                    throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                            this.getClass().getName(),
+                            methodName,
+                            errorMessage,
+                            errorCode.getSystemAction(),
+                            errorCode.getUserAction());
+                }
+                attrset.add(end1Name);
+            }
+        }
+        // check whether end1 has a local attribute name that clashes with a 
relationship end
+        EntityDef entityDef1 = entityDefMap.get(end1Type);
+
+        if (entityDef1.getPropertiesDefinition()!=null)
+        {
+            Set<String> attrset = entityAttributeMap.get(end1Type);
+            for (TypeDefAttribute typeDefAttr : 
entityDef1.getPropertiesDefinition())
+            {
+                String localAttributeName = typeDefAttr.getAttributeName();
+                // this attribute name should not already be defined for this 
entity
+
+                if (localAttributeName.equals(end2Name))
+                {
+                    OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENDDEF2_NAME_IN_ARCHIVE;
+                    String errorMessage = errorCode.getErrorMessageId()
+                            + errorCode.getFormattedErrorMessage(
+                            end1Type,
+                            end2Name,
+                            relationshipDef.getName()
+                    );
+
+                    throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                            this.getClass().getName(),
+                            methodName,
+                            errorMessage,
+                            errorCode.getSystemAction(),
+                            errorCode.getUserAction());
+                }
+                attrset.add(end2Name);
+            }
+        }
+        EntityDef entityDef2 = entityDefMap.get(end2Type);
+        if (entityDef2.getPropertiesDefinition()!=null)
+        {
+            Set<String> attrset = entityAttributeMap.get(end2Type);
+            for (TypeDefAttribute typeDefAttr : 
entityDef2.getPropertiesDefinition())
+            {
+                String localAttributeName = typeDefAttr.getAttributeName();
+                // this attribute name should not already be defined for this 
entity
+
+                if (localAttributeName.equals(end1Name))
+                {
+                    OMRSErrorCode errorCode = 
OMRSErrorCode.DUPLICATE_ENDDEF1_NAME_IN_ARCHIVE;
+                    String errorMessage = errorCode.getErrorMessageId()
+                            + errorCode.getFormattedErrorMessage(
+                            end2Type,
+                            end1Name,
+                            relationshipDef.getName()
+                    );
+
+                    throw new 
OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                            this.getClass().getName(),
+                            methodName,
+                            errorMessage,
+                            errorCode.getSystemAction(),
+                            errorCode.getUserAction());
+                }
+                attrset.add(end1Name);
+            }
+        }
+    }
+
 
     /**
      * Add a new entity to the archive.
@@ -994,4 +1258,22 @@ public class OMRSArchiveBuilder
 
         return archive;
     }
+    private void checkForBlanksInTypeName(String typeName)
+    {
+        final String methodName = "checkForBlanksInTypeName()";
+        if (typeName.contains(" "))
+        {
+            OMRSErrorCode errorCode = OMRSErrorCode.BLANK_TYPENAME_IN_ARCHIVE;
+            String        errorMessage = errorCode.getErrorMessageId()
+                    + errorCode.getFormattedErrorMessage(typeName);
+
+            throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
+                    this.getClass().getName(),
+                    methodName,
+                    errorMessage,
+                    errorCode.getSystemAction(),
+                    errorCode.getUserAction());
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/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
index 42d2d87..7994b08 100644
--- 
a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java
+++ 
b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/OMRSArchiveHelper.java
@@ -134,7 +134,7 @@ public class OMRSArchiveHelper
         CollectionDef   collectionDef = new 
CollectionDef(CollectionDefCategory.OM_COLLECTION_MAP);
 
         collectionDef.setGUID(guid);
-        collectionDef.setName("map<" + propertyKeyType.getName() + ", " + 
propertyValueType.getName() + ">");
+        collectionDef.setName("map<" + propertyKeyType.getName() + "," + 
propertyValueType.getName() + ">");
         collectionDef.setDescription(description);
         collectionDef.setDescriptionGUID(descriptionGUID);
         collectionDef.setVersion(versionNumber);
@@ -405,7 +405,7 @@ public class OMRSArchiveHelper
         attribute.setAttributeName(attributeName);
         attribute.setAttributeDescription(attributeDescription);
         attribute.setAttributeDescriptionGUID(attributeDescriptionGUID);
-        
attribute.setAttributeType(this.archiveBuilder.getCollectionDef("map<string, 
string>"));
+        
attribute.setAttributeType(this.archiveBuilder.getCollectionDef("map<string,string>"));
         attribute.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE);
         attribute.setValuesMinCount(0);
         attribute.setValuesMaxCount(1);

http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/opentypes/OpenMetadataTypesArchive.java
----------------------------------------------------------------------
diff --git 
a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/opentypes/OpenMetadataTypesArchive.java
 
b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/opentypes/OpenMetadataTypesArchive.java
index faab96c..3fe4d34 100644
--- 
a/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/opentypes/OpenMetadataTypesArchive.java
+++ 
b/omrs/src/main/java/org/apache/atlas/omrs/archivemanager/opentypes/OpenMetadataTypesArchive.java
@@ -186,7 +186,7 @@ public class OpenMetadataTypesArchive
 
 
     /**
-     * Defines the "map<string, string>" type.
+     * Defines the "map<string,string>" type.
      *
      * @return CollectionDef for this type
      */
@@ -10959,7 +10959,7 @@ public class OpenMetadataTypesArchive
          * Set up end 1.
          */
         final String               end1EntityType               = 
"GlossaryTerm";
-        final String               end1AttributeName            = "attributes";
+        final String               end1AttributeName            = 
"attributesTypedBy";
         final String               end1AttributeDescription     = "Attributes 
of this type.";
         final String               end1AttributeDescriptionGUID = null;
         final AttributeCardinality end1Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;
@@ -12885,9 +12885,9 @@ public class OpenMetadataTypesArchive
         /*
          * Set up end 1.
          */
-        final String               end1EntityType               = 
"GovernanceRule";
-        final String               end1AttributeName            = 
"implementsGovernanceRules";
-        final String               end1AttributeDescription     = "The rules 
that are implemented by this component.";
+        final String               end1EntityType               = 
"GovernanceProcess";
+        final String               end1AttributeName            = 
"implementsGovernanceProcesses";
+        final String               end1AttributeDescription     = "The 
processes that are implemented by this component.";
         final String               end1AttributeDescriptionGUID = null;
         final AttributeCardinality end1Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;
 
@@ -12902,9 +12902,9 @@ public class OpenMetadataTypesArchive
         /*
          * Set up end 2.
          */
-        final String               end2EntityType               = 
"SoftwareComponent";
+        final String               end2EntityType               = "Process";
         final String               end2AttributeName            = 
"implementations";
-        final String               end2AttributeDescription     = "The 
software components that implement this governance rule.";
+        final String               end2AttributeDescription     = "The 
processes that implement this governance process.";
         final String               end2AttributeDescriptionGUID = null;
         final AttributeCardinality end2Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;
 
@@ -12922,7 +12922,7 @@ public class OpenMetadataTypesArchive
         TypeDefAttribute            property;
 
         final String attribute1Name            = "notes";
-        final String attribute1Description     = "Documents reasons for 
implementing the rule using this implementation.";
+        final String attribute1Description     = "Documents reasons for 
implementing the process using this implementation.";
         final String attribute1DescriptionGUID = null;
 
         property = archiveHelper.getStringTypeDefAttribute(attribute1Name, 
attribute1Description, attribute1DescriptionGUID);
@@ -14438,8 +14438,8 @@ public class OpenMetadataTypesArchive
          * Set up end 1.
          */
         final String               end1EntityType               = 
"Referenceable";
-        final String               end1AttributeName            = "licensed";
-        final String               end1AttributeDescription     = "Items 
licensed by this type of license.";
+        final String               end1AttributeName            = "certifies";
+        final String               end1AttributeDescription     = "Items 
certified by this type of certification.";
         final String               end1AttributeDescriptionGUID = null;
         final AttributeCardinality end1Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;
 
@@ -14454,9 +14454,9 @@ public class OpenMetadataTypesArchive
         /*
          * Set up end 2.
          */
-        final String               end2EntityType               = 
"LicenseType";
-        final String               end2AttributeName            = "licenses";
-        final String               end2AttributeDescription     = "The types 
of licenses that apply.";
+        final String               end2EntityType               = 
"CertificationType";
+        final String               end2AttributeName            = 
"certifications";
+        final String               end2AttributeDescription     = "The types 
of certifications that apply.";
         final String               end2AttributeDescriptionGUID = null;
         final AttributeCardinality end2Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;
 
@@ -16430,7 +16430,7 @@ public class OpenMetadataTypesArchive
          * Set up end 2.
          */
         final String               end2EntityType               = "SchemaType";
-        final String               end2AttributeName            = 
"apiResponse";
+        final String               end2AttributeName            = "apiHeader";
         final String               end2AttributeDescription     = "Header 
structure for this API operation.";
         final String               end2AttributeDescriptionGUID = null;
         final AttributeCardinality end2Cardinality              = 
AttributeCardinality.ANY_NUMBER_UNORDERED;

http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/omrs/src/main/java/org/apache/atlas/omrs/ffdc/OMRSErrorCode.java
----------------------------------------------------------------------
diff --git a/omrs/src/main/java/org/apache/atlas/omrs/ffdc/OMRSErrorCode.java 
b/omrs/src/main/java/org/apache/atlas/omrs/ffdc/OMRSErrorCode.java
index f1871ef..9d84f36 100644
--- a/omrs/src/main/java/org/apache/atlas/omrs/ffdc/OMRSErrorCode.java
+++ b/omrs/src/main/java/org/apache/atlas/omrs/ffdc/OMRSErrorCode.java
@@ -399,6 +399,30 @@ public enum OMRSErrorCode
             "A request for a type from category {0} passed a null name.",
             "The build of the archive terminates.",
             "Verify the definition of the elements being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    DUPLICATE_ENDDEF1_NAME_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-006 ",
+            "endDef2 type {0} and EndDef1 name {1} in RelationshipDef {2} are 
incorrect, because entity {0} already has a {1} attribute or is referred to in 
an existing relationshipDef with an endDef with name {1}.",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    DUPLICATE_ENDDEF2_NAME_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-007 ",
+            "EndDef1 type {0} and EndDef2 name {1} in RelationshipDef {2} are 
incorrect, because entity {0} already has a {1} attribute or is referred to in 
an existing relationshipDef with an endDef with name {1}.",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    DUPLICATE_RELATIONSHIP_ATTR_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-008 ",
+            "Duplicate attribute name {0} is defined in RelationshipDef {2}. ",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    DUPLICATE_ENTITY_ATTR_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-009 ",
+            "Duplicate attribute name {0} is defined in EntityDef {2}. ",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    DUPLICATE_CLASSIFICATION_ATTR_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-010 
",
+            "Duplicate attribute name {0} is defined in ClassificationDef {2}. 
",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
+    BLANK_TYPENAME_IN_ARCHIVE(400, "OMRS-ARCHIVEBUILDER-400-011 ",
+            "Type name {0} is invalid because it contains a blank character. ",
+            "The build of the archive terminates.",
+            "Verify the definition of the types being added to the archive. 
Once the definitions have been corrected, rerun the request."),
     NULL_LOG_RECORD(400, "OMRS-AUDITLOG-400-001 ",
             "A null log record has been passed by the audit log to the audit 
log store.",
             "The audit log store throws an exception and the log record is not 
written to the audit log store.",

http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/opentypes/TestOpenMetadataTypesArchive.java
----------------------------------------------------------------------
diff --git 
a/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/opentypes/TestOpenMetadataTypesArchive.java
 
b/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/opentypes/TestOpenMetadataTypesArchive.java
new file mode 100644
index 0000000..3f85317
--- /dev/null
+++ 
b/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/opentypes/TestOpenMetadataTypesArchive.java
@@ -0,0 +1,47 @@
+/*
+ * 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.opentypes;
+
+
+import org.apache.atlas.omrs.archivemanager.properties.OpenMetadataArchive;
+import 
org.apache.atlas.omrs.archivemanager.properties.OpenMetadataArchiveTypeStore;
+import org.apache.atlas.omrs.metadatacollection.properties.typedefs.*;
+
+import java.util.*;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+import static org.testng.Assert.assertFalse;
+
+/**
+ * Test that the open metadata archive types load without error.
+ */
+public class TestOpenMetadataTypesArchive
+{
+    @Test
+    public void testOpenMetadataTypesload()
+    {
+        OpenMetadataTypesArchive archive = new OpenMetadataTypesArchive();
+        //load the archive
+        OpenMetadataArchive archiveProperties = 
archive.getOpenMetadataArchive();
+        OpenMetadataArchiveTypeStore typeStore = 
archiveProperties.getArchiveTypeStore();
+        assert (typeStore != null);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/atlas/blob/20d4f4d8/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/store/TestOMRSArchiveBuilder.java
----------------------------------------------------------------------
diff --git 
a/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/store/TestOMRSArchiveBuilder.java
 
b/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/store/TestOMRSArchiveBuilder.java
new file mode 100644
index 0000000..ccf0de6
--- /dev/null
+++ 
b/omrs/src/test/java/org/apache/atlas/omrs/archivemanager/store/TestOMRSArchiveBuilder.java
@@ -0,0 +1,339 @@
+/*
+ * 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.store;
+
+import org.apache.atlas.omrs.archivemanager.OMRSArchiveBuilder;
+import org.apache.atlas.omrs.archivemanager.properties.OpenMetadataArchive;
+import org.apache.atlas.omrs.archivemanager.properties.OpenMetadataArchiveType;
+import org.apache.atlas.omrs.ffdc.exception.OMRSLogicErrorException;
+import org.apache.atlas.omrs.metadatacollection.properties.typedefs.*;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+public class TestOMRSArchiveBuilder
+{
+    @Test
+    public void testAddEntityDef()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+
+    }
+    @Test
+    public void testAddRelationshipDef()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+        assertNotNull(oMRSArchiveBuilder);
+
+        List<TypeDefAttribute> propertyList1 = new ArrayList();
+        TypeDefAttribute attr1 = new TypeDefAttribute();
+        attr1.setAttributeName("abc");
+        propertyList1.add(attr1);
+        entityDefA.setPropertiesDefinition(propertyList1);
+
+        List<TypeDefAttribute> propertyList2 = new ArrayList();
+        TypeDefAttribute attr2 = new TypeDefAttribute();
+        attr2.setAttributeName("abc2");
+        propertyList2.add(attr2);
+        entityDefB.setPropertiesDefinition(propertyList2);
+
+        RelationshipDef relationshipDef = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","EntityDef1",1L,"1");
+        RelationshipEndDef endDef1 = new RelationshipEndDef();
+        endDef1.setAttributeName("aaaa");
+
+        TypeDefLink entityTypeA = new TypeDefLink();
+        entityTypeA.setGUID("1111");
+        entityTypeA.setName("EntityDefA");
+        endDef1.setEntityType(entityTypeA);
+        relationshipDef.setEndDef1(endDef1);
+
+        RelationshipEndDef endDef2 = new RelationshipEndDef();
+        endDef2.setAttributeName("bbbb");
+        TypeDefLink entityTypeB= new TypeDefLink();
+        entityTypeB.setGUID("2222");
+        entityTypeB.setName("EntityDefB");
+        endDef2.setEntityType(entityTypeB);
+        relationshipDef.setEndDef2(endDef2);
+
+        List<TypeDefAttribute> propertyList3 = new ArrayList();
+        TypeDefAttribute attr3 = new TypeDefAttribute();
+        attr3.setAttributeName("abc3");
+        propertyList3.add(attr3);
+        relationshipDef.setPropertiesDefinition(propertyList3);
+        oMRSArchiveBuilder.addRelationshipDef(relationshipDef);
+    }
+
+    @Test
+    public void testAddEntityDefSameAttr()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        List<TypeDefAttribute> propertyList1 = new ArrayList();
+        TypeDefAttribute attr1 = new TypeDefAttribute();
+        attr1.setAttributeName("abc");
+        propertyList1.add(attr1);
+        TypeDefAttribute attr2 = new TypeDefAttribute();
+        attr2.setAttributeName("abc");
+        propertyList1.add(attr2);
+        entityDefA.setPropertiesDefinition(propertyList1);
+        try {
+            oMRSArchiveBuilder.addEntityDef(entityDefA);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e) {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-009"));
+        }
+    }
+    @Test
+    public void testAddClassificationDefSameAttr() {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        ClassificationDef classificationDef = new 
ClassificationDef(TypeDefCategory.CLASSIFICATION_DEF,"1111","EntityDefA",1L,"1");
+        List<TypeDefAttribute> propertyList1 = new ArrayList();
+        TypeDefAttribute attr1 = new TypeDefAttribute();
+        attr1.setAttributeName("abc");
+        propertyList1.add(attr1);
+        TypeDefAttribute attr2 = new TypeDefAttribute();
+        attr2.setAttributeName("abc");
+        propertyList1.add(attr2);
+        classificationDef.setPropertiesDefinition(propertyList1);
+        try {
+            oMRSArchiveBuilder.addClassificationDef(classificationDef);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e) {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-010"));
+        }
+    }
+    @Test
+    public void testAddRelationshipDefSameAttr() {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        List<TypeDefAttribute> propertyList1 = new ArrayList();
+        TypeDefAttribute attr1 = new TypeDefAttribute();
+        attr1.setAttributeName("abc");
+        propertyList1.add(attr1);
+        entityDefA.setPropertiesDefinition(propertyList1);
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        List<TypeDefAttribute> propertyList2 = new ArrayList();
+        TypeDefAttribute attr2 = new TypeDefAttribute();
+        attr2.setAttributeName("abc2");
+        propertyList2.add(attr2);
+        entityDefB.setPropertiesDefinition(propertyList2);
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+
+        RelationshipDef relationshipDef = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","RelDef1",1L,"1");
+        RelationshipEndDef endDef1 = new RelationshipEndDef();
+        endDef1.setAttributeName("aaaa");
+
+        TypeDefLink entityTypeA = new TypeDefLink();
+        entityTypeA.setGUID("1111");
+        entityTypeA.setName("EntityDefA");
+        endDef1.setEntityType(entityTypeA);
+        relationshipDef.setEndDef1(endDef1);
+
+        RelationshipEndDef endDef2 = new RelationshipEndDef();
+        endDef2.setAttributeName("bbbb");
+        TypeDefLink entityTypeB= new TypeDefLink();
+        entityTypeB.setGUID("2222");
+        entityTypeB.setName("EntityDefB");
+        endDef2.setEntityType(entityTypeB);
+        relationshipDef.setEndDef2(endDef2);
+
+        List<TypeDefAttribute> propertyList3 = new ArrayList();
+        TypeDefAttribute attr3 = new TypeDefAttribute();
+        attr3.setAttributeName("abc3");
+        TypeDefAttribute attr4 = new TypeDefAttribute();
+        attr4.setAttributeName("abc3");
+        propertyList3.add(attr3);
+        propertyList3.add(attr4);
+
+        relationshipDef.setPropertiesDefinition(propertyList3);
+        try {
+            oMRSArchiveBuilder.addRelationshipDef(relationshipDef);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e) {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-008"));
+        }
+    }
+
+
+    @Test
+    public void testAddRelationshipDefDuplicateEnd2()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+        EntityDef entityDefC = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1122","EntityDefC",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefC);
+
+        RelationshipDef relationshipDef1 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","RelDef1",1L,"1");
+        
createEndDefs(relationshipDef1,"1111","aaaa","EntityDefA","2222","bbbb","EntityDefB");
+        oMRSArchiveBuilder.addRelationshipDef(relationshipDef1);
+
+        RelationshipDef relationshipDef2 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"4444","RelDef2",1L,"1");
+        
createEndDefs(relationshipDef2,"1111","aaaa","EntityDefA","1122","bbbb","EntityDefC");
+
+        try {
+            oMRSArchiveBuilder.addRelationshipDef(relationshipDef2);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e) {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-007"));
+        }
+    }
+
+    @Test
+    public void testAddRelationshipDefDuplicateEnd1()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+        EntityDef entityDefC = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1122","EntityDefC",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefC);
+
+        List<TypeDefAttribute> propertyList1 = new ArrayList();
+        TypeDefAttribute attr1 = new TypeDefAttribute();
+        attr1.setAttributeName("abc");
+        propertyList1.add(attr1);
+        entityDefA.setPropertiesDefinition(propertyList1);
+
+        List<TypeDefAttribute> propertyList2 = new ArrayList();
+        TypeDefAttribute attr2 = new TypeDefAttribute();
+        attr2.setAttributeName("abc2");
+        propertyList2.add(attr2);
+        entityDefB.setPropertiesDefinition(propertyList2);
+
+        RelationshipDef relationshipDef1 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","RelDef1",1L,"1");
+        
createEndDefs(relationshipDef1,"2222","bbbb","EntityDefB","1111","aaaa","EntityDefA");
+        oMRSArchiveBuilder.addRelationshipDef(relationshipDef1);
+
+        RelationshipDef relationshipDef2 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"4444","RelDef2",1L,"1");
+        
createEndDefs(relationshipDef2,"1122","bbbb","EntityDefC","1111","aaaa","EntityDefA");
+
+        try
+        {
+            oMRSArchiveBuilder.addRelationshipDef(relationshipDef2);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e)
+        {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-006"));
+        }
+    }
+
+    @Test
+    public void testAddRelationshipDefDuplicateEnd1NameAndLocal()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        List<TypeDefAttribute> propertyList0 = new ArrayList();
+        TypeDefAttribute attr = new TypeDefAttribute();
+        attr.setAttributeName("aaaa");
+        propertyList0.add(attr);
+        entityDefA.setPropertiesDefinition(propertyList0);
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+
+        RelationshipDef relationshipDef1 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","RelDef1",1L,"1");
+        
createEndDefs(relationshipDef1,"2222","aaaa","EntityDefB","1111","bbbb","EntityDefA");
+
+        try
+        {
+            oMRSArchiveBuilder.addRelationshipDef(relationshipDef1);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e)
+        {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-006"));
+        }
+    }
+    @Test
+    public void testAddRelationshipDefDuplicateEnd2NameAndLocal()
+    {
+        OMRSArchiveBuilder oMRSArchiveBuilder = getOmrsArchiveBuilder();
+        EntityDef entityDefA = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"1111","EntityDefA",1L,"1");
+        List<TypeDefAttribute> propertyList = new ArrayList();
+       ;
+        oMRSArchiveBuilder.addEntityDef(entityDefA);
+
+        EntityDef entityDefB = new 
EntityDef(TypeDefCategory.ENTITY_DEF,"2222","EntityDefB",1L,"1");
+        TypeDefAttribute attr = new TypeDefAttribute();
+        attr.setAttributeName("bbbb");
+        propertyList.add(attr);
+        entityDefB.setPropertiesDefinition(propertyList);
+        oMRSArchiveBuilder.addEntityDef(entityDefB);
+
+        RelationshipDef relationshipDef1 = new 
RelationshipDef(TypeDefCategory.RELATIONSHIP_DEF,"3333","RelDef1",1L,"1");
+        
createEndDefs(relationshipDef1,"2222","aaaa","EntityDefB","1111","bbbb","EntityDefA");
+
+        try
+        {
+            oMRSArchiveBuilder.addRelationshipDef(relationshipDef1);
+            assertTrue(false);
+        } catch (OMRSLogicErrorException e)
+        {
+            assertTrue(e.getMessage().contains("OMRS-ARCHIVEBUILDER-400-007"));
+        }
+    }
+
+    private void createEndDefs(RelationshipDef relationshipDef,String 
guid1,String name1, String type1,String guid2,String name2, String type2)
+    {
+        RelationshipEndDef endDef1 = new RelationshipEndDef();
+        endDef1.setAttributeName(name1);
+        TypeDefLink entityType1 = new TypeDefLink();
+        entityType1.setGUID(guid1);
+        entityType1.setName(type1);
+        endDef1.setEntityType(entityType1);
+        relationshipDef.setEndDef1(endDef1);
+
+        RelationshipEndDef endDef2 = new RelationshipEndDef();
+        endDef2.setAttributeName(name2);
+        TypeDefLink entityType2 = new TypeDefLink();
+        entityType2.setGUID(guid2);
+        entityType2.setName(type2);
+        endDef2.setEntityType(entityType2);
+        relationshipDef.setEndDef2(endDef2);
+    }
+
+    private OMRSArchiveBuilder getOmrsArchiveBuilder()
+    {
+        OMRSArchiveBuilder archive = new OMRSArchiveBuilder("guid",
+                    "testArchiveName",
+                    "test description",
+                     OpenMetadataArchiveType.CONTENT_PACK,
+                    "testOwner",
+                    null,
+                    null);
+        return archive;
+    }
+}
\ No newline at end of file

Reply via email to