Repository: incubator-atlas Updated Branches: refs/heads/master 6fd04d9a8 -> 44df46cf1
ATLAS-1614: updated v1 partial-update to perform attribute validation Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/44df46cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/44df46cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/44df46cf Branch: refs/heads/master Commit: 44df46cf14c216021d80c1a49c62bd0e48f6844a Parents: 6fd04d9 Author: Madhan Neethiraj <[email protected]> Authored: Wed Mar 1 17:45:38 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Wed Mar 1 18:17:28 2017 -0800 ---------------------------------------------------------------------- intg/src/main/java/org/apache/atlas/AtlasErrorCode.java | 1 + .../repository/converters/AtlasInstanceConverter.java | 12 ++++++++++++ .../apache/atlas/services/DefaultMetadataService.java | 10 ++++++---- .../java/org/apache/atlas/services/MetadataService.java | 4 ++++ 4 files changed, 23 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/44df46cf/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java index edcef4b..5ad362c 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -66,6 +66,7 @@ public enum AtlasErrorCode { INVALID_STRUCT_VALUE(400, "ATLAS40036E", "not a valid struct value {0}"), INSTANCE_LINEAGE_INVALID_PARAMS(400, "ATLAS40037E", "Invalid lineage query parameters passed {0}: {1}"), ATTRIBUTE_UPDATE_NOT_SUPPORTED(400, "ATLAS40038E", "{0}.{1} : attribute update not supported"), + INVALID_VALUE(400, "ATLAS40039E", "invalid value: {0}"), // All Not found enums go here TYPE_NAME_NOT_FOUND(404, "ATLAS4041E", "Given typename {0} was invalid"), http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/44df46cf/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java index 287ce15..a4f99a5 100644 --- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java +++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java @@ -49,6 +49,7 @@ import org.apache.atlas.typesystem.exception.EntityNotFoundException; import org.apache.atlas.typesystem.exception.TraitNotFoundException; import org.apache.atlas.typesystem.exception.TypeNotFoundException; import org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext; +import org.apache.atlas.typesystem.types.ValueConversionException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.slf4j.Logger; @@ -149,6 +150,13 @@ public class AtlasInstanceConverter { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName()); } + // validate + try { + metadataService.validateAndConvertToTypedInstance(referenceable, entityType.getTypeName()); + } catch (AtlasException excp) { + throw toAtlasBaseException(excp); + } + ConverterContext ctx = new ConverterContext(); AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, ctx); @@ -199,6 +207,10 @@ public class AtlasInstanceConverter { return new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e); } + if (e instanceof ValueConversionException) { + return new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, e, e.getMessage()); + } + return new AtlasBaseException(e); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/44df46cf/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java index 77db167..5a8add1 100755 --- a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java +++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java @@ -42,6 +42,7 @@ import org.apache.atlas.repository.audit.EntityAuditRepository; import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.typestore.ITypeStore; import org.apache.atlas.type.AtlasTypeUtil; +import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; @@ -476,7 +477,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang newEntity = ParamChecker.notNull(newEntity, "updatedEntity cannot be null"); ITypedReferenceableInstance existInstance = validateEntityExists(guid); - ITypedReferenceableInstance newInstance = convertToTypedInstance(newEntity, existInstance.getTypeName()); + ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(newEntity, existInstance.getTypeName()); ((ReferenceableInstance)newInstance).replaceWithNewId(new Id(guid, 0, newInstance.getTypeName())); CreateUpdateEntitiesResult result = repository.updatePartial(newInstance); @@ -484,10 +485,11 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang return result; } - private ITypedReferenceableInstance convertToTypedInstance(Referenceable updatedEntity, String typeName) + @Override + public ITypedReferenceableInstance validateAndConvertToTypedInstance(IReferenceableInstance updatedEntity, String typeName) throws AtlasException { ClassType type = typeSystem.getDataType(ClassType.class, typeName); - ITypedReferenceableInstance newInstance = type.createInstance(); + ITypedReferenceableInstance newInstance = type.createInstance(updatedEntity.getId()); for (String attributeName : updatedEntity.getValuesMap().keySet()) { AttributeInfo attributeInfo = type.fieldMapping.fields.get(attributeName); @@ -538,7 +540,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang ITypedReferenceableInstance oldInstance = getEntityDefinitionReference(typeName, uniqueAttributeName, attrValue); - final ITypedReferenceableInstance newInstance = convertToTypedInstance(updatedEntity, typeName); + final ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(updatedEntity, typeName); ((ReferenceableInstance)newInstance).replaceWithNewId(oldInstance.getId()); CreateUpdateEntitiesResult result = repository.updatePartial(newInstance); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/44df46cf/server-api/src/main/java/org/apache/atlas/services/MetadataService.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java index 45b35b3..0110373 100644 --- a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java +++ b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java @@ -23,6 +23,7 @@ import org.apache.atlas.AtlasException; import org.apache.atlas.CreateUpdateEntitiesResult; import org.apache.atlas.EntityAuditEvent; import org.apache.atlas.listener.EntityChangeListener; +import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.Referenceable; @@ -309,4 +310,7 @@ public interface MetadataService { * @throws AtlasException */ ITypedReferenceableInstance[] deserializeClassInstances(String entityInstanceDefinition) throws AtlasException; + + ITypedReferenceableInstance validateAndConvertToTypedInstance(IReferenceableInstance updatedEntity, String typeName) + throws AtlasException; }
