diff options
author | 2017-11-16 14:56:59 -0500 | |
---|---|---|
committer | 2017-11-16 15:01:37 -0500 | |
commit | be2eab9395a787ca4b13447f9d2c382d12f5dcd5 (patch) | |
tree | 87c81f3a919ca61515212455fc90bc96402de9a5 /src/main/java/org/openecomp/schema | |
parent | eff2052b4a77690b4e2e67c8a5b438457657c99f (diff) |
Add bulk API to gizmo
Add bulk API to gizmo
IssueID: AAI-481
Change-Id: Iff9df1a8fdc73c87d726da7294c2eb9f471080f1
Signed-off-by: Bansal, Nitin (nb121v) <nitin.bansal@amdocs.com>
Diffstat (limited to 'src/main/java/org/openecomp/schema')
-rw-r--r-- | src/main/java/org/openecomp/schema/OxmModelValidator.java | 49 | ||||
-rw-r--r-- | src/main/java/org/openecomp/schema/RelationshipSchemaLoader.java | 39 |
2 files changed, 58 insertions, 30 deletions
diff --git a/src/main/java/org/openecomp/schema/OxmModelValidator.java b/src/main/java/org/openecomp/schema/OxmModelValidator.java index 0ae3e13..e51b23f 100644 --- a/src/main/java/org/openecomp/schema/OxmModelValidator.java +++ b/src/main/java/org/openecomp/schema/OxmModelValidator.java @@ -163,6 +163,7 @@ public class OxmModelValidator { CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type)); final DynamicType modelObjectType = jaxbContext.getDynamicType(modelObjectClass); + final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames"); Set<Map.Entry<String, JsonElement>> payloadEntriesSet = properties.getAsJsonObject() .entrySet(); @@ -173,7 +174,9 @@ public class OxmModelValidator { // check for valid field if (modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) == null) { - throw new CrudException("Invalid field: " + entry.getKey(), Status.BAD_REQUEST); + if(reservedType.getDescriptor().getMappingForAttributeName(keyJavaName) == null){ + throw new CrudException("Invalid field: " + entry.getKey(), Status.BAD_REQUEST); + } } } @@ -219,6 +222,20 @@ public class OxmModelValidator { } } } + + // Handle reserved properties + for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) { + if (mapping.isAbstractDirectMapping()) { + DatabaseField field = mapping.getField(); + String keyName = field.getName().substring(0, field.getName().indexOf("/")); + + if (entriesMap.containsKey(keyName)) { + Object value = CrudServiceUtil.validateFieldType(entriesMap.get(keyName) + .getAsString(), field.getType()); + modelVertexBuilder.property(keyName, value); + } + } + } return modelVertexBuilder.build(); } catch (Exception e) { @@ -237,6 +254,7 @@ public class OxmModelValidator { CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type)); final DynamicType modelObjectType = jaxbContext.getDynamicType(modelObjectClass); + final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames"); Set<Map.Entry<String, JsonElement>> payloadEntriesSet = properties.getAsJsonObject() .entrySet(); @@ -247,19 +265,26 @@ public class OxmModelValidator { String keyJavaName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, entry.getKey()); - // check for valid field - if (modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) == null) { + DatabaseField field = null; + String defaultValue = null; + + if (modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) != null) { + field = modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName).getField(); + defaultValue = modelObjectType.getDescriptor() + .getMappingForAttributeName(keyJavaName) + .getProperties().get("defaultValue") == null ? "" + : modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) + .getProperties().get("defaultValue").toString(); + } + else if (reservedType.getDescriptor().getMappingForAttributeName(keyJavaName) != null) { + field = reservedType.getDescriptor().getMappingForAttributeName(keyJavaName).getField(); + defaultValue = ""; + } + + if (field == null) { throw new CrudException("Invalid field: " + entry.getKey(), Status.BAD_REQUEST); } - DatabaseField field = modelObjectType.getDescriptor() - .getMappingForAttributeName(keyJavaName).getField(); - String defaultValue = modelObjectType.getDescriptor() - .getMappingForAttributeName(keyJavaName) - .getProperties().get("defaultValue") == null ? "" - : modelObjectType.getDescriptor().getMappingForAttributeName(keyJavaName) - .getProperties().get("defaultValue").toString(); - // check if mandatory field is not set to null if (((XMLField) field).isRequired() && entry.getValue() instanceof JsonNull && !defaultValue.isEmpty()) { @@ -288,7 +313,7 @@ public class OxmModelValidator { } } - + private static DatabaseField getDatabaseField(String fieldName, DynamicType modelObjectType) { for (DatabaseField field : modelObjectType.getDescriptor().getAllFields()) { int ix = field.getName().indexOf("/"); diff --git a/src/main/java/org/openecomp/schema/RelationshipSchemaLoader.java b/src/main/java/org/openecomp/schema/RelationshipSchemaLoader.java index d4ae2b9..89a9e58 100644 --- a/src/main/java/org/openecomp/schema/RelationshipSchemaLoader.java +++ b/src/main/java/org/openecomp/schema/RelationshipSchemaLoader.java @@ -23,34 +23,38 @@ */ package org.openecomp.schema; -import org.apache.commons.io.IOUtils; -import org.openecomp.aai.dbmodel.DbEdgeRules; -import org.openecomp.cl.eelf.LoggerFactory; -import org.openecomp.crud.exception.CrudException; -import org.openecomp.crud.logging.CrudServiceMsgs; -import org.openecomp.crud.util.CrudServiceConstants; -import org.openecomp.crud.util.FileWatcher; -import org.springframework.core.io.UrlResource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; - -import java.io.*; -import java.util.Arrays; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; -import java.util.concurrent.ConcurrentHashMap; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.SortedSet; -import java.util.stream.Collectors; import java.util.Timer; import java.util.TimerTask; import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + import javax.ws.rs.core.Response.Status; +import org.apache.commons.io.IOUtils; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.crud.exception.CrudException; +import org.openecomp.crud.logging.CrudServiceMsgs; +import org.openecomp.crud.util.CrudServiceConstants; +import org.openecomp.crud.util.FileWatcher; +import org.springframework.core.io.UrlResource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; + public class RelationshipSchemaLoader { private static Map<String, RelationshipSchema> versionContextMap = new ConcurrentHashMap<>(); @@ -153,7 +157,6 @@ public class RelationshipSchemaLoader { String errorMsg = "Expecting a rules and a edge_properties files for " + version + ". Found: " + filenames; logger.warn(CrudServiceMsgs.INVALID_OXM_FILE, errorMsg); }}); - logger.info(CrudServiceMsgs.LOADED_OXM_FILE, "Relationship Schema and Properties files: " + rulesFiles.stream().map(f -> filename(f)).collect(Collectors.toList())); } catch (IOException e) { logger.error(CrudServiceMsgs.INVALID_OXM_DIR, rulesDir); |