<properties>
<docker.location>${basedir}/target</docker.location>
<aaiCommonVersion>1.2.4</aaiCommonVersion>
+ <event.client.version>1.3.1</event.client.version>
</properties>
<dependencyManagement>
<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>
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;
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;
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>();
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);
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;
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
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*)");
private synchronized static void loadModel(String oxmVersion, DynamicJAXBContext jaxbContext) {
versionContextMap.put(oxmVersion, jaxbContext);
+ loadXmlLookupMap(oxmVersion, jaxbContext);
logger.info(SpikeMsgs.LOADED_OXM_FILE, oxmVersion);
}
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.
*