X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fschema%2FOxmModelValidator.java;h=ae3e18b805707526ecc412a2cd2b5525a69c20c4;hb=1bb61ff3e013bcd41beffc5d9f01964f422f8a9e;hp=d23804cb83fcb39014072a1e19346cbf1f990a3d;hpb=94cbd3286b5fdd2f3f8fa3325835e713d71aac73;p=aai%2Fgizmo.git diff --git a/src/main/java/org/onap/schema/OxmModelValidator.java b/src/main/java/org/onap/schema/OxmModelValidator.java index d23804c..ae3e18b 100644 --- a/src/main/java/org/onap/schema/OxmModelValidator.java +++ b/src/main/java/org/onap/schema/OxmModelValidator.java @@ -44,8 +44,12 @@ import javax.ws.rs.core.Response.Status; public class OxmModelValidator { public enum Metadata { - NODE_TYPE("aai-node-type"), URI("aai-uri"), CREATED_TS("aai-created-ts"), SOT("source-of-truth"), LAST_MOD_SOT( - "last-mod-source-of-truth"); + NODE_TYPE("aai-node-type"), + URI("aai-uri"), + CREATED_TS("aai-created-ts"), + UPDATED_TS("aai-last-mod-ts"), + SOT("source-of-truth"), + LAST_MOD_SOT("last-mod-source-of-truth"); private final String propName; @@ -83,12 +87,18 @@ public class OxmModelValidator { } final DynamicType modelObjectType = jaxbContext.getDynamicType( CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type))); + final DynamicType reservedObjectType = jaxbContext.getDynamicType("ReservedPropNames"); for (String key : filter.keySet()) { String keyJavaName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key); - if (modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) != null) { + DatabaseMapping mapping = modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName); + + // Try both the model for the specified type and the reserved properties for our key + if (mapping == null) { + mapping = reservedObjectType.getDescriptor().getMappingForAttributeName(keyJavaName); + } + if (mapping != null) { try { - DatabaseMapping mapping = modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName); Object value = CrudServiceUtil.validateFieldType(filter.get(key), mapping.getField().getType()); result.put(key, value); } catch (Exception ex) { @@ -143,7 +153,7 @@ public class OxmModelValidator { public static Vertex validateIncomingUpsertPayload(String id, String version, String type, JsonElement properties) throws CrudException { - + try { type = resolveCollectionType(version, type); DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion(version); @@ -226,7 +236,6 @@ public class OxmModelValidator { public static Vertex validateIncomingPatchPayload(String id, String version, String type, JsonElement properties, Vertex existingVertex) throws CrudException { - try { type = resolveCollectionType(version, type); DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion(version); @@ -276,14 +285,12 @@ public class OxmModelValidator { Object value = CrudServiceUtil.validateFieldType(entry.getValue().getAsString(), field.getType()); existingVertex.getProperties().put(entry.getKey(), value); } - } return existingVertex; } catch (Exception e) { throw new CrudException(e.getMessage(), Status.BAD_REQUEST); } - } private static DatabaseField getDatabaseField(String fieldName, DynamicType modelObjectType) { @@ -301,8 +308,7 @@ public class OxmModelValidator { return null; } - public static Vertex validateOutgoingPayload(String version, Vertex vertex) { - + public static Vertex validateOutgoingPayload(String version, Vertex vertex) { Vertex.Builder modelVertexBuilder = new Vertex.Builder(vertex.getType()).id(vertex.getId().get()); try { @@ -321,6 +327,7 @@ public class OxmModelValidator { } } } + return modelVertexBuilder.build(); } catch (Exception ex) { return vertex;