Commit df9f5d27 by Madhan Neethiraj

ATLAS-2327: updated V1 to V2 conversion with addition of validation of attribute values

parent 08ac11c0
...@@ -246,10 +246,15 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter { ...@@ -246,10 +246,15 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
AtlasType attrType = attr.getAttributeType(); AtlasType attrType = attr.getAttributeType();
AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory()); AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
Object v1Value = attributes.get(attr.getName()); Object v1Value = attributes.get(attrName);
if (attrType.isValidValue(v1Value)) {
Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context); Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context);
ret.put(attr.getAttributeDef().getName(), v2Value); ret.put(attrName, v2Value);
} else {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, attrName + "=" + v1Value);
}
} }
} }
......
...@@ -138,13 +138,13 @@ public class EntityResource { ...@@ -138,13 +138,13 @@ public class EntityResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.submit()"); 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 //Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
String[] jsonStrings; String[] jsonStrings;
try { try {
ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entities); ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
jsonStrings = new String[jsonEntities.size()]; jsonStrings = new String[jsonEntities.size()];
...@@ -154,11 +154,11 @@ public class EntityResource { ...@@ -154,11 +154,11 @@ public class EntityResource {
} catch (IOException e) { } catch (IOException e) {
jsonStrings = new String[1]; jsonStrings = new String[1];
jsonStrings[0] = entities; jsonStrings[0] = entityJson;
} }
if (LOG.isDebugEnabled()) { 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); AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings);
......
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