aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorShwetank Dave <shwetank.dave@amdocs.com>2018-11-07 16:04:43 -0500
committerShwetank Dave <shwetank.dave@amdocs.com>2018-11-07 16:19:38 -0500
commitb1ea3b6d19de319a283b6284595b0465c9e98030 (patch)
tree60ab835aaa668ce34f0f5f26c88e930b70fe903e /src/main
parent99159b883ec864955502b76844a79eb8df3bfe3f (diff)
Upgrading event-client to version 1.3.1
- Adding support for rabbit mq (from event-client version 1.3.1) - Fixing issue where the checking offset fails - Adding a fix for fully qualified domain name Change-Id: Ibab1fc48e00df15a8a2b17369d0731fece17061c Issue-ID: AAI-1798 Signed-off-by: Shwetank Dave <shwetank.dave@amdocs.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java19
-rw-r--r--src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java63
-rw-r--r--src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java2
3 files changed, 73 insertions, 11 deletions
diff --git a/src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java b/src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java
index 54d9936..205a17e 100644
--- a/src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java
+++ b/src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java
@@ -23,6 +23,7 @@ package org.onap.aai.spike.schema;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import javax.ws.rs.core.Response.Status;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
@@ -33,6 +34,7 @@ import org.onap.aai.spike.event.incoming.GizmoEdge;
import org.onap.aai.spike.event.incoming.GizmoGraphEvent;
import org.onap.aai.spike.event.incoming.GizmoVertex;
import org.onap.aai.spike.exception.SpikeException;
+import org.onap.aai.spike.logging.SpikeMsgs;
import com.google.common.base.CaseFormat;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -95,11 +97,14 @@ public class GraphEventTransformer {
try {
DynamicJAXBContext jaxbContext = OXMModelLoader.getContextForVersion(version);
- String modelObjectClass = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL,
- CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, rawVertex.getType()));
- final DynamicType modelObjectType = jaxbContext.getDynamicType(modelObjectClass);
+ final DynamicType modelObjectType = OXMModelLoader.getDynamicTypeForVersion(version, rawVertex.getType());
final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
+ if (modelObjectType == null) {
+ logger.error(SpikeMsgs.LOADED_OXM_FILE, "Object of collection type not found: " + rawVertex.getType());
+ throw new SpikeException("Object of collection type not found: " + rawVertex.getType());
+ }
+
Set<Map.Entry<String, JsonElement>> vertexEntriesSet =
rawVertex.getProperties().getAsJsonObject().entrySet();
Map<String, JsonElement> vertexEntriesMap = new HashMap<String, JsonElement>();
@@ -216,14 +221,10 @@ public class GraphEventTransformer {
JsonObject modelJsonElement = new JsonObject();
for (String property : relationshipModel.keySet()) {
-
- if (!edgeEntriesMap.containsKey(property)) {
- throw new SpikeException("Missing required field: " + property);
- }
-
+ if (edgeEntriesMap.containsKey(property)) {
validateFieldType(edgeEntriesMap.get(property), relationshipModel.get(property));
modelJsonElement.add(property, edgeEntriesMap.get(property));
-
+ }
}
rawEdge.setProperties(modelJsonElement);
diff --git a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
index 0d174db..5d35017 100644
--- a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
+++ b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java
@@ -22,11 +22,17 @@ package org.onap.aai.spike.schema;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.eclipse.persistence.dynamic.DynamicType;
+import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.nodes.NodeIngestor;
@@ -36,6 +42,7 @@ import org.onap.aai.setup.Version;
import org.onap.aai.spike.exception.SpikeException;
import org.onap.aai.spike.logging.SpikeMsgs;
import org.onap.aai.spike.util.SchemaIngestPropertiesReader;
+import com.google.common.base.CaseFormat;
/**
* This class contains all of the logic for importing OXM model schemas from the available OXM
@@ -45,7 +52,8 @@ public class OXMModelLoader {
private static Map<String, DynamicJAXBContext> versionContextMap =
new ConcurrentHashMap<String, DynamicJAXBContext>();
-
+ private static Map<String, HashMap<String, DynamicType>> xmlElementLookup = new ConcurrentHashMap<String, HashMap<String, DynamicType>>();
+
final static Pattern p = Pattern.compile("aai_oxm_(.*).xml");
final static Pattern versionPattern = Pattern.compile("V(\\d*)");
@@ -82,6 +90,7 @@ public class OXMModelLoader {
private synchronized static void loadModel(String oxmVersion, DynamicJAXBContext jaxbContext) {
versionContextMap.put(oxmVersion, jaxbContext);
+ loadXmlLookupMap(oxmVersion, jaxbContext);
logger.info(SpikeMsgs.LOADED_OXM_FILE, oxmVersion);
}
@@ -158,6 +167,58 @@ public class OXMModelLoader {
OXMModelLoader.versionContextMap = versionContextMap;
}
+ public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext) {
+
+ @SuppressWarnings("rawtypes")
+ List<Descriptor> descriptorsList = jaxbContext.getXMLContext().getDescriptors();
+ HashMap<String, DynamicType> types = new HashMap<String, DynamicType>();
+
+ for (@SuppressWarnings("rawtypes")
+ Descriptor desc : descriptorsList) {
+
+ DynamicType entity = jaxbContext.getDynamicType(desc.getAlias());
+ String entityName = desc.getDefaultRootElement();
+ types.put(entityName, entity);
+ }
+ xmlElementLookup.put(version, types);
+ }
+
+ public static DynamicType getDynamicTypeForVersion(String version, String type) throws SpikeException {
+
+ DynamicType dynamicType;
+ // If we haven't already loaded in the available OXM models, then do so now.
+ if (versionContextMap == null || versionContextMap.isEmpty()) {
+ loadModels();
+ } else if (!versionContextMap.containsKey(version)) {
+ logger.error(SpikeMsgs.OXM_LOAD_ERROR, "Error loading oxm model: " + version);
+ throw new SpikeException("Error loading oxm model: " + version);
+ }
+
+ // First try to match the Java-type based on hyphen to camel case
+ // translation
+ String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, type);
+ dynamicType = versionContextMap.get(version).getDynamicType(javaTypeName);
+
+ if (xmlElementLookup.containsKey(version)) {
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by exact match
+ dynamicType = xmlElementLookup.get(version).get(type);
+ }
+
+ if (dynamicType == null) {
+ // Try to lookup by xml root element by lowercase
+ dynamicType = xmlElementLookup.get(version).get(type.toLowerCase());
+ }
+
+ if (dynamicType == null) {
+ // Direct lookup as java-type name
+ dynamicType = versionContextMap.get(version).getDynamicType(type);
+ }
+ }
+
+ return dynamicType;
+ }
+
/**
* Retrieves the list of all Loaded OXM versions.
*
diff --git a/src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java b/src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java
index c4e1746..88fa716 100644
--- a/src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java
+++ b/src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java
@@ -186,7 +186,7 @@ public class SpikeEventProcessor extends TimerTask {
// There is no point in continually committing the same offset value, so make sure
// that something has actually changed before we do anything...
- if ((lastCommittedOffset == null) || (lastCommittedOffset != nextOffset)) {
+ if ((lastCommittedOffset == null) || (!lastCommittedOffset.equals(nextOffset))) {
if (logger.isDebugEnabled()) {
logger.debug(