summaryrefslogtreecommitdiffstats
path: root/sli
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-02-27 16:27:37 -0500
committerDan Timoney <dtimoney@att.com>2020-02-28 16:30:33 +0000
commitce993645564e2ba43c80fdc80a7265dc4032ceae (patch)
tree08e7b53a4969a1429589cc002390d7234506c746 /sli
parentde26ce8cdf4a64e690e7409319c6d738e8666135 (diff)
Support merge JSON to SvcLogicContext
Add support for merging JSON into SvcLogicContext Change-Id: If13fd6328a36ccff6393d0829319bbd99cd2a1f0 Issue-ID: CCSDK-2096 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sli')
-rwxr-xr-xsli/common/pom.xml4
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java34
-rw-r--r--sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java14
-rw-r--r--sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java26
4 files changed, 71 insertions, 7 deletions
diff --git a/sli/common/pom.xml b/sli/common/pom.xml
index 8290a42b..2570f33b 100755
--- a/sli/common/pom.xml
+++ b/sli/common/pom.xml
@@ -61,6 +61,10 @@
<groupId>org.onap.logging-analytics</groupId>
<artifactId>logging-slf4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
index 3681e1e1..fcd51d14 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
@@ -25,6 +25,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
+import com.google.gson.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@@ -207,6 +209,38 @@ public class SvcLogicContext {
}
+ public void mergeJson(String pfx, String jsonString) {
+ JsonParser jp = new JsonParser();
+ JsonElement element = jp.parse(jsonString);
+
+ mergeJsonObject(element.getAsJsonObject(), pfx+".");
+ }
+
+ public void mergeJsonObject(JsonObject jsonObject, String pfx) {
+ for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
+ if (entry.getValue().isJsonObject()) {
+ mergeJsonObject(entry.getValue().getAsJsonObject(), pfx + entry.getKey() + ".");
+ } else if (entry.getValue().isJsonArray()) {
+ JsonArray array = entry.getValue().getAsJsonArray();
+ this.setAttribute(pfx + entry.getKey() + "_length", String.valueOf(array.size()));
+ Integer arrayIdx = 0;
+ for (JsonElement element : array) {
+ if (element.isJsonObject()) {
+ mergeJsonObject(element.getAsJsonObject(), pfx + entry.getKey() + "[" + arrayIdx + "].");
+ }
+ arrayIdx++;
+ }
+ } else {
+ if (entry.getValue() instanceof JsonNull) {
+ LOG.debug("Skipping parameter {} with null value",entry.getKey());
+
+ } else {
+ this.setAttribute(pfx + entry.getKey(), entry.getValue().getAsString());
+ }
+ }
+ }
+ }
+
public String resolve(String ctxVarName) {
if (ctxVarName.indexOf('[') == -1) {
diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java
index 8c436fef..3bade813 100644
--- a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java
+++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceBase.java
@@ -56,6 +56,20 @@ public interface SvcLogicServiceBase {
*
*/
Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException;
+ /**
+ * Execute a directed graph
+ *
+ * @param module - module name
+ * @param rpc - rpc name
+ * @param version - version. If null, use active version
+ * @param mode - mode (sync/async)
+ * @param ctx - parameters, as a SvcLogicContext object
+ * @return final values of attributes from SvcLogicContext, as Properties
+ * @throws SvcLogicException
+ *
+ *
+ */
+ SvcLogicContext execute(String module, String rpc, String version, String mode, SvcLogicContext ctx) throws SvcLogicException;
SvcLogicStore getStore() throws SvcLogicException;
diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java
index 80d992f2..75673f75 100644
--- a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java
+++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicServiceImplBase.java
@@ -142,25 +142,37 @@ public class SvcLogicServiceImplBase implements SvcLogicServiceBase {
@Override
public Properties execute(String module, String rpc, String version, String mode, Properties props)
throws SvcLogicException {
+
+ SvcLogicContext ctx = new SvcLogicContext(props);
+
+ return(execute(module, rpc, version, mode, ctx).toProperties());
+ }
+
+ @Override
+ public SvcLogicContext execute(String module, String rpc, String version, String mode, SvcLogicContext ctx) throws SvcLogicException {
SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
+ if (ctx == null) {
+ ctx = new SvcLogicContext();
+ }
+
if (graph == null) {
- Properties retProps = new Properties();
- retProps.setProperty("error-code", "401");
- retProps.setProperty("error-message",
+ ctx.setAttribute("error-code", "401");
+ ctx.setAttribute("error-message",
"No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
- return (retProps);
+ return (ctx);
}
- SvcLogicContext ctx = new SvcLogicContext(props);
+
+
ctx.setAttribute(CURRENT_GRAPH, graph.toString());
// To support legacy code we should not stop populating X-ECOMP-RequestID
ctx.setAttribute("X-ECOMP-RequestID", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
execute(graph, ctx);
- return (ctx.toProperties());
+ return (ctx);
}
- @Override
+ @Override
public SvcLogicStore getStore() throws SvcLogicException {
return this.store;
}