Commit 5e7f8949 by Mandar Ambawane Committed by Madhan Neethiraj

ATLAS-3619: updated namespace-def to allow attributes with no associated…

ATLAS-3619: updated namespace-def to allow attributes with no associated entity-types, mandatory attributes and unique attributes Signed-off-by: 's avatarMadhan Neethiraj <madhan@apache.org>
parent 3e035c45
...@@ -163,12 +163,10 @@ public enum AtlasErrorCode { ...@@ -163,12 +163,10 @@ public enum AtlasErrorCode {
INVALID_PROPAGATION_TYPE(400, "ATLAS-400-00-091", "Invalid propagation {0} for relationship-type={1}. Default value is {2}"), INVALID_PROPAGATION_TYPE(400, "ATLAS-400-00-091", "Invalid propagation {0} for relationship-type={1}. Default value is {2}"),
DUPLICATE_NAMESPACE_ATTRIBUTE(400, "ATLAS-400-00-092", "Duplicate Namespace Attributes: {0} not allowed within the same namespace: {1}"), DUPLICATE_NAMESPACE_ATTRIBUTE(400, "ATLAS-400-00-092", "Duplicate Namespace Attributes: {0} not allowed within the same namespace: {1}"),
APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED(400, "ATLAS-400-00-093", "Cannot remove applicableEntityTypes in Attribute Def: {0}, defined in namespace: {1}"), APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED(400, "ATLAS-400-00-093", "Cannot remove applicableEntityTypes in Attribute Def: {0}, defined in namespace: {1}"),
NAMESPACE_DEF_MANDATORY_ATTRIBUTE_NOT_ALLOWED(400, "ATLAS-400-00-094", "{0}.{1} : namespaces can not have mandatory attribute"), NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-094", "{0}.{1}: invalid attribute type. Namespace attribute cannot be of type entity/classification/struct/namespace"),
NAMESPACE_DEF_UNIQUE_ATTRIBUTE_NOT_ALLOWED(400, "ATLAS-400-00-095", "{0}.{1} : namespaces can not have unique attribute"), INVALID_NAMESPACE_NAME_FOR_ENTITY_TYPE(400, "ATLAS-400-00-095", "Invalid Namespace: {0} specified for entity, applicable namespaces: {1}"),
NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-096", "{0}.{1}: invalid attribute type. Namespace attribute cannot be of type entity/classification/struct/namespace"), NAMESPACE_ATTRIBUTE_DOES_NOT_EXIST(400, "ATLAS-400-00-096", "Namespace attribute does not exist in entity: {0}"),
INVALID_NAMESPACE_NAME_FOR_ENTITY_TYPE(400, "ATLAS-400-00-097", "Invalid Namespace: {0} specified for entity, applicable namespaces: {1}"), NAMESPACE_ATTRIBUTE_ALREADY_EXISTS(400, "ATLAS-400-00-097", "Namespace attribute already exists in entity: {0}"),
NAMESPACE_ATTRIBUTE_DOES_NOT_EXIST(400, "ATLAS-400-00-098", "Namespace attribute does not exist in entity: {0}"),
NAMESPACE_ATTRIBUTE_ALREADY_EXISTS(400, "ATLAS-400-00-099", "Namespace attribute already exists in entity: {0}"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"), UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
...@@ -84,14 +84,6 @@ public class AtlasNamespaceType extends AtlasStructType { ...@@ -84,14 +84,6 @@ public class AtlasNamespaceType extends AtlasStructType {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName); throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
} }
if (!attributeDef.getIsOptional()) {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_MANDATORY_ATTRIBUTE_NOT_ALLOWED, getTypeName(), attrName);
}
if (attributeDef.getIsUnique()) {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_UNIQUE_ATTRIBUTE_NOT_ALLOWED, getTypeName(), attrName);
}
Set<String> entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES); Set<String> entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
Set<AtlasEntityType> entityTypes = new HashSet<>(); Set<AtlasEntityType> entityTypes = new HashSet<>();
...@@ -105,8 +97,6 @@ public class AtlasNamespaceType extends AtlasStructType { ...@@ -105,8 +97,6 @@ public class AtlasNamespaceType extends AtlasStructType {
entityTypes.add(entityType); entityTypes.add(entityType);
} }
} else {
throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, attributeDef.getName(), "options." + ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
} }
AtlasNamespaceAttribute nsAttribute; AtlasNamespaceAttribute nsAttribute;
......
...@@ -166,25 +166,7 @@ public class AtlasNamespaceDefStoreV2Test { ...@@ -166,25 +166,7 @@ public class AtlasNamespaceDefStoreV2Test {
typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef)); typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef));
typeDefStore.updateTypesDef(typesDefs); typeDefStore.updateTypesDef(typesDefs);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE); Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED);
} finally {
typesDefs = existingTypeDefs;
}
}
/**
* Test to verify that we cannot have an empty applicable entity types in an attribute definition
* @throws AtlasBaseException
*/
@Test
public void createNsAttrDefWithoutApplicableEntityTypes() {
AtlasTypesDef existingTypeDefs = typesDefs;
try {
typesDefs.setNamespaceDefs(Arrays.asList(createNamespaceDef2(namespaceName)));
typeDefStore.updateTypesDef(typesDefs);
} catch (AtlasBaseException e) {
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE);
} finally { } finally {
typesDefs = existingTypeDefs; typesDefs = existingTypeDefs;
} }
......
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