aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/aai/datarouter/Application.java14
-rw-r--r--src/main/java/org/onap/aai/datarouter/SpringXMLConfig.java11
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java37
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java25
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java27
-rw-r--r--src/main/java/org/onap/aai/datarouter/service/EchoService.java16
-rw-r--r--src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java21
7 files changed, 83 insertions, 68 deletions
diff --git a/src/main/java/org/onap/aai/datarouter/Application.java b/src/main/java/org/onap/aai/datarouter/Application.java
new file mode 100644
index 0000000..e81ba3e
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/Application.java
@@ -0,0 +1,14 @@
+package org.onap.aai.datarouter;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/datarouter/SpringXMLConfig.java b/src/main/java/org/onap/aai/datarouter/SpringXMLConfig.java
new file mode 100644
index 0000000..1d9234c
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/SpringXMLConfig.java
@@ -0,0 +1,11 @@
+package org.onap.aai.datarouter;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+
+@Configuration
+@ImportResource({"file:${SERVICE_BEANS}/*.xml"})
+public class SpringXMLConfig {
+
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
index 1d447c9..793588f 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
@@ -74,20 +74,20 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
public class EntityEventPolicy implements Processor {
public static final String additionalInfo = "Response of AAIEntityEventPolicy";
- private static final String entitySearchSchema = "entitysearch_schema.json";
- private static final String topographicalSearchSchema = "topographysearch_schema.json";
+ private static final String ENTITY_SEARCH_SCHEMA = "entitysearch_schema.json";
+ private static final String TOPOGRAPHICAL_SEARCH_SCHEMA = "topographysearch_schema.json";
private Collection<ExternalOxmModelProcessor> externalOxmModelProcessors;
- private final String EVENT_HEADER = "event-header";
- private final String ENTITY_HEADER = "entity";
- private final String ACTION_CREATE = "create";
- private final static String ACTION_DELETE = "delete";
- private final String ACTION_UPDATE = "update";
- private final String PROCESS_AAI_EVENT = "Process AAI Event";
- private final String TOPO_LAT = "latitude";
- private final String TOPO_LONG = "longitude";
+ private static final String EVENT_HEADER = "event-header";
+ private static final String ENTITY_HEADER = "entity";
+ private static final String ACTION_CREATE = "create";
+ private static final String ACTION_DELETE = "delete";
+ private static final String ACTION_UPDATE = "update";
+ private static final String PROCESS_AAI_EVENT = "Process AAI Event";
+ private static final String TOPO_LAT = "latitude";
+ private static final String TOPO_LONG = "longitude";
- private final List<String> SUPPORTED_ACTIONS =
+ private static final List<String> SUPPORTED_ACTIONS =
Arrays.asList(ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE);
Map<String, DynamicJAXBContext> oxmVersionContextMap = new HashMap<>();
@@ -172,8 +172,8 @@ public class EntityEventPolicy implements Processor {
public void startup() {
// Create the indexes in the search service if they do not already exist.
- searchAgent.createSearchIndex(entitySearchIndex, entitySearchSchema);
- searchAgent.createSearchIndex(topographicalSearchIndex, topographicalSearchSchema);
+ searchAgent.createSearchIndex(entitySearchIndex, ENTITY_SEARCH_SCHEMA);
+ searchAgent.createSearchIndex(topographicalSearchIndex, TOPOGRAPHICAL_SEARCH_SCHEMA);
logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
}
@@ -506,7 +506,7 @@ public class EntityEventPolicy implements Processor {
updateCerInEntity(entityToSync);
} catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
+ logger.debug(e.getMessage());
}
}
} else {
@@ -814,7 +814,7 @@ public class EntityEventPolicy implements Processor {
uebJsonObj = new JSONObject(payload);
} catch (JSONException e) {
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE,
- "Payload has invalid JSON Format", payload.toString());
+ "Payload has invalid JSON Format", payload);
logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE,
"Payload has invalid JSON Format");
return null;
@@ -823,8 +823,7 @@ public class EntityEventPolicy implements Processor {
if (uebJsonObj.has(ENTITY_HEADER)) {
return uebJsonObj.getJSONObject(ENTITY_HEADER);
} else {
- logger.debug(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing",
- payload.toString());
+ logger.debug(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing", payload);
logger.error(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, ENTITY_HEADER + " missing");
return null;
}
@@ -846,8 +845,6 @@ public class EntityEventPolicy implements Processor {
primaryKeyValues.add(pkeyValue);
primaryKeyNames.add(keyName);
} else {
- // logger.warn("getPopulatedDocument(), pKeyValue is null for entityType = " +
- // resultDescriptor.getEntityName());
logger.error(EntityEventPolicyMsgs.PRIMARY_KEY_NULL_FOR_ENTITY_TYPE,
resultDescriptor.getEntityName());
}
@@ -966,8 +963,6 @@ public class EntityEventPolicy implements Processor {
String entityId = eventEntity.getId();
- // System.out.println("aaiEventEntity as json = " + aaiEventEntity.getAsJson());
-
if ((action.equalsIgnoreCase(ACTION_CREATE) && entityId != null)
|| action.equalsIgnoreCase(ACTION_UPDATE)) {
diff --git a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
index 455e6b9..36bb142 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
@@ -64,20 +64,20 @@ import com.fasterxml.jackson.databind.ObjectWriter;
public class SpikeEntityEventPolicy implements Processor {
public static final String additionalInfo = "Response of SpikeEntityEventPolicy";
- private static final String entitySearchSchema = "entitysearch_schema.json";
+ private static final String ENTITY_SEARCH_SCHEMA = "entitysearch_schema.json";
private Collection<ExternalOxmModelProcessor> externalOxmModelProcessors;
- private final String ACTION_CREATE = "create";
- private final String EVENT_VERTEX = "vertex";
- private final static String ACTION_DELETE = "delete";
- private final String ACTION_UPDATE = "update";
- private final String PROCESS_SPIKE_EVENT = "Process Spike Event";
- private final String OPERATION_KEY = "operation";
+ private static final String ACTION_CREATE = "create";
+ private static final String EVENT_VERTEX = "vertex";
+ private static final String ACTION_DELETE = "delete";
+ private static final String ACTION_UPDATE = "update";
+ private static final String PROCESS_SPIKE_EVENT = "Process Spike Event";
+ private static final String OPERATION_KEY = "operation";
- private final List<String> SUPPORTED_ACTIONS =
+ private static final List<String> SUPPORTED_ACTIONS =
Arrays.asList(ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE);
Map<String, DynamicJAXBContext> oxmVersionContextMap = new HashMap<>();
@@ -86,7 +86,6 @@ public class SpikeEntityEventPolicy implements Processor {
/** Agent for communicating with the Search Service. */
private SearchServiceAgent searchAgent = null;
private String entitySearchIndex;
- private String srcDomain;
private Logger logger;
private Logger metricsLogger;
@@ -101,7 +100,7 @@ public class SpikeEntityEventPolicy implements Processor {
metricsLogger = loggerFactoryInstance.getMetricsLogger(SpikeEntityEventPolicy.class.getName());
- srcDomain = config.getSourceDomain();
+ //srcDomain = config.getSourceDomain();
// Populate the index names.
entitySearchIndex = config.getSearchEntitySearchIndex();
@@ -145,7 +144,7 @@ public class SpikeEntityEventPolicy implements Processor {
public void startup() {
// Create the indexes in the search service if they do not already exist.
- searchAgent.createSearchIndex(entitySearchIndex, entitySearchSchema);
+ searchAgent.createSearchIndex(entitySearchIndex, ENTITY_SEARCH_SCHEMA);
logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
}
@@ -441,7 +440,7 @@ public class SpikeEntityEventPolicy implements Processor {
return "";
}
- private String lookupValueUsingKey(String payload, String key) throws JSONException {
+ private String lookupValueUsingKey(String payload, String key) {
JsonNode jsonNode = convertToJsonNode(payload);
return RouterServiceUtil.recursivelyLookupJsonPayload(jsonNode, key);
}
@@ -537,8 +536,6 @@ public class SpikeEntityEventPolicy implements Processor {
primaryKeyValues.add(pkeyValue);
primaryKeyNames.add(keyName);
} else {
- // logger.warn("getPopulatedDocument(), pKeyValue is null for entityType = " +
- // resultDescriptor.getEntityName());
logger.error(EntityEventPolicyMsgs.PRIMARY_KEY_NULL_FOR_ENTITY_TYPE,
resultDescriptor.getEntityName());
}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
index f74e742..d319c48 100644
--- a/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
@@ -32,32 +32,33 @@ import com.google.gson.JsonParser;
public class ChameleonResponseBuiler {
- public static void buildEntity(Exchange exchange, String ID){
+ private static final String SOURCE = "source";
+ private static final String TARGET = "target";
+ private static final String TYPE = "type";
+
+ public static void buildEntity(Exchange exchange, String id){
String response = exchange.getIn().getBody().toString();
JsonParser parser = new JsonParser();
JsonObject root = parser.parse(response).getAsJsonObject();
JsonObject champResponse = new JsonObject();
- if (!root.has("type")) {
+ if (!root.has(TYPE)) {
exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
return ;
}
- champResponse.addProperty("key", ID);
- champResponse.addProperty("type", root.get("type").getAsString());
- if (root.has("source")) {
- champResponse.add("source", root.get("source"));
+ champResponse.addProperty("key", id);
+ champResponse.addProperty(TYPE, root.get(TYPE).getAsString());
+ if (root.has(SOURCE)) {
+ champResponse.add(SOURCE, root.get(SOURCE));
}
- if (root.has("target")) {
- champResponse.add("target", root.get("target"));
+ if (root.has(TARGET)) {
+ champResponse.add(TARGET, root.get(TARGET));
}
JsonObject props = new JsonObject();
List<Map.Entry<String, JsonElement>> entries = new ArrayList<Map.Entry<String, JsonElement>>(
root.getAsJsonObject().entrySet());
for (Map.Entry<String, JsonElement> e : entries) {
- if (!e.getKey().equals("type") && !e.getKey().equals("source") && !e.getKey().equals("target")) {
- if (e.getKey().equals("source")) {
-
- }
+ if (!TYPE.equals(e.getKey()) && !SOURCE.equals(e.getKey()) && !TARGET.equals(e.getKey())) {
props.addProperty(e.getKey(), e.getValue().getAsString());
}
@@ -70,7 +71,7 @@ public class ChameleonResponseBuiler {
}
- public static void buildObjectRelationship(Exchange exchange, String ID){
+ public static void buildObjectRelationship(Exchange exchange, String id){
//TODO: implement when chameleon supports this query
}
public static void buildCollection(Exchange exchange){
diff --git a/src/main/java/org/onap/aai/datarouter/service/EchoService.java b/src/main/java/org/onap/aai/datarouter/service/EchoService.java
index 4ff658b..8192935 100644
--- a/src/main/java/org/onap/aai/datarouter/service/EchoService.java
+++ b/src/main/java/org/onap/aai/datarouter/service/EchoService.java
@@ -44,6 +44,8 @@ public class EchoService {
private static Logger logger = LoggerFactory.getInstance().getLogger(EchoService.class.getName());
private static Logger auditLogger =
LoggerFactory.getInstance().getAuditLogger(EchoService.class.getName());
+ private static final String XFROMAPPID = "X-FromAppId";
+ private static final String XTRANSACTIONID = "X-TransactionId";
@GET
@Path("echo/{input}")
@@ -55,15 +57,15 @@ public class EchoService {
String fromAppId = "";
String transId;
- if (headers.getRequestHeaders().getFirst("X-FromAppId") != null) {
- fromAppId = headers.getRequestHeaders().getFirst("X-FromAppId");
+ if (headers.getRequestHeaders().getFirst(XFROMAPPID) != null) {
+ fromAppId = headers.getRequestHeaders().getFirst(XFROMAPPID);
}
- if ((headers.getRequestHeaders().getFirst("X-TransactionId") == null)
- || headers.getRequestHeaders().getFirst("X-TransactionId").isEmpty()) {
+ if ((headers.getRequestHeaders().getFirst(XTRANSACTIONID) == null)
+ || headers.getRequestHeaders().getFirst(XTRANSACTIONID).isEmpty()) {
transId = java.util.UUID.randomUUID().toString();
} else {
- transId = headers.getRequestHeaders().getFirst("X-TransactionId");
+ transId = headers.getRequestHeaders().getFirst(XTRANSACTIONID);
}
MdcContext.initialize(transId, DataRouterConstants.DATA_ROUTER_SERVICE_NAME, "", fromAppId,
@@ -83,9 +85,7 @@ public class EchoService {
auditLogger.info(DataRouterMsgs.PROCESS_REST_REQUEST,
new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, status)
.setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, respStatusString),
- (req != null) ? req.getMethod() : "Unknown",
- (req != null) ? req.getRequestURL().toString() : "Unknown",
- (req != null) ? req.getRemoteHost() : "Unknown", Integer.toString(status));
+ req.getMethod(), req.getRequestURL().toString(), req.getRemoteHost(), Integer.toString(status));
MDC.clear();
return "Hello, " + input + ".";
diff --git a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java b/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java
index c9d114e..345bc48 100644
--- a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java
+++ b/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java
@@ -24,10 +24,11 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Collection;
+import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -40,23 +41,20 @@ import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.datarouter.logging.DataRouterMsgs;
-import org.onap.aai.datarouter.util.ExternalOxmModelProcessor;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
public class OxmModelLoader {
- private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>();
+ private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>();
private static List<ExternalOxmModelProcessor> oxmModelProcessorRegistry = new ArrayList<>();
- final static Pattern p = Pattern.compile("aai_oxm_(.*).xml");
-
-
+ static final Pattern p = Pattern.compile("aai_oxm_(.*).xml");
private static org.onap.aai.cl.api.Logger logger = LoggerFactory.getInstance()
.getLogger(OxmModelLoader.class.getName());
- public synchronized static void loadModels() throws FileNotFoundException {
+ public static synchronized void loadModels() throws FileNotFoundException {
ClassLoader cl = OxmModelLoader.class.getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
@@ -89,9 +87,8 @@ public class OxmModelLoader {
}
-
- private synchronized static void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException, FileNotFoundException {
+ private static synchronized void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException {
Map<String, Object> properties = new HashMap<>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory
@@ -105,11 +102,11 @@ public class OxmModelLoader {
logger.info(DataRouterMsgs.LOADED_OXM_FILE, resourceName);
}
- public static DynamicJAXBContext getContextForVersion(String version) throws Exception {
+ public static DynamicJAXBContext getContextForVersion(String version) throws NoSuchElementException, FileNotFoundException {
if (versionContextMap == null || versionContextMap.isEmpty()) {
loadModels();
} else if (!versionContextMap.containsKey(version)) {
- throw new Exception(Status.NOT_FOUND.toString());
+ throw new NoSuchElementException(Status.NOT_FOUND.toString());
}
@@ -124,7 +121,7 @@ public class OxmModelLoader {
OxmModelLoader.versionContextMap = versionContextMap;
}
- public synchronized static void registerExternalOxmModelProcessors(Collection<ExternalOxmModelProcessor> processors) {
+ public static synchronized void registerExternalOxmModelProcessors(Collection<ExternalOxmModelProcessor> processors) {
if(processors != null) {
for(ExternalOxmModelProcessor processor : processors) {
if(!oxmModelProcessorRegistry.contains(processor)) {