X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fcrud%2Futil%2FCrudServiceUtil.java;h=ed5fe535323f2f8ed66400478dca2821f67d8642;hb=d10a218c76633374f083f7a2802c198e93a6abae;hp=4d108f22e89a302570d8562e7861d93c906ad5c0;hpb=18703cdc19842806969d30f19f8171469c79a0fe;p=aai%2Fgizmo.git diff --git a/src/main/java/org/onap/crud/util/CrudServiceUtil.java b/src/main/java/org/onap/crud/util/CrudServiceUtil.java index 4d108f2..ed5fe53 100644 --- a/src/main/java/org/onap/crud/util/CrudServiceUtil.java +++ b/src/main/java/org/onap/crud/util/CrudServiceUtil.java @@ -20,23 +20,22 @@ */ package org.onap.crud.util; -import org.onap.aai.db.props.AAIProperties; -import org.onap.crud.exception.CrudException; -import org.onap.schema.OxmModelLoader; -import org.onap.schema.RelationshipSchemaLoader; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; - import java.util.AbstractMap; import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; - +import java.util.Set; +import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response.Status; +import org.onap.aai.db.props.AAIProperties; +import org.onap.crud.exception.CrudException; +import org.onap.schema.EdgeRulesLoader; +import org.onap.schema.OxmModelLoader; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; public class CrudServiceUtil { @@ -54,13 +53,13 @@ public class CrudServiceUtil { } else if (clazz.isAssignableFrom(Double.class)) { return Double.parseDouble(value); } else if (clazz.isAssignableFrom(Boolean.class)) { - + // If the value is an IN/OUT direction, this gets seen as a boolean, so // check for that first. if (value.equals("OUT") || value.equals("IN")) { return value; } - + if (!value.equals("true") && !value.equals("false")) { throw new CrudException("Invalid propertry value: " + value, Status.BAD_REQUEST); } @@ -77,12 +76,12 @@ public class CrudServiceUtil { // load the schemas try { OxmModelLoader.loadModels(); + EdgeRulesLoader.loadModels (); } catch (Exception e) { throw new CrudException(e); } - RelationshipSchemaLoader.loadModels(); } - + /** * This method will merge header property from app id in request payload if not already populated * @param propertiesFromRequest @@ -104,12 +103,12 @@ public class CrudServiceUtil { if(!propertyKeys.contains(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH)) { properties.add(new AbstractMap.SimpleEntry(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, - (JsonElement)(new JsonPrimitive(sourceOfTruth)))); + (new JsonPrimitive(sourceOfTruth)))); } if(isAdd && !propertyKeys.contains(AAIProperties.SOURCE_OF_TRUTH)) { properties.add(new AbstractMap.SimpleEntry(AAIProperties.SOURCE_OF_TRUTH, - (JsonElement)(new JsonPrimitive(sourceOfTruth)))); + (new JsonPrimitive(sourceOfTruth)))); } Object[] propArray = properties.toArray(); @@ -117,7 +116,7 @@ public class CrudServiceUtil { sb.append("{"); boolean first=true; for(int i=0; i entry = (Entry) propArray[i]; if(!first) { sb.append(","); @@ -126,7 +125,17 @@ public class CrudServiceUtil { first=false; } sb.append("}"); - + return gson.fromJson(sb.toString(), JsonElement.class); } + + public static EntityTag getETagFromHeader(MultivaluedMap headers) { + EntityTag entityTag = null; + if (headers != null && headers.containsKey(CrudServiceConstants.CRD_HEADER_ETAG)) { + String value = headers.getFirst(CrudServiceConstants.CRD_HEADER_ETAG); + entityTag = new EntityTag(value.replace("\"", "")); + } + return entityTag; + } + }