Repository: atlas Updated Branches: refs/heads/master 08ac11c09 -> df9f5d276
ATLAS-2327: updated V1 to V2 conversion with addition of validation of attribute values Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/df9f5d27 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/df9f5d27 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/df9f5d27 Branch: refs/heads/master Commit: df9f5d276286c0b510591e39fb8af2cbdc2ebfbb Parents: 08ac11c Author: Madhan Neethiraj <mad...@apache.org> Authored: Sun Jan 7 23:43:39 2018 -0800 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Sun Jan 7 23:43:39 2018 -0800 ---------------------------------------------------------------------- .../converters/AtlasStructFormatConverter.java | 11 ++++++++--- .../org/apache/atlas/web/resources/EntityResource.java | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/df9f5d27/repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java index 70b23c5..a5c9ded 100644 --- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java +++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java @@ -246,10 +246,15 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter { AtlasType attrType = attr.getAttributeType(); AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory()); - Object v1Value = attributes.get(attr.getName()); - Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context); + Object v1Value = attributes.get(attrName); - ret.put(attr.getAttributeDef().getName(), v2Value); + if (attrType.isValidValue(v1Value)) { + Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context); + + ret.put(attrName, v2Value); + } else { + throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, attrName + "=" + v1Value); + } } } http://git-wip-us.apache.org/repos/asf/atlas/blob/df9f5d27/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index e8126b5..8fd4d5a 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -138,13 +138,13 @@ public class EntityResource { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.submit()"); } - String entities = Servlets.getRequestPayload(request); + entityJson = Servlets.getRequestPayload(request); //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray String[] jsonStrings; try { - ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entities); + ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson); jsonStrings = new String[jsonEntities.size()]; @@ -154,11 +154,11 @@ public class EntityResource { } catch (IOException e) { jsonStrings = new String[1]; - jsonStrings[0] = entities; + jsonStrings[0] = entityJson; } if (LOG.isDebugEnabled()) { - LOG.debug("submitting entities: count={}; entities-json={}", jsonStrings.length, entities); + LOG.debug("submitting entities: count={}; entities-json={}", jsonStrings.length, entityJson); } AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings);