Commit 20d4f4d8 by David Radley Committed by Graham Wallis

ATLAS2604 Minor fixups to open metadata archive types

parent e7aec335
...@@ -63,6 +63,10 @@ public class OMRSArchiveBuilder ...@@ -63,6 +63,10 @@ public class OMRSArchiveBuilder
private ArrayList<Relationship> relationshipList = new ArrayList<>(); private ArrayList<Relationship> relationshipList = new ArrayList<>();
private Map<String, Object> guidMap = new HashMap<>(); private Map<String, Object> guidMap = new HashMap<>();
private Map<String, Object> nameMap = 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); private static final Logger log = LoggerFactory.getLogger(OMRSArchiveBuilder.class);
...@@ -114,6 +118,7 @@ public class OMRSArchiveBuilder ...@@ -114,6 +118,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding PrimitiveDef: " + primitiveDef.toString()); log.debug("Adding PrimitiveDef: " + primitiveDef.toString());
} }
this.checkForBlanksInTypeName(primitiveDef.getName());
PrimitiveDef duplicateElement = primitiveDefMap.put(primitiveDef.getName(), primitiveDef); PrimitiveDef duplicateElement = primitiveDefMap.put(primitiveDef.getName(), primitiveDef);
...@@ -242,6 +247,7 @@ public class OMRSArchiveBuilder ...@@ -242,6 +247,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding CollectionDef: " + collectionDef.toString()); log.debug("Adding CollectionDef: " + collectionDef.toString());
} }
this.checkForBlanksInTypeName(collectionDef.getName());
CollectionDef duplicateElement = collectionDefMap.put(collectionDef.getName(), collectionDef); CollectionDef duplicateElement = collectionDefMap.put(collectionDef.getName(), collectionDef);
...@@ -370,6 +376,7 @@ public class OMRSArchiveBuilder ...@@ -370,6 +376,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding EnumDef: " + enumDef.toString()); log.debug("Adding EnumDef: " + enumDef.toString());
} }
this.checkForBlanksInTypeName(enumDef.getName());
EnumDef duplicateElement = enumDefMap.put(enumDef.getName(), enumDef); EnumDef duplicateElement = enumDefMap.put(enumDef.getName(), enumDef);
...@@ -498,6 +505,7 @@ public class OMRSArchiveBuilder ...@@ -498,6 +505,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding ClassificationDef: " + classificationDef.toString()); log.debug("Adding ClassificationDef: " + classificationDef.toString());
} }
this.checkForBlanksInTypeName(classificationDef.getName());
ClassificationDef duplicateElement = classificationDefMap.put(classificationDef.getName(), classificationDef); ClassificationDef duplicateElement = classificationDefMap.put(classificationDef.getName(), classificationDef);
...@@ -553,6 +561,33 @@ public class OMRSArchiveBuilder ...@@ -553,6 +561,33 @@ public class OMRSArchiveBuilder
errorCode.getSystemAction(), errorCode.getSystemAction(),
errorCode.getUserAction()); 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); classificationDefList.add(classificationDef);
} }
...@@ -574,6 +609,7 @@ public class OMRSArchiveBuilder ...@@ -574,6 +609,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding EntityDef: " + entityDef.toString()); log.debug("Adding EntityDef: " + entityDef.toString());
} }
this.checkForBlanksInTypeName(entityDef.getName());
EntityDef duplicateElement = entityDefMap.put(entityDef.getName(), entityDef); EntityDef duplicateElement = entityDefMap.put(entityDef.getName(), entityDef);
...@@ -629,7 +665,33 @@ public class OMRSArchiveBuilder ...@@ -629,7 +665,33 @@ public class OMRSArchiveBuilder
errorCode.getSystemAction(), errorCode.getSystemAction(),
errorCode.getUserAction()); 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); entityDefList.add(entityDef);
} }
} }
...@@ -702,7 +764,7 @@ public class OMRSArchiveBuilder ...@@ -702,7 +764,7 @@ public class OMRSArchiveBuilder
{ {
log.debug("Adding RelationshipDef: " + relationshipDef.toString()); log.debug("Adding RelationshipDef: " + relationshipDef.toString());
} }
this.checkForBlanksInTypeName(relationshipDef.getName());
RelationshipDef duplicateElement = relationshipDefMap.put(relationshipDef.getName(), relationshipDef); RelationshipDef duplicateElement = relationshipDefMap.put(relationshipDef.getName(), relationshipDef);
if (duplicateElement != null) if (duplicateElement != null)
...@@ -746,22 +808,224 @@ public class OMRSArchiveBuilder ...@@ -746,22 +808,224 @@ public class OMRSArchiveBuilder
{ {
OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE; OMRSErrorCode errorCode = OMRSErrorCode.DUPLICATE_TYPENAME_IN_ARCHIVE;
String errorMessage = errorCode.getErrorMessageId() String errorMessage = errorCode.getErrorMessageId()
+ errorCode.getFormattedErrorMessage(relationshipDef.getName(), + errorCode.getFormattedErrorMessage(relationshipDef.getName(),
duplicateName.toString(), duplicateName.toString(),
relationshipDef.toString()); relationshipDef.toString());
throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(), throw new OMRSLogicErrorException(errorCode.getHTTPErrorCode(),
this.getClass().getName(), this.getClass().getName(),
methodName, methodName,
errorMessage, errorMessage,
errorCode.getSystemAction(), errorCode.getSystemAction(),
errorCode.getUserAction()); 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); 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. * Add a new entity to the archive.
...@@ -994,4 +1258,22 @@ public class OMRSArchiveBuilder ...@@ -994,4 +1258,22 @@ public class OMRSArchiveBuilder
return archive; 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());
}
}
} }
...@@ -134,7 +134,7 @@ public class OMRSArchiveHelper ...@@ -134,7 +134,7 @@ public class OMRSArchiveHelper
CollectionDef collectionDef = new CollectionDef(CollectionDefCategory.OM_COLLECTION_MAP); CollectionDef collectionDef = new CollectionDef(CollectionDefCategory.OM_COLLECTION_MAP);
collectionDef.setGUID(guid); collectionDef.setGUID(guid);
collectionDef.setName("map<" + propertyKeyType.getName() + ", " + propertyValueType.getName() + ">"); collectionDef.setName("map<" + propertyKeyType.getName() + "," + propertyValueType.getName() + ">");
collectionDef.setDescription(description); collectionDef.setDescription(description);
collectionDef.setDescriptionGUID(descriptionGUID); collectionDef.setDescriptionGUID(descriptionGUID);
collectionDef.setVersion(versionNumber); collectionDef.setVersion(versionNumber);
...@@ -405,7 +405,7 @@ public class OMRSArchiveHelper ...@@ -405,7 +405,7 @@ public class OMRSArchiveHelper
attribute.setAttributeName(attributeName); attribute.setAttributeName(attributeName);
attribute.setAttributeDescription(attributeDescription); attribute.setAttributeDescription(attributeDescription);
attribute.setAttributeDescriptionGUID(attributeDescriptionGUID); 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.setAttributeCardinality(AttributeCardinality.AT_MOST_ONE);
attribute.setValuesMinCount(0); attribute.setValuesMinCount(0);
attribute.setValuesMaxCount(1); attribute.setValuesMaxCount(1);
......
...@@ -186,7 +186,7 @@ public class OpenMetadataTypesArchive ...@@ -186,7 +186,7 @@ public class OpenMetadataTypesArchive
/** /**
* Defines the "map<string, string>" type. * Defines the "map<string,string>" type.
* *
* @return CollectionDef for this type * @return CollectionDef for this type
*/ */
...@@ -10959,7 +10959,7 @@ public class OpenMetadataTypesArchive ...@@ -10959,7 +10959,7 @@ public class OpenMetadataTypesArchive
* Set up end 1. * Set up end 1.
*/ */
final String end1EntityType = "GlossaryTerm"; final String end1EntityType = "GlossaryTerm";
final String end1AttributeName = "attributes"; final String end1AttributeName = "attributesTypedBy";
final String end1AttributeDescription = "Attributes of this type."; final String end1AttributeDescription = "Attributes of this type.";
final String end1AttributeDescriptionGUID = null; final String end1AttributeDescriptionGUID = null;
final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
...@@ -12885,9 +12885,9 @@ public class OpenMetadataTypesArchive ...@@ -12885,9 +12885,9 @@ public class OpenMetadataTypesArchive
/* /*
* Set up end 1. * Set up end 1.
*/ */
final String end1EntityType = "GovernanceRule"; final String end1EntityType = "GovernanceProcess";
final String end1AttributeName = "implementsGovernanceRules"; final String end1AttributeName = "implementsGovernanceProcesses";
final String end1AttributeDescription = "The rules that are implemented by this component."; final String end1AttributeDescription = "The processes that are implemented by this component.";
final String end1AttributeDescriptionGUID = null; final String end1AttributeDescriptionGUID = null;
final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
...@@ -12902,9 +12902,9 @@ public class OpenMetadataTypesArchive ...@@ -12902,9 +12902,9 @@ public class OpenMetadataTypesArchive
/* /*
* Set up end 2. * Set up end 2.
*/ */
final String end2EntityType = "SoftwareComponent"; final String end2EntityType = "Process";
final String end2AttributeName = "implementations"; 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 String end2AttributeDescriptionGUID = null;
final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
...@@ -12922,7 +12922,7 @@ public class OpenMetadataTypesArchive ...@@ -12922,7 +12922,7 @@ public class OpenMetadataTypesArchive
TypeDefAttribute property; TypeDefAttribute property;
final String attribute1Name = "notes"; 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; final String attribute1DescriptionGUID = null;
property = archiveHelper.getStringTypeDefAttribute(attribute1Name, attribute1Description, attribute1DescriptionGUID); property = archiveHelper.getStringTypeDefAttribute(attribute1Name, attribute1Description, attribute1DescriptionGUID);
...@@ -14438,8 +14438,8 @@ public class OpenMetadataTypesArchive ...@@ -14438,8 +14438,8 @@ public class OpenMetadataTypesArchive
* Set up end 1. * Set up end 1.
*/ */
final String end1EntityType = "Referenceable"; final String end1EntityType = "Referenceable";
final String end1AttributeName = "licensed"; final String end1AttributeName = "certifies";
final String end1AttributeDescription = "Items licensed by this type of license."; final String end1AttributeDescription = "Items certified by this type of certification.";
final String end1AttributeDescriptionGUID = null; final String end1AttributeDescriptionGUID = null;
final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end1Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
...@@ -14454,9 +14454,9 @@ public class OpenMetadataTypesArchive ...@@ -14454,9 +14454,9 @@ public class OpenMetadataTypesArchive
/* /*
* Set up end 2. * Set up end 2.
*/ */
final String end2EntityType = "LicenseType"; final String end2EntityType = "CertificationType";
final String end2AttributeName = "licenses"; final String end2AttributeName = "certifications";
final String end2AttributeDescription = "The types of licenses that apply."; final String end2AttributeDescription = "The types of certifications that apply.";
final String end2AttributeDescriptionGUID = null; final String end2AttributeDescriptionGUID = null;
final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
...@@ -16430,7 +16430,7 @@ public class OpenMetadataTypesArchive ...@@ -16430,7 +16430,7 @@ public class OpenMetadataTypesArchive
* Set up end 2. * Set up end 2.
*/ */
final String end2EntityType = "SchemaType"; final String end2EntityType = "SchemaType";
final String end2AttributeName = "apiResponse"; final String end2AttributeName = "apiHeader";
final String end2AttributeDescription = "Header structure for this API operation."; final String end2AttributeDescription = "Header structure for this API operation.";
final String end2AttributeDescriptionGUID = null; final String end2AttributeDescriptionGUID = null;
final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED; final AttributeCardinality end2Cardinality = AttributeCardinality.ANY_NUMBER_UNORDERED;
......
...@@ -399,6 +399,30 @@ public enum OMRSErrorCode ...@@ -399,6 +399,30 @@ public enum OMRSErrorCode
"A request for a type from category {0} passed a null name.", "A request for a type from category {0} passed a null name.",
"The build of the archive terminates.", "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."), "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 ", NULL_LOG_RECORD(400, "OMRS-AUDITLOG-400-001 ",
"A null log record has been passed by the audit log to the audit log store.", "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.", "The audit log store throws an exception and the log record is not written to the audit log store.",
......
/*
* 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);
}
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment