diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-05-28 11:11:09 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-05-28 11:55:34 +0200 |
commit | fa42cc548fb2f002b4e94e79bcbf10fbd7bcfa6d (patch) | |
tree | d8d76d76780b69f48f13400885cc19d13ed48063 /aai-core/src | |
parent | 17cf0fc2bd8ead53beadafe0fda7605fbb27f618 (diff) |
Refactor HttpEntry class - Part 1
- simplify setHttpEntryProperties (later on this will likely be done in the constructor)
- move some logic of UEBNotification into separate methods
- resolve jsonassert dependency conflict
Issue-ID: AAI-3863
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: Ic84b43156890352509dc9c547478abdf53e96d6a
Diffstat (limited to 'aai-core/src')
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()); } |