summaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java33
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java75
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java6
3 files changed, 54 insertions, 60 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
index 28d66dd0..7ecdd6d5 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/db/HttpEntry.java
@@ -155,49 +155,22 @@ public class HttpEntry {
}
public HttpEntry setHttpEntryProperties(SchemaVersion version, String serverBase) {
- this.version = version;
- this.loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- this.dbEngine = new JanusGraphDBEngine(queryStyle, loader);
-
- getDbEngine().startTransaction();
- this.notification = new UEBNotification(loader, loaderFactory, schemaVersions);
- if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
- this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
- } else {
- this.notificationDepth = AAIProperties.MINIMUM_DEPTH;
- }
-
+ setHttpEntryProperties(version);
this.serverBase = serverBase;
return this;
}
public HttpEntry setHttpEntryProperties(SchemaVersion version, UEBNotification notification) {
- this.version = version;
- this.loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- this.dbEngine = new JanusGraphDBEngine(queryStyle, loader);
-
+ setHttpEntryProperties(version);
this.notification = notification;
-
- if ("true".equals(AAIConfig.get("aai.notification.depth.all.enabled", "true"))) {
- this.notificationDepth = AAIProperties.MAXIMUM_DEPTH;
- } else {
- this.notificationDepth = AAIProperties.MINIMUM_DEPTH;
- }
- // start transaction on creation
- getDbEngine().startTransaction();
return this;
}
public HttpEntry setHttpEntryProperties(SchemaVersion version, UEBNotification notification,
int notificationDepth) {
- this.version = version;
- this.loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- this.dbEngine = new JanusGraphDBEngine(queryStyle, loader);
-
+ setHttpEntryProperties(version);
this.notification = notification;
this.notificationDepth = notificationDepth;
- // start transaction on creation
- getDbEngine().startTransaction();
return this;
}
diff --git a/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java b/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
index be30c468..0c8fde62 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/ueb/UEBNotification.java
@@ -98,42 +98,15 @@ public class UEBNotification {
Introspector obj, HashMap<String, Introspector> relatedObjects, String basePath)
throws AAIException, UnsupportedEncodingException {
- String action = "UPDATE";
-
- if (status.equals(Status.CREATED)) {
- action = "CREATE";
- } else if (status.equals(Status.OK)) {
- action = "UPDATE";
- } else if (status.equals(Status.NO_CONTENT)) {
- action = "DELETE";
- }
+ String action = getAction(status);
try {
Introspector eventHeader = currentVersionLoader.introspectorFromName("notification-event-header");
URIToObject parser = new URIToObject(currentVersionLoader, uri, relatedObjects);
- if ((basePath != null) && (!basePath.isEmpty())) {
- if (!(basePath.startsWith("/"))) {
- basePath = "/" + basePath;
- }
- if (!(basePath.endsWith("/"))) {
- basePath = basePath + "/";
- }
- } else {
- // default
- basePath = "/aai/";
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Please check the schema.uri.base.path as it didn't seem to be set");
- }
- }
+ basePath = formatBasePath(basePath);
- String uriStr = getUri(uri.toString(), basePath);
- String entityLink;
- if (uriStr.startsWith("/")) {
- entityLink = basePath + notificationVersion + uriStr;
- } else {
- entityLink = basePath + notificationVersion + "/" + uriStr;
- }
+ String entityLink = formatEntityLink(uri, basePath);
eventHeader.setValue("entity-link", entityLink);
eventHeader.setValue("action", action);
@@ -191,6 +164,48 @@ public class UEBNotification {
}
}
+ private String formatEntityLink(URI uri, String basePath) {
+ String uriStr = getUri(uri.toString(), basePath);
+ String entityLink;
+ if (uriStr.startsWith("/")) {
+ entityLink = basePath + notificationVersion + uriStr;
+ } else {
+ entityLink = basePath + notificationVersion + "/" + uriStr;
+ }
+ return entityLink;
+ }
+
+ private String formatBasePath(String basePath) {
+ if ((basePath != null) && (!basePath.isEmpty())) {
+ if (!(basePath.startsWith("/"))) {
+ basePath = "/" + basePath;
+ }
+ if (!(basePath.endsWith("/"))) {
+ basePath = basePath + "/";
+ }
+ } else {
+ // default
+ basePath = "/aai/";
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Please check the schema.uri.base.path as it didn't seem to be set");
+ }
+ }
+ return basePath;
+ }
+
+ private String getAction(Status status) {
+ String action = "UPDATE";
+
+ if (status.equals(Status.CREATED)) {
+ action = "CREATE";
+ } else if (status.equals(Status.OK)) {
+ action = "UPDATE";
+ } else if (status.equals(Status.NO_CONTENT)) {
+ action = "DELETE";
+ }
+ return action;
+ }
+
/**
* Trigger events.
*
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
index 371c07a5..8d703d3b 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
@@ -196,7 +196,13 @@ public class HttpEntryTest extends AAISetup {
.put("equip-type", "theEquipType")
.toString();
+ JSONObject expectedResponseBody = new JSONObject()
+ .put("hostname", "theHostname")
+ .put("equip-type", "theEquipType");
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, requestBody);
+ JSONObject actualResponseBody = new JSONObject(response.getEntity().toString());
+
+ JSONAssert.assertEquals(expectedResponseBody, actualResponseBody, JSONCompareMode.NON_EXTENSIBLE);
assertEquals("Expected the pserver to be returned", 200, response.getStatus());
}