diff options
-rw-r--r-- | .gitreview | 4 | ||||
-rw-r--r-- | pom.xml | 13 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/spike/schema/GraphEventTransformer.java | 19 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java | 63 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/spike/service/SpikeEventProcessor.java | 2 |
5 files changed, 87 insertions, 14 deletions
diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..0878209 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=gerrit.onap.org +port=29418 +project=aai/spike @@ -37,6 +37,7 @@ <properties> <docker.location>${basedir}/target</docker.location> <aaiCommonVersion>1.2.4</aaiCommonVersion> + <event.client.version>1.3.1</event.client.version> </properties> <dependencyManagement> @@ -164,19 +165,25 @@ <dependency> <groupId>org.onap.aai.event-client</groupId> <artifactId>event-client-api</artifactId> - <version>1.3.0</version> + <version>${event.client.version}</version> </dependency> <dependency> <groupId>org.onap.aai.event-client</groupId> <artifactId>event-client-dmaap</artifactId> - <version>1.3.0</version> + <version>${event.client.version}</version> </dependency> <dependency> <groupId>org.onap.aai.event-client</groupId> <artifactId>event-client-kafka</artifactId> - <version>1.3.0</version> + <version>${event.client.version}</version> + </dependency> + + <dependency> + <groupId>org.onap.aai.event-client</groupId> + <artifactId>event-client-rabbitmq</artifactId> + <version>${event.client.version}</version> </dependency> <dependency> 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( |