summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCoreBPMN/src/main/java
diff options
context:
space:
mode:
authorArthur Martella <amartell@research.att.com>2017-09-08 13:27:46 -0400
committerArthur Martella <amartell@research.att.com>2017-09-08 13:32:24 -0400
commit62cd6aaaf74aa91ee0037c0e155c8e7284f07567 (patch)
tree68c0c53c9156f5aa3c6b3599ac940770f986633d /bpmn/MSOCoreBPMN/src/main/java
parentfa1a211d28a912892fcd888569df033900eb01ee (diff)
1710 Rebase - Second Attempt
This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit: 54483fc6606ddb1591a2e9da61bff8712325f924 Wed Sep 6 18:12:56 2017 -0400 Rebasing was done on a branch on top of this commit in so/master in ONAP: 93fbdfbe46104f8859d4754040f979cb7997c157 Thu Sep 7 16:42:59 2017 +0000 Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59 Issue-id: SO-107 Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'bpmn/MSOCoreBPMN/src/main/java')
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/BaseTask.java25
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/HealthCheckHandler.java64
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java27
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java36
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java31
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/AllottedResource.java38
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/HomingSolution.java49
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/NetworkResource.java42
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceDecomposition.java159
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/AllottedResource.java78
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java110
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/InventoryType.java17
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/JsonWrapper.java)98
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModelInfo.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModelInfo.java)55
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModuleResource.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModuleResource.java)10
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/NetworkResource.java58
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Resource.java105
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceDecomposition.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ResourceDecomposition.java)14
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceInstance.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/InstanceData.java)23
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceType.java6
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java414
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceInstance.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceInstanceData.java)15
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Subscriber.java49
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/VnfResource.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/VnfResource.java)65
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java148
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java215
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonWrapper.java125
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/mybatis/URNMapping.java2
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java44
29 files changed, 1596 insertions, 526 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/BaseTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/BaseTask.java
index 5b43c3fc07..dea2fa7c5e 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/BaseTask.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/BaseTask.java
@@ -20,9 +20,6 @@
package org.openecomp.mso.bpmn.core;
-import java.util.Objects;
-
-import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
import org.camunda.bpm.engine.delegate.JavaDelegate;
@@ -30,7 +27,7 @@ import org.camunda.bpm.engine.delegate.JavaDelegate;
/**
* Base class for service tasks.
*/
-public abstract class BaseTask implements JavaDelegate {
+public class BaseTask implements JavaDelegate {
/**
* Get the value of a required field. This method throws
@@ -188,7 +185,13 @@ public abstract class BaseTask implements JavaDelegate {
protected String getOptionalStringField(Expression expression,
DelegateExecution execution, String fieldName) {
Object o = getFieldImpl(expression, execution, fieldName, true);
- return Objects.toString(o, null);
+ if (o instanceof String) {
+ return (String) o;
+ } else if (o == null) {
+ return null;
+ } else {
+ return o.toString();
+ }
}
/**
@@ -524,14 +527,6 @@ public abstract class BaseTask implements JavaDelegate {
return getClass().getSimpleName();
}
-
- /**
- * Check if shouldFail variable is set to true.
- * @param execution
- * @return
- */
- protected boolean shouldFail(DelegateExecution execution) {
- Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
- return shouldFail != null && shouldFail;
- }
+ @Override
+ public void execute(DelegateExecution execution) throws Exception { }
}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/HealthCheckHandler.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/HealthCheckHandler.java
index 409297c927..40ef11d347 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/HealthCheckHandler.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/HealthCheckHandler.java
@@ -20,28 +20,12 @@
package org.openecomp.mso.bpmn.core;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-
import java.io.BufferedReader;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Base64;
import java.util.Map;
-import java.util.Properties;
import java.util.UUID;
-import org.openecomp.mso.logger.MsoLogger;
-import org.openecomp.mso.utils.UUIDChecker;
-import org.openecomp.mso.HealthCheckUtils;
-import org.openecomp.mso.logger.MessageEnum;
-import org.openecomp.mso.utils.CryptoUtils;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.Path;
@@ -49,19 +33,32 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.camunda.bpm.engine.ProcessEngines;
+import org.openecomp.mso.HealthCheckUtils;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.utils.CryptoUtils;
+import org.openecomp.mso.utils.UUIDChecker;
@Path("/")
public class HealthCheckHandler {
private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
private static final String SITENAME = "mso.sitename";
- private static final String ADPTER_ENDPOINT = "mso.adapters.db.endpoint";
+ private static final String ADPTER_ENDPOINT = "mso.openecomp.adapters.db.endpoint";
+ private static final String OPENECOMP_ADAPTER_NAMESPACE = "mso.openecomp.adapter.namespace";
private static final String CONFIG = "mso.bpmn.urn.properties";
- private static final String PENGINE_PROPERTY = "processengine.properties";
- private static final String PENGINE_PARAM = "processEngineName";
private static final String CREDENTIAL = "mso.adapters.db.auth";
private static final String MSOKEY = "mso.msoKey";
+ private String healthcheckDebugEnabled = "mso.healthcheck.log.debug";
private static final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
private static final String NOT_FOUND = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Application Not Started</title></head><body>Application not started. Properties file missing or invalid or database Connection failed</body></html>";
@@ -106,7 +103,7 @@ public class HealthCheckHandler {
}
try {
- if (!this.getSiteStatus (endpoint, siteName, props.get(CREDENTIAL), props.get(MSOKEY))) {
+ if (!this.getSiteStatus (endpoint, siteName, props.get(CREDENTIAL), props.get(MSOKEY), props.get(OPENECOMP_ADAPTER_NAMESPACE))) {
msoLogger.debug("This site is currently disabled for maintenance.");
return HEALTH_CHECK_NOK_RESPONSE;
}
@@ -158,7 +155,7 @@ public class HealthCheckHandler {
}
try {
- if (!this.getSiteStatus (endpoint, siteName, props.get(CREDENTIAL), props.get(MSOKEY))) {
+ if (!this.getSiteStatus (endpoint, siteName, props.get(CREDENTIAL), props.get(MSOKEY), props.get(OPENECOMP_ADAPTER_NAMESPACE))) {
msoLogger.debug("This site is currently disabled for maintenance.");
return HEALTH_CHECK_NOK_RESPONSE;
}
@@ -171,13 +168,7 @@ public class HealthCheckHandler {
}
try {
- InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(PENGINE_PROPERTY);
- Properties prop = new Properties();
- prop.load(stream);
- String [] engineNames = prop.getProperty(PENGINE_PARAM).split(",");
- for (String engine : engineNames) {
- ProcessEngines.getProcessEngine(engine).getIdentityService().createGroupQuery().list();
- }
+ ProcessEngines.getDefaultProcessEngine().getIdentityService().createGroupQuery().list();
} catch (final Exception e) {
msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception while verifying Camunda engine", e);
@@ -224,7 +215,7 @@ public class HealthCheckHandler {
return null;
}
- private boolean getSiteStatus (String url, String site, String credential, String key) throws Exception {
+ private boolean getSiteStatus (String url, String site, String credential, String key, String adapterNamespace) throws Exception {
// set the connection timeout value to 30 seconds (30000 milliseconds)
RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder = requestBuilder.setConnectTimeout(30000);
@@ -238,12 +229,15 @@ public class HealthCheckHandler {
if (cred != null && !cred.isEmpty()) {
post.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(cred.getBytes()));
}
- msoLogger.debug("Post url is: " + url);
+ if(healthcheckDebugEnabled == null){
+ healthcheckDebugEnabled = "false";
+ }
+ BPMNLogger.debug(healthcheckDebugEnabled, "Post url is: " + url);
//now create a soap request message as follows:
final StringBuffer payload = new StringBuffer();
payload.append("\n");
- payload.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:req=\"http://org.openecomp.mso/requestsdb\">\n");
+ payload.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:req=\"" + adapterNamespace + "/requestsdb\">\n");
payload.append("<soapenv:Header/>\n");
payload.append("<soapenv:Body>\n");
payload.append("<req:getSiteStatus>\n");
@@ -252,14 +246,14 @@ public class HealthCheckHandler {
payload.append("</soapenv:Body>\n");
payload.append("</soapenv:Envelope>\n");
- msoLogger.debug ("Initialize SOAP request to url:" + url);
- msoLogger.debug ("The payload of the request is:" + payload);
+ BPMNLogger.debug(healthcheckDebugEnabled, "Initialize SOAP request to url:" + url);
+ BPMNLogger.debug(healthcheckDebugEnabled, "The payload of the request is:" + payload);
HttpEntity entity = new StringEntity(payload.toString(),"UTF-8");
post.setEntity(entity);
CloseableHttpClient client = builder.build ();
HttpResponse response = client.execute(post);
- msoLogger.debug("Response received is:" + response);
+ BPMNLogger.debug(healthcheckDebugEnabled, "Response received is:" + response);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
@@ -278,7 +272,7 @@ public class HealthCheckHandler {
while ((line = rd.readLine()) != null) {
result.append(line);
}
- msoLogger.debug("Content of the response is:" + result);
+ BPMNLogger.debug(healthcheckDebugEnabled, "Content of the response is:" + result);
String status = result.substring(result.indexOf("<return>") + 8, result.indexOf("</return>"));
client.close (); //shut down the connection
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java
index 09288f0cff..b46ffcd7f7 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java
@@ -27,6 +27,7 @@ import java.util.Properties;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
+
import org.openecomp.mso.logger.MsoLogger;
/**
@@ -56,20 +57,38 @@ public class ReadConfigTask extends BaseTask {
msoLogger.debug("propertiesFile = " + thePropertiesFile);
}
- if (shouldFail(execution)) {
- throw new ProcessEngineException(getTaskName() + " Failed");
- }
+ Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
+
+ if (shouldFail != null && shouldFail) {
+ throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
+ }
synchronized (ReadConfigTask.class) {
if (properties == null) {
properties = new Properties();
- try(InputStream stream = getClass().getResourceAsStream(thePropertiesFile)) {
+ InputStream stream = null;
+
+ try {
+ stream = getClass().getResourceAsStream(thePropertiesFile);
+
if (stream == null) {
throw new IOException("Resource not found: " + thePropertiesFile);
}
properties.load(stream);
+
+ stream.close();
+ stream = null;
+
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
}
}
}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java
index 3adba195ea..389fdc0518 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java
@@ -24,11 +24,11 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.stream.Collectors;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
+
import org.openecomp.mso.logger.MsoLogger;
/**
@@ -66,21 +66,45 @@ public class ReadFileTask extends BaseTask {
+ "file = " + theFile);
}
- if (shouldFail(execution)) {
- throw new ProcessEngineException(getTaskName() + " Failed");
- }
+ Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
+
+ if (shouldFail != null && shouldFail) {
+ throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
+ }
Object value = execution.getVariable(theInputVariable);
if (value == null) {
- try(InputStream xmlStream = getClass().getResourceAsStream(theFile)) {
+ InputStream xmlStream = null;
+
+ try {
+ xmlStream = getClass().getResourceAsStream(theFile);
if (xmlStream == null) {
throw new IOException("Resource not found: " + theFile);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(xmlStream));
- value = reader.lines().collect(Collectors.joining());
+ StringBuilder output = new StringBuilder();
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ output.append(line);
+ }
+
+ xmlStream.close();
+ xmlStream = null;
+
+ value = output.toString();
+
+ } finally {
+ if (xmlStream != null) {
+ try {
+ xmlStream.close();
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
}
}
execution.setVariable(theInputVariable, value);
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java
index e42806e95e..31da7376be 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URI;
+import java.util.Iterator;
import javax.xml.transform.stream.StreamSource;
@@ -32,6 +33,7 @@ import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
//import java.util.logging.Logger;
import org.camunda.bpm.engine.delegate.Expression;
+
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
@@ -95,9 +97,11 @@ public class XQueryScriptTask extends BaseTask {
String[] atomicInputVariableArray = (theAtomicInputVariables == null)
? new String[0] : theAtomicInputVariables.split(",[ ]*");
- if (shouldFail(execution)) {
- throw new ProcessEngineException(getTaskName() + " Failed");
- }
+ Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
+
+ if (shouldFail != null && shouldFail) {
+ throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
+ }
// The script could be compiled once and reused, but we are reading it
// and compiling it every time.
@@ -186,7 +190,9 @@ public class XQueryScriptTask extends BaseTask {
// Evaluate the query and collect the output.
StringBuilder output = new StringBuilder();
- for(XdmItem item : evaluator) {
+ Iterator<XdmItem> xdmItems = evaluator.iterator();
+ while (xdmItems.hasNext()) {
+ XdmItem item = xdmItems.next();
if (msoLogger.isDebugEnabled()) {
msoLogger.debug("XQuery result item = " + item);
@@ -212,13 +218,26 @@ public class XQueryScriptTask extends BaseTask {
*/
private XQueryExecutable compile(XQueryCompiler compiler, String resource)
throws Exception {
- try(InputStream xqStream = getClass().getResourceAsStream(resource)) {
+ InputStream xqStream = null;
+ try {
+ xqStream = getClass().getResourceAsStream(resource);
if (xqStream == null) {
throw new IOException("Resource not found: " + resource);
}
- return compiler.compile(xqStream);
+ XQueryExecutable executable = compiler.compile(xqStream);
+ xqStream.close();
+ xqStream = null;
+ return executable;
+ } finally {
+ if (xqStream != null) {
+ try {
+ xqStream.close();
+ } catch (Exception e) {
+ // Do nothing
+ }
+ }
}
}
} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/AllottedResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/AllottedResource.java
deleted file mode 100644
index c7d2ed9583..0000000000
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/AllottedResource.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.openecomp.mso.bpmn.core.decomposition;
-
-import org.codehaus.jackson.map.annotate.JsonRootName;
-
-@JsonRootName("allottedResource")
-public class AllottedResource extends ResourceDecomposition {
-
- private static final long serialVersionUID = 1L;
-
- /*
- * set resourceType for this object
- */
- public AllottedResource(){
- resourceType = "allottedResource";
- }
-
- /*
- * fields specific to VNF resource type
- */
- private String allottedResourceType;
- private String allottedResourceRole;
-
- /*
- * GET and SET
- */
- public String getAllottedResourceType() {
- return allottedResourceType;
- }
- public void setAllottedResourceType(String allottedResourceType) {
- this.allottedResourceType = allottedResourceType;
- }
- public String getAllottedResourceRole() {
- return allottedResourceRole;
- }
- public void setAllottedResourceRole(String allottedResourceRole) {
- this.allottedResourceRole = allottedResourceRole;
- }
-}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/HomingSolution.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/HomingSolution.java
deleted file mode 100644
index f6c1ad917f..0000000000
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/HomingSolution.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.openecomp.mso.bpmn.core.decomposition;
-
-import java.io.Serializable;
-import java.util.List;
-
-public class HomingSolution extends JsonWrapper implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String infraServiceInstanceId;
- private String aicCloudRegionId;
- private String ucpeId;
- private List<String> entitlementPool;
- private List<String> entitlementKeyGroup;
-
- /*
- * GET && SET
- */
- public String getInfraServiceInstanceId() {
- return infraServiceInstanceId;
- }
- public void setInfraServiceInstanceId(String infraServiceInstanceId) {
- this.infraServiceInstanceId = infraServiceInstanceId;
- }
- public String getAicCloudRegionId() {
- return aicCloudRegionId;
- }
- public void setAicCloudRegionId(String aicCloudRegionId) {
- this.aicCloudRegionId = aicCloudRegionId;
- }
- public String getUcpeId() {
- return ucpeId;
- }
- public void setUcpeId(String ucpeId) {
- this.ucpeId = ucpeId;
- }
- public List<String> getEntitlementPool() {
- return entitlementPool;
- }
- public void setEntitlementPool(List<String> entitlementPool) {
- this.entitlementPool = entitlementPool;
- }
- public List getEntitlementKeyGroup() {
- return entitlementKeyGroup;
- }
- public void setEntitlementKeyGroup(List entitlementKeyGroup) {
- this.entitlementKeyGroup = entitlementKeyGroup;
- }
-}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/NetworkResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/NetworkResource.java
deleted file mode 100644
index 16d1010633..0000000000
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/NetworkResource.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.openecomp.mso.bpmn.core.decomposition;
-
-import org.codehaus.jackson.map.annotate.JsonRootName;
-
-
-/**
- * Encapsulates Network resource data set
- * @author
- *
- */
-@JsonRootName("networkResource")
-public class NetworkResource extends ResourceDecomposition {
-
- private static final long serialVersionUID = 1L;
- /*
- * set resourceType for this object
- */
- public NetworkResource(){
- resourceType = "networkResource";
- }
- /*
- * fields specific to VNF resource type
- */
- private String networkType;
- private String networkRole;
-
- /*
- * GET and SET
- */
- public String getNetworkType() {
- return networkType;
- }
- public void setNetworkType(String networkType) {
- this.networkType = networkType;
- }
- public String getNetworkRole() {
- return networkRole;
- }
- public void setNetworkRole(String networkRole) {
- this.networkRole = networkRole;
- }
-}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceDecomposition.java
deleted file mode 100644
index 00ba091677..0000000000
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceDecomposition.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package org.openecomp.mso.bpmn.core.decomposition;
-
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.map.annotate.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import org.json.JSONObject;
-
-
-
-/**
- * Service Decomposition Structure
- * This Java object contains service information:
- * - Service model info
- * - list of VNF resource's decompositon
- * - list of network resource's decompositon
- * - list of allotted resource's decompositon
- */
-@JsonRootName(value = "serviceResources")
-//@JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME)
-public class ServiceDecomposition extends JsonWrapper implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @JsonProperty("modelInfo")
- private ModelInfo modelInfo;
- private ServiceInstanceData serviceInstanceData;
- @JsonProperty("vnfResource")
- private List <VnfResource> vnfResources;
- @JsonProperty("networkResource")
- private List <NetworkResource> networkResources;
- @JsonProperty("allottedResource")
- private List <AllottedResource> allottedResources;
-
- public ServiceDecomposition () {
- super();
- }
-
- public ServiceDecomposition (ModelInfo modelInfo, ServiceInstanceData serviceInstanceData, List <VnfResource> vnfResources, List <NetworkResource> networkResources, List <AllottedResource> allottedResources ) {
- //TODO provide constructor implementation
-// this.modelInfo = modelInfo;
-// this.serviceInstanceData = serviceInstanceData;
-// this.vnfResources = vnfResources;
-// this.networkResources = networkResources;
-// this.allottedResources = allottedResources;
-
- }
-
- public ServiceDecomposition (String catalogRestOutput, String serviceInstanceId) {
- //TODO provide constructor implementation
-
- this.modelInfo = this.JsonToServiceDecomposition(catalogRestOutput).getModelInfo();
- this.vnfResources = this.JsonToServiceDecomposition(catalogRestOutput).getServiceVnfs();
- this.allottedResources = this.JsonToServiceDecomposition(catalogRestOutput).getServiceAllottedResources();
- this.networkResources = this.JsonToServiceDecomposition(catalogRestOutput).getServiceNetworks();
- this.serviceInstanceData = new ServiceInstanceData();
- this.serviceInstanceData.setInstanceId(serviceInstanceId);
- }
- public ServiceDecomposition (JSONObject catalogRestOutput, String serviceInstanceId) {
- //TODO provide constructor implementation
- }
- //GET and SET
- public ModelInfo getModelInfo() {
- return modelInfo;
- }
- public void setModelInfo(ModelInfo modelInfo) {
- this.modelInfo = modelInfo;
- }
- public ServiceInstanceData getServiceInstanceData() {
- return serviceInstanceData;
- }
- public void setServiceInstanceData(ServiceInstanceData serviceInstanceData) {
- this.serviceInstanceData = serviceInstanceData;
- }
- public List<VnfResource> getServiceVnfs() {
- return vnfResources;
- }
- public void setServiceVnfs(List<VnfResource> vnfResources) {
- this.vnfResources = vnfResources;
- }
- public List<NetworkResource> getServiceNetworks() {
- return networkResources;
- }
- public void setServiceNetworks(List<NetworkResource> networkResources) {
- this.networkResources = networkResources;
- }
- public List<AllottedResource> getServiceAllottedResources() {
- return allottedResources;
- }
- public void setServiceAllottedResources(List<AllottedResource> allottedResources) {
- this.allottedResources = allottedResources;
- }
-
- // methods to add to the list
- public void addVnfResource(VnfResource vnfResource) {
- if (vnfResources == null){
- vnfResources = new ArrayList<VnfResource>();
- }
- this.vnfResources.add(vnfResource);
- }
- public void addNetworkResource(NetworkResource networkResource) {
- if (networkResources == null){
- networkResources = new ArrayList<NetworkResource>();
- }
- this.networkResources.add(networkResource);
- }
- public void addAllottedResource(AllottedResource allottedResource) {
- if (allottedResources == null){
- allottedResources = new ArrayList<AllottedResource>();
- }
- this.allottedResources.add(allottedResource);
- }
-
-// //TODO - IF NEEDED, update below methods to return one resource decomposition by (?) ID, not index - used temporarily
-// public VnfResource getnfResource(int index) {
-//
-//// Iterator<VnfResource> iter = vnfResources.iterator();
-//// while (iter.hasNext()) {
-//// VnfResource vnfResource = iter.next();
-//// vnfResource.getModelInfo().getModelInvariantId();
-//// }
-// return this.vnfResources.get(index);
-// }
-// public NetworkResource getNetworkResource( int index) {
-// return this.networkResources.get(index);
-// }
-// public AllottedResource getAllottedResource(int index) {
-// return this.allottedResources.get(index);
-// }
-
- @JsonIgnore
- public List<ResourceDecomposition> getServiceResources(){
- ArrayList serviceResources = new ArrayList();
- serviceResources.addAll(this.getServiceNetworks());
- serviceResources.addAll(this.getServiceVnfs());
- serviceResources.addAll(this.getServiceAllottedResources());
- return serviceResources;
- }
-
- @JsonIgnore
- public String getServiceResourcesJsonString(){
- StringBuffer serviceResourcesJsonStringBuffer = new StringBuffer();
- serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceNetworks())));
- serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceVnfs())));
- serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceAllottedResources())));
- return serviceResourcesJsonStringBuffer.toString();
- }
-
- //return String representation of JSON
- @Override
- public String toString(){
- return "string representation";
- }
-
-}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/AllottedResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/AllottedResource.java
new file mode 100644
index 0000000000..562a4d8124
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/AllottedResource.java
@@ -0,0 +1,78 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+import java.util.UUID;
+
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+
+@JsonRootName("allottedResource")
+public class AllottedResource extends Resource {
+
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * set resourceType for this object
+ */
+ public AllottedResource(){
+ resourceType = ResourceType.ALLOTTED_RESOURCE;
+ setResourceId(UUID.randomUUID().toString());
+ }
+
+ /*
+ * fields specific to Allotted Resource resource type
+ */
+ private String allottedResourceType;
+ private String allottedResourceRole;
+ private String providingServiceModelInvariantUuid;
+ private String nfFunction;
+ private String nfType;
+ private String nfRole;
+ private String nfNamingCode;
+
+ /*
+ * GET and SET
+ */
+ public String getAllottedResourceType() {
+ return allottedResourceType;
+ }
+ public void setAllottedResourceType(String allottedResourceType) {
+ this.allottedResourceType = allottedResourceType;
+ }
+ public String getAllottedResourceRole() {
+ return allottedResourceRole;
+ }
+ public void setAllottedResourceRole(String allottedResourceRole) {
+ this.allottedResourceRole = allottedResourceRole;
+ }
+ public String getProvidingServiceModelInvariantUuid() {
+ return providingServiceModelInvariantUuid;
+ }
+ public void setProvidingServiceModelInvariantUuid(
+ String providingServiceModelInvariantUuid) {
+ this.providingServiceModelInvariantUuid = providingServiceModelInvariantUuid;
+ }
+ public String getNfFunction() {
+ return nfFunction;
+ }
+ public void setNfFunction(String nfFunction) {
+ this.nfFunction = nfFunction;
+ }
+ public String getNfType() {
+ return nfType;
+ }
+ public void setNfType(String nfType) {
+ this.nfType = nfType;
+ }
+ public String getNfRole() {
+ return nfRole;
+ }
+ public void setNfRole(String nfRole) {
+ this.nfRole = nfRole;
+ }
+ public String getNfNamingCode() {
+ return nfNamingCode;
+ }
+ public void setNfNamingCode(String nfNamingCode) {
+ this.nfNamingCode = nfNamingCode;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java
new file mode 100644
index 0000000000..e0b0dcd367
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/HomingSolution.java
@@ -0,0 +1,110 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+@JsonRootName("homingSolution")
+public class HomingSolution extends JsonWrapper implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private InventoryType inventoryType;
+ private String serviceInstanceId;
+ private String vnfHostname;
+ private String cloudOwner;
+ private String cloudRegionId;
+ private String aicClli;
+ private String aicVersion;
+ private String ucpeId; //TODO Remove?
+ private List<String> entitlementPoolList;
+ private List<String> licenseKeyGroupList;
+
+
+ public InventoryType getInventoryType(){
+ return inventoryType;
+ }
+
+ public void setInventoryType(InventoryType inventoryType){
+ this.inventoryType = inventoryType;
+ }
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public void setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ }
+
+ public String getVnfHostname(){
+ return vnfHostname;
+ }
+
+ public void setVnfHostname(String vnfHostname){
+ this.vnfHostname = vnfHostname;
+ }
+
+
+ public String getCloudOwner(){
+ return cloudOwner;
+ }
+
+
+ public void setCloudOwner(String cloudOwner){
+ this.cloudOwner = cloudOwner;
+ }
+
+ public String getCloudRegionId() {
+ return cloudRegionId;
+ }
+
+ public void setCloudRegionId(String cloudRegionId) {
+ this.cloudRegionId = cloudRegionId;
+ }
+
+
+ public String getAicClli(){
+ return aicClli;
+ }
+
+
+ public void setAicClli(String aicClli){
+ this.aicClli = aicClli;
+ }
+
+
+ public String getAicVersion(){
+ return aicVersion;
+ }
+
+
+ public void setAicVersion(String aicVersion){
+ this.aicVersion = aicVersion;
+ }
+
+ public String getUcpeId(){
+ return ucpeId;
+ }
+
+ public void setUcpeId(String ucpeId){
+ this.ucpeId = ucpeId;
+ }
+
+ public List<String> getEntitlementPoolList(){
+ return entitlementPoolList;
+ }
+
+ public void setEntitlementPoolList(List<String> entitlementPoolList){
+ this.entitlementPoolList = entitlementPoolList;
+ }
+
+ public List<String> getLicenseKeyGroupList(){
+ return licenseKeyGroupList;
+ }
+
+ public void setLicenseKeyGroupList(List<String> licenseKeyGroupList){
+ this.licenseKeyGroupList = licenseKeyGroupList;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/InventoryType.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/InventoryType.java
new file mode 100644
index 0000000000..e30a7781eb
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/InventoryType.java
@@ -0,0 +1,17 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+public enum InventoryType{
+
+ cloud("CLOUD"),
+ service("SERVICE");
+
+ private String type;
+
+ private InventoryType(String type){
+ this.type = type;
+ }
+
+ public String type(){
+ return type;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/JsonWrapper.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java
index dcc6852c4e..10e52d1b0d 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/JsonWrapper.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/JsonWrapper.java
@@ -1,59 +1,59 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.io.IOException;
+import java.io.Serializable;
import java.util.List;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectWriter;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
//import org.codehaus.jackson.map.SerializationConfig.Feature;
-import org.codehaus.jackson.map.DeserializationConfig.Feature;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
+
/**
* Wrapper encapsulates needed JSON functionality
* to be extended by MSO service decomposition objects
* providing ways to convert to and from JSON
- *
- * @author
*
*/
@JsonInclude(Include.NON_NULL)
-public abstract class JsonWrapper {
-
+public abstract class JsonWrapper implements Serializable {
+
@JsonInclude(Include.NON_NULL)
public String toJsonString(){
-
-
String jsonString = "";
//convert with Jackson
ObjectMapper mapper = new ObjectMapper();
- mapper.enable(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
- mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+ mapper.setSerializationInclusion(Include.NON_NULL);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
try {
jsonString = ow.writeValueAsString(this);
- } catch (JsonGenerationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JsonMappingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
+// } catch (JsonGenerationException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// } catch (JsonMappingException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ } catch (Exception e){
+
e.printStackTrace();
}
return jsonString;
@@ -66,7 +66,7 @@ public abstract class JsonWrapper {
// mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
//mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
- mapper.enable(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
// mapper.enable(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
JSONObject json = new JSONObject();
try {
@@ -89,7 +89,7 @@ public abstract class JsonWrapper {
public String listToJson(List list) {
ObjectMapper mapper = new ObjectMapper();
- mapper.enable(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
String jsonString = "";
try {
@@ -104,37 +104,31 @@ public abstract class JsonWrapper {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
return jsonString;
}
- /**
- * Method to construct Service Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ServiceDecomposition
- * @return - ServiceDecomposition object
- */
- public ServiceDecomposition JsonToServiceDecomposition(String jsonString) {
-
- ServiceDecomposition serviceDecomposition = new ServiceDecomposition();
- ObjectMapper om = new ObjectMapper();
- om.configure(Feature.UNWRAP_ROOT_VALUE, true);
-
+ @JsonInclude(Include.NON_NULL)
+ public String toJsonStringNoRootName(){
+
+ String jsonString = "";
+ //convert with Jackson
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+
+ ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
try {
- serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);
- } catch (JsonParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JsonMappingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
+ jsonString = ow.writeValueAsString(this);
+ } catch (Exception e){
+
e.printStackTrace();
}
-
- return serviceDecomposition;
+ return jsonString;
}
+ /**
+ * Returns a string representation of this object.
+ */
+ public String toString() {
+ return this.toJsonString();
+ }
}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModelInfo.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModelInfo.java
index ecbb076d80..03dd69e1da 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModelInfo.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModelInfo.java
@@ -1,29 +1,28 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.io.Serializable;
-import org.codehaus.jackson.map.annotate.JsonRootName;
+import com.fasterxml.jackson.annotation.JsonRootName;
@JsonRootName("modelInfo")
public class ModelInfo extends JsonWrapper implements Serializable {
/**
- *
+ * This is domain object defining structure for MODEL INFO
+ * It will be valid for each Resource type object
*/
private static final long serialVersionUID = 1L;
private String modelName = "";
private String modelUuid = "";
- private String modelInvariantId = "";
+ private String modelInvariantUuid = "";
private String modelVersion = "";
//additionally on resource level
private String modelCustomizationUuid = "";
private String modelInstanceName = "";
-
- //TODO - those were present in original "modelInfo" object structure. Confirm.
- private String modelCustomizationName = "";
- private String modelVersionId = "";
private String modelType = "";
+
+ //GET and SET methods
public String getModelName() {
return modelName;
@@ -37,11 +36,11 @@ public class ModelInfo extends JsonWrapper implements Serializable {
public void setModelUuid(String modelUuid) {
this.modelUuid = modelUuid;
}
- public String getModelInvariantId() {
- return modelInvariantId;
+ public String getModelInvariantUuid() {
+ return modelInvariantUuid;
}
- public void setModelInvariantId(String modelInvariantId) {
- this.modelInvariantId = modelInvariantId;
+ public void setModelInvariantUuid(String modelInvariantUuid) {
+ this.modelInvariantUuid = modelInvariantUuid;
}
public String getModelVersion() {
return modelVersion;
@@ -61,41 +60,11 @@ public class ModelInfo extends JsonWrapper implements Serializable {
public void setModelInstanceName(String modelInstanceName) {
this.modelInstanceName = modelInstanceName;
}
- public String getModelCustomizationName() {
- return modelCustomizationName;
- }
- public void setModelCustomizationName(String modelCustomizationName) {
- this.modelCustomizationName = modelCustomizationName;
- }
- public String getModelVersionId() {
- return modelVersionId;
- }
- public void setModelVersionId(String modelVersionId) {
- this.modelVersionId = modelVersionId;
- }
public String getModelType() {
return modelType;
}
public void setModelType(String modelType) {
this.modelType = modelType;
}
-
- //TODO add convenience methods
-
-
- //TODO - complete this manual
- public String toString(){
-
- String jsonString = "";
-
- //can try building manually
- jsonString = "{" +
- "\"modelName\":\"" + getModelName() + "\"," +
- "\"modelUuid\":\"" + getModelUuid() + "\"" +
- "\"modelInvariantId\":\"" + getModelInvariantId() + "\"" +
- "}";
-
- return jsonString;
- }
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModuleResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModuleResource.java
index 1c91f4e600..39cb839b90 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ModuleResource.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ModuleResource.java
@@ -1,9 +1,9 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
-import org.codehaus.jackson.map.annotate.JsonRootName;
+import com.fasterxml.jackson.annotation.JsonRootName;
@JsonRootName("vfModule")
-public class ModuleResource extends ResourceDecomposition {
+public class ModuleResource extends Resource {
private static final long serialVersionUID = 1L;
@@ -11,7 +11,7 @@ public class ModuleResource extends ResourceDecomposition {
* set resourceType for this object
*/
public ModuleResource(){
- resourceType = "module";
+ resourceType = ResourceType.MODULE;
}
/*
@@ -57,4 +57,4 @@ public class ModuleResource extends ResourceDecomposition {
this.hasVolumeGroup = hasVolumeGroup;
}
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/NetworkResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/NetworkResource.java
new file mode 100644
index 0000000000..31f997532f
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/NetworkResource.java
@@ -0,0 +1,58 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+import java.util.UUID;
+
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+
+/**
+ * Encapsulates Network resource data set
+ *
+ */
+@JsonRootName("networkResource")
+public class NetworkResource extends Resource {
+
+ private static final long serialVersionUID = 1L;
+ /*
+ * set resourceType for this object
+ */
+ public NetworkResource(){
+ resourceType = ResourceType.NETWORK;
+ setResourceId(UUID.randomUUID().toString());
+ }
+ /*
+ * fields specific to Network resource type
+ */
+ private String networkType;
+ private String networkRole;
+ private String networkTechnology;
+ private String networkScope;
+
+ /*
+ * GET and SET
+ */
+ public String getNetworkType() {
+ return networkType;
+ }
+ public void setNetworkType(String networkType) {
+ this.networkType = networkType;
+ }
+ public String getNetworkRole() {
+ return networkRole;
+ }
+ public void setNetworkRole(String networkRole) {
+ this.networkRole = networkRole;
+ }
+ public String getNetworkTechnology() {
+ return networkTechnology;
+ }
+ public void setNetworkTechnology(String networkTechnology) {
+ this.networkTechnology = networkTechnology;
+ }
+ public String getNetworkScope() {
+ return networkScope;
+ }
+ public void setNetworkScope(String networkScope) {
+ this.networkScope = networkScope;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Resource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Resource.java
new file mode 100644
index 0000000000..4e6fedde9e
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Resource.java
@@ -0,0 +1,105 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+
+
+public abstract class Resource extends JsonWrapper implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private String resourceId;
+ protected ResourceType resourceType; // Enum of vnf or network or allotted resource
+ protected ModelInfo modelInfo;
+ private long concurrencyCounter = 1L;
+
+ //private List modules;
+ private ResourceInstance resourceInstance = new ResourceInstance(); // TODO possibly remove
+ private HomingSolution homingSolution = new HomingSolution(); // TODO maybe this instead of resourceInstance being "bridge"
+
+ //common parameters for all Resources
+ private String toscaNodeType;
+
+ // GET and SET
+ public String getResourceId() {
+ return resourceId;
+ }
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+ public ModelInfo getModelInfo() {
+ return modelInfo;
+ }
+ public void setModelInfo(ModelInfo modelInfo) {
+ this.modelInfo = modelInfo;
+ }
+
+ public ResourceInstance getResourceInstance() {
+ return resourceInstance;
+ }
+ public void setResourceInstance(ResourceInstance resourceInstance) {
+ this.resourceInstance = resourceInstance;
+ }
+ public HomingSolution getHomingSolution(){
+ return homingSolution;
+ }
+
+ public void setHomingSolution(HomingSolution homingSolution){
+ this.homingSolution = homingSolution;
+ }
+ public void setResourceType(ResourceType resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ public ResourceType getResourceType(){
+ return resourceType;
+ }
+
+ public String getToscaNodeType() {
+ return toscaNodeType;
+ }
+ public void setToscaNodeType(String toscaNodeType) {
+ this.toscaNodeType = toscaNodeType;
+ }
+
+ //Utility methods
+
+ public String getResourceInstanceId() {
+ return this.getResourceInstance().getInstanceId();
+ }
+ public String getResourceInstanceName() {
+ return this.getResourceInstance().getInstanceName();
+ }
+ //TODO
+// @JsonIgnore
+// public String getResourceHomingSolution() {
+// }
+
+ public void setResourceInstanceId(String newInstanceId){
+ this.getResourceInstance().setInstanceId(newInstanceId);
+ }
+ public void setResourceInstanceName(String newInstanceName){
+ this.getResourceInstance().setInstanceName(newInstanceName);
+ }
+
+ //TODO
+// @JsonIgnore
+// public String setResourceHomingSolution() {
+// }
+ /**
+ * To be used by macro flow to increment concurrency counter after update to it's structure was completed
+ */
+ public void incrementConcurrencyCounter(){
+ this.concurrencyCounter ++;
+ }
+ /**
+ * Method to get concurrency counter data
+ * @return long value for the counter
+ */
+ @JsonIgnore
+ public long getConcurrencyCounter(){
+ return concurrencyCounter;
+ }
+
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ResourceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceDecomposition.java
index ba01c8fc44..67e1906223 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ResourceDecomposition.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceDecomposition.java
@@ -1,16 +1,12 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.io.Serializable;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonRootName;
+import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Abstract superclass for all individual decomposition resources
*
- * @author
- *
*/
//@JsonIgnoreProperties
public abstract class ResourceDecomposition extends JsonWrapper implements Serializable {
@@ -21,7 +17,7 @@ public abstract class ResourceDecomposition extends JsonWrapper implements Seri
private ModelInfo modelInfo;
//private List modules;
- private InstanceData instanceData = new InstanceData();
+ private ResourceInstance instanceData = new ResourceInstance();
// GET and SET
public ModelInfo getModelInfo() {
@@ -31,10 +27,10 @@ public abstract class ResourceDecomposition extends JsonWrapper implements Seri
this.modelInfo = modelInfo;
}
- public InstanceData getInstanceData() {
+ public ResourceInstance getInstanceData() {
return instanceData;
}
- public void setInstanceData(InstanceData instanceData) {
+ public void setInstanceData(ResourceInstance instanceData) {
this.instanceData = instanceData;
}
public void setResourceType(String resourceType) {
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/InstanceData.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceInstance.java
index 13e9f9ac00..85368963c1 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/InstanceData.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceInstance.java
@@ -1,21 +1,26 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-@JsonIgnoreProperties
-public class InstanceData extends JsonWrapper implements Serializable {
+/**
+ * This class is used to store instance
+ * data of Resources
+ *
+ * @author cb645j
+ *
+ */
+//@JsonIgnoreProperties
+public class ResourceInstance extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
-
+
private String instanceId;
private String instanceName;
private HomingSolution homingSolution;
-
- /*
- * GET && SET
- */
+
+
public String getInstanceId() {
return instanceId;
}
@@ -34,4 +39,4 @@ public class InstanceData extends JsonWrapper implements Serializable {
public void setHomingSolution(HomingSolution homingSolution) {
this.homingSolution = homingSolution;
}
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceType.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceType.java
new file mode 100644
index 0000000000..85c41e0fc6
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ResourceType.java
@@ -0,0 +1,6 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+public enum ResourceType {
+
+ VNF, NETWORK, MODULE, ALLOTTED_RESOURCE // etc.
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java
new file mode 100644
index 0000000000..4bee115411
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java
@@ -0,0 +1,414 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonRootName;
+
+import org.json.JSONObject;
+import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
+
+
+
+/**
+ * Service Decomposition Structure
+ * This Java object contains service information:
+ * - Service model info
+ * - Service type and role
+ * - list of VNF resource's decompositon
+ * - list of network resource's decompositon
+ * - list of allotted resource's decompositon
+ */
+@JsonRootName(value = "serviceResources")
+//@JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME)
+public class ServiceDecomposition extends JsonWrapper implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ DecomposeJsonUtil jsonUtils = new DecomposeJsonUtil();
+
+ @JsonProperty("modelInfo")
+ private ModelInfo modelInfo;
+ @JsonProperty("serviceType")
+ private String serviceType;
+ @JsonProperty("serviceRole")
+ private String serviceRole;
+ private ServiceInstance serviceInstance;
+ @JsonProperty("vnfResource")
+ private List <VnfResource> vnfResources;
+ @JsonProperty("networkResource")
+ private List <NetworkResource> networkResources;
+ @JsonProperty("allottedResource")
+ private List <AllottedResource> allottedResources;
+
+ public ServiceDecomposition () {
+ super();
+ }
+
+ public ServiceDecomposition (String catalogRestOutput) {
+
+ ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
+ this.modelInfo = serviceDecomposition.getModelInfo();
+ this.vnfResources = serviceDecomposition.getServiceVnfs();
+ this.allottedResources = serviceDecomposition.getServiceAllottedResources();
+ this.networkResources = serviceDecomposition.getServiceNetworks();
+ this.serviceRole = serviceDecomposition.getServiceRole();
+ this.serviceType = serviceDecomposition.getServiceType();
+ }
+
+ /**
+ * Constructor taking Catalog DB Adapter REST output (serviceResources model) + service Instance ID
+ * @param catalogRestOutput
+ * @param serviceInstanceId
+ */
+ public ServiceDecomposition (String catalogRestOutput, String serviceInstanceId) {
+
+ ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
+ this.modelInfo = serviceDecomposition.getModelInfo();
+ this.vnfResources = serviceDecomposition.getServiceVnfs();
+ this.allottedResources = serviceDecomposition.getServiceAllottedResources();
+ this.networkResources = serviceDecomposition.getServiceNetworks();
+
+ this.serviceRole = serviceDecomposition.getServiceRole();
+ this.serviceType = serviceDecomposition.getServiceType();
+
+ this.serviceInstance = new ServiceInstance();
+ this.serviceInstance.setInstanceId(serviceInstanceId);
+ }
+
+ /**
+ * Constructor taking a Service Decomposition JSON serialization
+ * @param catalogRestOutput
+ * @param serviceInstanceId
+ */
+ public ServiceDecomposition (JSONObject jsonServiceDecomposition, String serviceInstanceId) {
+ //TODO provide constructor implementation
+
+ }
+
+ //*****
+ //GET and SET section
+ /**
+ * Return just the service model portion of the Service Decomposition as a Java object.
+ * The service model object should support retrieval as JSON string that is formatted correctly for sending serviceModelInfo to Building Blocks.
+ * @return
+ */
+ public ModelInfo getModelInfo() {
+ return modelInfo;
+ }
+ public void setModelInfo(ModelInfo modelInfo) {
+ this.modelInfo = modelInfo;
+ }
+ public ServiceInstance getServiceInstance() {
+ return serviceInstance;
+ }
+ public void setServiceInstance(ServiceInstance serviceInstance) {
+ this.serviceInstance = serviceInstance;
+ }
+ public List<VnfResource> getServiceVnfs() {
+ return vnfResources;
+ }
+ public void setServiceVnfs(List<VnfResource> vnfResources) {
+ this.vnfResources = vnfResources;
+ }
+ public List<NetworkResource> getServiceNetworks() {
+ return networkResources;
+ }
+ public void setServiceNetworks(List<NetworkResource> networkResources) {
+ this.networkResources = networkResources;
+ }
+ public List<AllottedResource> getServiceAllottedResources() {
+ return allottedResources;
+ }
+ public void setServiceAllottedResources(List<AllottedResource> allottedResources) {
+ this.allottedResources = allottedResources;
+ }
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getServiceRole() {
+ return serviceRole;
+ }
+
+ public void setServiceRole(String serviceRole) {
+ this.serviceRole = serviceRole;
+ }
+ //*****
+
+ //*****
+ //Access methods
+
+
+ /**
+ * This method returns one combined list of Resources of All Types
+ * @return
+ */
+ @JsonIgnore
+ public List<Resource> getServiceResources(){
+ ArrayList serviceResources = new ArrayList();
+ if(this.getServiceAllottedResources() != null){
+ serviceResources.addAll(this.getServiceAllottedResources());
+ }
+ if(this.getServiceNetworks() != null){
+ serviceResources.addAll(this.getServiceNetworks());
+ }
+ if(this.getServiceVnfs() != null){
+ serviceResources.addAll(this.getServiceVnfs());
+ }
+ return serviceResources;
+ }
+
+ /**
+ * This method returns String representation of one combined list of Resources of All Types
+ * @return
+ */
+ @JsonIgnore
+ public String getServiceResourcesJsonString(){
+ StringBuffer serviceResourcesJsonStringBuffer = new StringBuffer();
+ serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceNetworks())));
+ serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceVnfs())));
+ serviceResourcesJsonStringBuffer.append(listToJson((this.getServiceAllottedResources())));
+ return serviceResourcesJsonStringBuffer.toString();
+ }
+
+ /**
+ * Returns a JSON list of all Network Resource structures (i.e. the serialized NetworkDecomposition objects).
+ * @return
+ */
+ @JsonIgnore
+ public String getServiceNetworksJson(){
+ return listToJson(this.getServiceNetworks());
+ }
+ /**
+ * Returns a JSON list of all VnfResource structures (i.e. the serialized VnfResource objects).
+ * @return
+ */
+ @JsonIgnore
+ public String getServiceVnfsJson(){
+ return listToJson(this.getServiceVnfs());
+ }
+ /**
+ * Returns a JSON list of all Allotted Resource structures (i.e. the serialized AllottedResource objects).
+ * @return
+ */
+ @JsonIgnore
+ public String getServiceAllottedResourcesJson(){
+ return listToJson(this.getServiceAllottedResources());
+ }
+
+ //TODO - define Resource Object ID
+ @JsonIgnore
+ public String getVnfResource(String resourceObjectId) {
+
+ Iterator<Resource> iter = getServiceResources().iterator();
+ while (iter.hasNext()) {
+ Resource resource = iter.next();
+ //resource.getModelInfo().getModelInvariantId();
+
+ if (resourceObjectId.equals("extracted information")){
+ return resource.toJsonString();
+ }
+ }
+ return "";
+ }
+
+ //Methods to add Resource to the list
+ /**
+ * Add VNF resource to the list
+ * @param vnfResource
+ */
+ public void addVnfResource(Resource vnfResource) {
+ if (vnfResources == null){
+ vnfResources = new ArrayList<VnfResource>();
+ }
+ this.vnfResources.add((VnfResource)vnfResource);
+ }
+ /**
+ * Add Network resource to the list
+ * @param networkResource
+ */
+ public void addNetworkResource(Resource networkResource) {
+ if (networkResources == null){
+ networkResources = new ArrayList<NetworkResource>();
+ }
+ this.networkResources.add((NetworkResource)networkResource);
+ }
+ /**
+ * Add Allotted resource to the list
+ * @param allottedResource
+ */
+ public void addAllottedResource(Resource allottedResource) {
+ if (allottedResources == null){
+ allottedResources = new ArrayList<AllottedResource>();
+ }
+ this.allottedResources.add((AllottedResource)allottedResource);
+ }
+
+ /**
+ * Add resource to the list
+ * Given a ResourceDecomposition (subclass) object, add it to the Service Decomposition (in the appropriate category, e.g. as a VNF, Network, or Allotted Resource).
+ * As dependencies are not currently supported, add it to the end of any ordered lists.
+ * @param Resource
+ */
+ public void addResource(Resource resource) {
+ //create resource based upon type
+ switch (resource.resourceType) {
+ case VNF:
+ this.addVnfResource(resource);
+ break;
+ case NETWORK:
+ this.addNetworkResource(resource);
+ break;
+ case ALLOTTED_RESOURCE:
+ this.addAllottedResource(resource);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid resource type: " + resource.resourceType);
+ }
+ }
+
+ /**
+ * Add resource to the list
+ * @param Resource
+ */
+ public void addVnfResource(String jsonResource) {
+ VnfResource vnfResource = null;
+ vnfResource = DecomposeJsonUtil.JsonToVnfResource(jsonResource);
+ this.addVnfResource(vnfResource);
+ }
+ /**
+ * Add resource to the list
+ * @param Resource
+ */
+ public void addNetworkResource(String jsonResource) {
+ NetworkResource networkResource = null;
+ networkResource = DecomposeJsonUtil.JsonToNetworkResource(jsonResource);
+ this.addVnfResource(networkResource);
+ }
+ /**
+ * Add resource to the list
+ * @param Resource
+ */
+ public void addAllottedResource(String jsonResource) {
+ AllottedResource allottedResource = null;
+ allottedResource = DecomposeJsonUtil.JsonToAllottedResource(jsonResource);
+ this.addVnfResource(allottedResource);
+ }
+
+ /**
+ * Given a ResourceDecomposition (subclass) object, locate it in the Service Decomposition by its unique ID, and replace the current version with the new one.
+ * This method should support concurrency control via an auto-incrementing field in the ResourceDecomposition class.
+ * @param Resource
+ * @return TRUE if replacement was a success
+ */
+ public boolean replaceResource(Resource newResource){
+ boolean result = false;
+ List serviceResources = getServiceResources();
+ Iterator<Resource> iter = serviceResources.iterator();
+ while (iter.hasNext()) {
+ Resource resource = iter.next();
+ System.out.println("resource found");
+ if (resource.resourceType == newResource.resourceType){
+ System.out.println("resource type matches");
+ if (resource.getResourceId().equalsIgnoreCase(newResource.getResourceId())){
+ System.out.println("resource id matches");
+ //returns TRUE if replacement is a success
+ result = Collections.replaceAll(serviceResources, resource, newResource);
+ }
+ }
+ }
+ //set updated list into ServiceDecomposition
+ this.setResourceList(serviceResources);
+ return result;
+ }
+
+ /**
+ * Given a ResourceDecomposition as a JSON string, locate it in the Service Decomposition by its unique ID,
+ * and replace the current version with the new one.
+ * @param jsonString
+ * @return
+ */
+ public boolean replaceResource(String jsonString){
+ //TODO: define unique ID for the Resource!
+ return false;
+ }
+
+ /**
+ * Given a resource object ID, locate it in the Service Decomposition by its unique ID, and delete it.
+ * @param Resource
+ * @return TRUE if delete was a success
+ */
+ public boolean deleteResource(Resource resource){
+ List serviceResources = getServiceResources();
+ Iterator<Resource> iter = serviceResources.iterator();
+ while (iter.hasNext()) {
+ Resource item = iter.next();
+
+ if (item.resourceType == resource.resourceType){
+ if (item.getResourceId().equalsIgnoreCase(resource.getResourceId())){
+ //returns TRUE if replacement is a success
+ return serviceResources.remove(resource);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Generic method to set List of ResourceDecomposition objects
+ * @param resources
+ * @return
+ */
+ public boolean setResourceList(List<Resource> resources){
+ //create resource based upon type
+ switch (resources.get(0).resourceType) {
+ case VNF:
+ this.setServiceVnfs((List<VnfResource>)(List<?>)resources);
+ break;
+ case NETWORK:
+ this.setServiceNetworks((List<NetworkResource>)(List<?>)resources);
+ break;
+ case ALLOTTED_RESOURCE:
+ this.setServiceAllottedResources((List<AllottedResource>)(List<?>)resources);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid resource type: " + resources.get(0).resourceType);
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ * This method locates and returns a resource in a given
+ * Service Decomposition object by its unique resource id.
+ * Returns null if resource doesn't exist.
+ *
+ * @param resourceId - id of the resource
+ * @return resource
+ */
+ @JsonIgnore
+ public Resource getServiceResource(String resourceId){
+ List<Resource> resources = getServiceResources();
+ Iterator<Resource> iter = resources.iterator();
+ while (iter.hasNext()){
+ Resource resource = iter.next();
+ if (resource.getResourceId().equalsIgnoreCase(resourceId)){
+ //match
+ return resource;
+ }
+ }
+ return null;
+ }
+}
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceInstanceData.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceInstance.java
index 9b7393d742..e8757cb90f 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/ServiceInstanceData.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceInstance.java
@@ -1,13 +1,20 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.io.Serializable;
-public class ServiceInstanceData extends JsonWrapper implements Serializable {
+/**
+ * This class is used to store instance
+ * data of services aka ServiceDecomposition
+ *
+ * @author cb645j
+ *
+ */
+public class ServiceInstance extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
private String instanceId;
private String instanceName;
-
+
public String getInstanceId() {
return instanceId;
}
@@ -20,4 +27,4 @@ public class ServiceInstanceData extends JsonWrapper implements Serializable {
public void setInstanceName(String instanceName) {
this.instanceName = instanceName;
}
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Subscriber.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Subscriber.java
new file mode 100644
index 0000000000..415c412363
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/Subscriber.java
@@ -0,0 +1,49 @@
+package org.openecomp.mso.bpmn.core.domain;
+
+import java.io.Serializable;
+
+public class Subscriber implements Serializable {
+
+ private static final long serialVersionUID = -2416018315129127022L;
+ private String globalId;
+ private String name;
+ private String commonSiteId;
+
+ public Subscriber(String globalId, String name, String commonSiteId){
+ super();
+ this.globalId = globalId;
+ this.name = name;
+ this.commonSiteId = commonSiteId;
+ }
+
+
+ public String getGlobalId(){
+ return globalId;
+ }
+
+
+ public void setGlobalId(String globalId){
+ this.globalId = globalId;
+ }
+
+
+ public String getName(){
+ return name;
+ }
+
+
+ public void setName(String name){
+ this.name = name;
+ }
+
+
+ public String getCommonSiteId(){
+ return commonSiteId;
+ }
+
+ public void setCommonSiteId(String commonSiteId){
+ this.commonSiteId = commonSiteId;
+ }
+
+
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/VnfResource.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/VnfResource.java
index 267a20ebe6..08a74968ea 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/decomposition/VnfResource.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/VnfResource.java
@@ -1,20 +1,19 @@
-package org.openecomp.mso.bpmn.core.decomposition;
+package org.openecomp.mso.bpmn.core.domain;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.map.annotate.JsonRootName;
-
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonRootName;
/**
* Encapsulates VNF resource data set
- * @author
*
*/
@JsonRootName("vnfResource")
-public class VnfResource extends ResourceDecomposition {
+public class VnfResource extends Resource {
private static final long serialVersionUID = 1L;
@@ -22,7 +21,8 @@ public class VnfResource extends ResourceDecomposition {
* set resourceType for this object
*/
public VnfResource(){
- resourceType = "vnfResource";
+ resourceType = ResourceType.VNF;
+ setResourceId(UUID.randomUUID().toString());
}
/*
@@ -31,6 +31,10 @@ public class VnfResource extends ResourceDecomposition {
@JsonProperty("vfModules")
private List <ModuleResource> vfModules;
private String vnfType;
+ private String nfFunction;
+ private String nfType;
+ private String nfRole;
+ private String nfNamingCode;
/*
* GET and SET
@@ -41,13 +45,37 @@ public class VnfResource extends ResourceDecomposition {
public void setModules(List<ModuleResource> moduleResources) {
this.vfModules = moduleResources;
}
+ @Deprecated
+ public void setVnfType(String vnfType) {
+ this.vnfType = vnfType;
+ }
public String getVnfType() {
return vnfType;
}
- public void setVnfType(String vnfType) {
- this.vnfType = vnfType;
+ public String getNfFunction() {
+ return nfFunction;
+ }
+ public void setNfFunction(String nfFunction) {
+ this.nfFunction = nfFunction;
+ }
+ public String getNfType() {
+ return nfType;
+ }
+ public void setNfType(String nfType) {
+ this.nfType = nfType;
+ }
+ public String getNfRole() {
+ return nfRole;
+ }
+ public void setNfRole(String nfRole) {
+ this.nfRole = nfRole;
+ }
+ public String getNfNamingCode() {
+ return nfNamingCode;
+ }
+ public void setNfNamingCode(String nfNamingCode) {
+ this.nfNamingCode = nfNamingCode;
}
-
/*
* GET accessors per design requirements
*/
@@ -59,6 +87,9 @@ public class VnfResource extends ResourceDecomposition {
*/
@JsonIgnore
public List<ModuleResource> getAllVfModuleObjects(){
+ if (vfModules == null) {
+ return null;
+ }
for (int i = 0; i < vfModules.size(); i++) {
ModuleResource moduleResource = vfModules.get(i);
@@ -88,4 +119,16 @@ public class VnfResource extends ResourceDecomposition {
this.vfModules.add(moduleResource);
}
-}
+
+ /**
+ * Utility method to allow construction of the filed in the form of
+ * <serviceResources.modelInfo.modelName>/<serviceVnfs.modelInfo.modelInstanceName>
+ *
+ * default setter for this field deprecated
+ * @param modelName << serviceResources.modelInfo.modelName
+ * @param modelInstanceName
+ */
+ public void constructVnfType(String modelName) {
+ this.vnfType = modelName.concat("/").concat(this.modelInfo.getModelInstanceName());
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java
new file mode 100644
index 0000000000..32c4776daf
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java
@@ -0,0 +1,148 @@
+package org.openecomp.mso.bpmn.core.json;
+
+import java.io.Serializable;
+import java.io.IOException;
+
+
+import org.openecomp.mso.bpmn.core.domain.AllottedResource;
+import org.openecomp.mso.bpmn.core.domain.NetworkResource;
+import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
+import org.openecomp.mso.bpmn.core.domain.VnfResource;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class DecomposeJsonUtil implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Method to construct Service Decomposition object converting
+ * JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ServiceDecomposition
+ * @return - ServiceDecomposition object
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonParseException
+ */
+ public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {
+
+ ServiceDecomposition serviceDecomposition = new ServiceDecomposition();
+ ObjectMapper om = new ObjectMapper();
+ om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ try {
+ serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return serviceDecomposition;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting
+ * JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return - ServiceDecomposition object
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonParseException
+ */
+ public static VnfResource JsonToVnfResource(String jsonString) {
+
+ VnfResource vnfResource = new VnfResource();
+ ObjectMapper om = new ObjectMapper();
+ om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ try {
+ vnfResource = om.readValue(jsonString, VnfResource.class);
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return vnfResource;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting
+ * JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return - ServiceDecomposition object
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonParseException
+ */
+ public static NetworkResource JsonToNetworkResource(String jsonString) {
+
+ NetworkResource networkResource = new NetworkResource();
+ ObjectMapper om = new ObjectMapper();
+ om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ try {
+ networkResource = om.readValue(jsonString, NetworkResource.class);
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return networkResource;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting
+ * JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return - ServiceDecomposition object
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonParseException
+ */
+ public static AllottedResource JsonToAllottedResource(String jsonString) {
+
+ AllottedResource allottedResource = new AllottedResource();
+ ObjectMapper om = new ObjectMapper();
+ om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ try {
+ allottedResource = om.readValue(jsonString, AllottedResource.class);
+ } catch (JsonParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return allottedResource;
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java
index 4c0d068b28..fc59b2ba12 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonUtils.java
@@ -20,7 +20,9 @@
package org.openecomp.mso.bpmn.core.json;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer;
@@ -95,9 +97,11 @@ public class JsonUtils {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
if (pretty) {
- // use the local class method which properly handles certain JSONArray content
+// return XmlTool.normalize(XML.toString(jsonObj));
+// use the local class method which properly handles certain JSONArray content
return XmlTool.normalize(toXMLString(jsonObj, null));
} else {
+// return XML.toString(jsonObj);
// use the local class method which properly handles certain JSONArray content
return toXMLString(jsonObj, null);
}
@@ -106,7 +110,7 @@ public class JsonUtils {
return null;
}
}
-
+
/**
* Uses a modified version of the org.json.XML toString() algorithm
* to convert a JSONObject to an XML Doc. The intent of this is to
@@ -173,7 +177,7 @@ public class JsonUtils {
curObj = jsonArr.get(i);
if (curObj instanceof JSONArray) {
// The XML tags for the nested array should be generated below when this method
-// is called recursively and the JSONArray object is passed
+// is called recursively and the JSONArray object is passed
// strBuf.append("<");
// strBuf.append(key);
// strBuf.append(">");
@@ -237,7 +241,17 @@ public class JsonUtils {
+ tagName + ">" + str + "</" + tagName + ">";
}
}
-
+
+ /**
+ * Invokes json2xml(String, Boolean) defaulting to 'pretty' output.
+ *
+ * @param jsonStr String containing the XML doc
+ * @return String containing the JSON translation
+ */
+ public static String json2xml(String jsonStr) {
+ return json2xml(jsonStr, true);
+ }
+
/**
* Formats the JSON String using the value of MSOJsonIndentFactor.
*
@@ -254,17 +268,7 @@ public class JsonUtils {
return null;
}
}
-
- /**
- * Invokes json2xml(String, Boolean) defaulting to 'pretty' output.
- *
- * @param jsonStr String containing the XML doc
- * @return String containing the JSON translation
- */
- public static String json2xml(String jsonStr) {
- return json2xml(jsonStr, true);
- }
-
+
/**
* Returns an Iterator over the JSON keys in the specified JSON doc.
*
@@ -275,7 +279,7 @@ public class JsonUtils {
public static Iterator <String> getJsonIterator(String jsonStr) throws JSONException {
return new JSONObject(jsonStr).keys();
}
-
+
/**
* Returns the name of the "root" property in the specified JSON doc. The
* "root" property is the single top-level property in the JSON doc. An
@@ -306,7 +310,7 @@ public class JsonUtils {
/**
* Invokes the getJsonRawValue() method and returns the String equivalent of
* the object returned.
- *
+ *
* TBD: May need separate methods for boolean, float, and integer fields if the
* String representation is not sufficient to meet client needs.
*
@@ -334,8 +338,7 @@ public class JsonUtils {
}
return null;
}
-
-
+
/**
* Invokes the getJsonRawValue() method with the wrap flag set to true
* and returns the String equivalent of the json node object returned.
@@ -368,7 +371,7 @@ public class JsonUtils {
/**
* Invokes the getJsonRawValue() method and returns the String equivalent of
* the object returned.
- *
+ *
* TBD: May need separate methods for boolean, float, and integer fields if the
* String representation is not sufficient to meet client needs.
*
@@ -398,8 +401,37 @@ public class JsonUtils {
}
/**
+ * Invokes the getJsonRawValue() method and returns the boolean equivalent of
+ * the object returned.
+ *
+ * @param jsonStr String containing the JSON doc
+ * @param keys full key path to the target value in the format of "key1.key2.key3..."
+ * @return boolean field value associated with keys - default is false
+ */
+ public static boolean getJsonBooleanValue(String jsonStr, String keys) {
+ String isDebugLogEnabled = "true";
+ try {
+ Object rawValue = getJsonRawValue(jsonStr, keys);
+ if (rawValue == null) {
+ return false;
+ } else {
+ if (rawValue instanceof Boolean) {
+ msoLogger.debug("getJsonValue(): the raw value is a Boolean Object=" + ((String) rawValue).toString());
+ return (Boolean) rawValue;
+ } else {
+ msoLogger.debug("getJsonValue(): the raw value is NOT an Boolean Object=" + rawValue.toString());
+ return false;
+ }
+ }
+ } catch (Exception e) {
+ msoLogger.debug("getJsonValue(): unable to parse json to retrieve value for field=" + keys + ". Exception was: " + e.toString());
+ }
+ return false;
+ }
+
+ /**
* Invokes the getJsonParamValue() method to obtain the JSONArray associated with
- * the specified keys. The JSONArray is then walked to retrieve the first array
+ * the specified keys. The JSONArray is then walked to retrieve the first array
* value associated with the specified field name (index=0).
*
* @param jsonStr String containing the JSON doc
@@ -414,7 +446,7 @@ public class JsonUtils {
/**
* Invokes the getJsonRawValue() method to obtain the JSONArray associated with
* the specified keys. The JSONArray is then walked to retrieve the nth array
- * value associated with the specified field name and index
+ * value associated with the specified field name and index.
*
* @param jsonStr String containing the JSON doc
* @param keys full key path to the target value in the format of "key1.key2.key3..."
@@ -510,7 +542,11 @@ public class JsonUtils {
try {
if (jsonObj.has(key)) {
msoLogger.debug("getJsonValueForKey(): found value for key=" + key);
- return ((String) jsonObj.get(key));
+ Object value = jsonObj.get(key);
+ if (value == null)
+ return null;
+ else
+ return ((String) value);
} else {
msoLogger.debug("getJsonValueForKey(): iterating over the keys");
Iterator <String> itr = jsonObj.keys();
@@ -538,7 +574,7 @@ public class JsonUtils {
}
return keyValue;
}
-
+
/**
* Walks the JSONObject (and sub-objects recursively), searching for the first value associated with the
* single key/field name specified. Returns the associated value if found or null if the key is not found
@@ -581,7 +617,50 @@ public class JsonUtils {
}
return keyValue;
}
-
+
+ /**
+ * Walks the JSONObject (and sub-objects recursively), searching for the first value associated with the
+ * single key/field name specified. Returns the associated value if found or null if the key is not found
+ *
+ * @param jsonObj JSONObject representation of the the JSON doc
+ * @param key key to the target value
+ * @return String field value associated with key
+ */
+ public static Boolean getJsonBooleanValueForKey(JSONObject jsonObj, String key) {
+ String isDebugLogEnabled = "true";
+ Boolean keyValue = false;
+ try {
+ if (jsonObj.has(key)) {
+ msoLogger.debug("getJsonBooleanValueForKey(): found value for key=" + key);
+ return ((Boolean) jsonObj.get(key));
+ } else {
+ msoLogger.debug("getJsonBooleanValueForKey(): iterating over the keys");
+ Iterator <String> itr = jsonObj.keys();
+ while (itr.hasNext()) {
+ String nextKey = (String) itr.next();
+ Object obj = jsonObj.get(nextKey);
+ if (obj instanceof JSONObject) {
+ msoLogger.debug("getJsonBooleanValueForKey(): key=" + nextKey + ", points to JSONObject, recursive call");
+ keyValue = getJsonBooleanValueForKey((JSONObject) obj, key);
+ if (keyValue != null) {
+ msoLogger.debug("getJsonBooleanValueForKey(): found value=" + keyValue + ", for key=" + key);
+ break;
+ }
+ } else {
+ msoLogger.debug("getJsonBooleanValueForKey(): key=" + nextKey + ", does not point to a JSONObject, next key");
+ }
+ }
+ }
+ } catch (JSONException je) {
+ // JSONObject::get() throws this exception if one of the specified keys is not found
+ msoLogger.debug("getJsonBooleanValueForKey(): caught JSONException attempting to retrieve value for key=" + key);
+ keyValue = null;
+ } catch (Exception e) {
+ msoLogger.debug("getJsonBooleanValueForKey(): unable to parse json to retrieve value for field=" + key + ". Exception was: " + e.toString());
+ }
+ return keyValue;
+ }
+
/**
* Boolean method to determine if a key path is valid for the JSON doc. Invokes
* getJsonValue().
@@ -597,7 +676,7 @@ public class JsonUtils {
return true;
}
}
-
+
/**
* Inserts the new key/value pair at the appropriate location in the JSON
* document after first determining if keyed field already exists. If
@@ -673,7 +752,7 @@ public class JsonUtils {
*/
private static Object getJsonRawValue(String jsonStr, String keys) {
return getJsonRawValue(jsonStr, keys, false);
- }
+ }
/**
* Walks the JSON doc using the full key path to retrieve the associated
@@ -683,8 +762,8 @@ public class JsonUtils {
*
* @param jsonStr String containing the JSON doc
* @param keys full key path to the target value in the format of "key1.key2.key3..."
- * * @param wrap Boolean which determines if returned JSONObjects sould be "wrapped"
- * Note: wrap does not apply to returned scalar values
+ * @param wrap Boolean which determines if returned JSONObjects sould be "wrapped"
+ * Note: wrap does not apply to returned scalar values
* @return Object field value associated with keys
*/
private static Object getJsonRawValue(String jsonStr, String keys, Boolean wrap) {
@@ -735,7 +814,7 @@ public class JsonUtils {
* @param keys full key path to the value to be deleted in the format of "key1.key2.key3..."
* @return String containing the updated JSON doc
*/
- private static String putJsonValue(String jsonStr, String keys, String value) {
+ private static String putJsonValue(String jsonStr, String keys, String value) {
// String isDebugLogEnabled = "true";
String keyStr = "";
try {
@@ -760,7 +839,7 @@ public class JsonUtils {
}
// should not hit this point if the key points to a valid key value
return null;
-
+
} catch (JSONException je) {
// JSONObject::get() throws this exception if one of the specified keys is not found
msoLogger.debug("putJsonValue(): caught JSONException attempting to retrieve value for key=" + keyStr);
@@ -772,14 +851,13 @@ public class JsonUtils {
}
/**
- * This json util method converts a json "Key" and "Value"
- * entry Array to a Java map.
+ * This json util method converts a json array of Key Value
+ * pair objects into a Java Map.
*
* @param execution
- * @param entryArray - the json value of the entry Array
- *
- * @return map - a Map containing the entries
+ * @param entryArray - the getJsonValue of a json Array of key/value pairs
*
+ * @return Map - a Map containing the entries
*/
public Map<String, String> entryArrayToMap(Execution execution, String entryArray) {
msoLogger.debug("Started Entry Array To Map Util Method");
@@ -801,8 +879,68 @@ public class JsonUtils {
return map;
}
+ /**
+ * This json util method converts a json array of Key Value
+ * pair objects into a Java Map.
+ *
+ * @param execution
+ * @param entryArray - the getJsonValue of a json Array of key/value pairs
+ * @param keyNode - the name of the node that represents the key
+ * @param valueNode - the name of the node that represents the value
+ *
+ * @return Map - a Map containing the entries
+ *
+ */
+ public Map<String, String> entryArrayToMap(Execution execution, String entryArray, String keyNode, String valueNode) {
+ msoLogger.debug("Started Entry Array To Map Util Method");
+
+ Map<String, String> map = new HashMap<String, String>();
+ //Populate Map
+ String entryListJson = "{ \"entry\":" + entryArray + "}";
+ JSONObject obj = new JSONObject(entryListJson);
+ JSONArray arr = obj.getJSONArray("entry");
+ for (int i = 0; i < arr.length(); i++){
+ JSONObject jo = arr.getJSONObject(i);
+ String key = jo.getString(keyNode);
+ String value =jo.getString(valueNode);
+ map.put(key, value);
+ }
+ msoLogger.debug("Outgoing Map is: " + map);
+ msoLogger.debug("Completed Entry Array To Map Util Method");
+ return map;
+ }
/**
+ * This json util method converts a json Array of Strings
+ * to a Java List. It takes each String in the json Array
+ * and puts it in a Java List<String>.
+ *
+ * @param execution
+ * @param stringArray - the getJsonValue of a json array of strings
+ *
+ * @return List - a java list containing the strings
+ *
+ *
+ */
+ public List<String> StringArrayToList(Execution execution, String jsonArrayOfStrings) {
+ msoLogger.debug("Started String Array To List Util Method");
+
+ List<String> list = new ArrayList<String>();
+ //Populate List
+ String stringListJson = "{ \"strings\":" + jsonArrayOfStrings + "}";
+ JSONObject obj = new JSONObject(stringListJson);
+ JSONArray arr = obj.getJSONArray("strings");
+ for (int i = 0; i < arr.length(); i++){
+ String s = arr.getString(i);
+ list.add(s);
+ }
+ msoLogger.debug("Outgoing List is: " + list);
+ msoLogger.debug("Completed String Array To List Util Method");
+ return list;
+ }
+
+ /**
+ *
* Invokes the getJsonRawValue() method to determine if the
* json element/variable exist. Returns true if the
* json element exist
@@ -810,6 +948,8 @@ public class JsonUtils {
* @param jsonStr String containing the JSON doc
* @param keys full key path to the target value in the format of "key1.key2.key3..."
* @return boolean field value associated with keys
+ *
+ *
*/
public static boolean jsonElementExist(String jsonStr, String keys) {
@@ -826,5 +966,4 @@ public class JsonUtils {
return true;
}
-}
-
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonWrapper.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonWrapper.java
new file mode 100644
index 0000000000..8898f27b23
--- /dev/null
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonWrapper.java
@@ -0,0 +1,125 @@
+package org.openecomp.mso.bpmn.core.json;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.List;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+@JsonInclude(Include.NON_NULL)
+public abstract class JsonWrapper implements Serializable {
+
+
+ private static final long serialVersionUID = 8633550139273639875L;
+
+ @JsonInclude(Include.NON_NULL)
+ public String toJsonString(){
+
+ String jsonString = "";
+ //convert with Jackson
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+ mapper.setSerializationInclusion(Include.NON_NULL);
+
+ ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
+ try {
+ jsonString = ow.writeValueAsString(this);
+// } catch (JsonGenerationException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// } catch (JsonMappingException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ } catch (Exception e){
+
+ e.printStackTrace();
+ }
+ return jsonString;
+ }
+
+ @JsonInclude(Include.NON_NULL)
+ public JSONObject toJsonObject() {
+
+ ObjectMapper mapper = new ObjectMapper();
+ // mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
+ //mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
+
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+ // mapper.enable(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+ JSONObject json = new JSONObject();
+ try {
+ json = new JSONObject(mapper.writeValueAsString(this));
+ } catch (JsonGenerationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return json;
+ }
+
+ public String listToJson(List list) {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
+
+ String jsonString = "";
+ try {
+ jsonString = mapper.writeValueAsString(list);
+ } catch (JsonGenerationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return jsonString;
+ }
+
+ @JsonInclude(Include.NON_NULL)
+ public String toJsonStringNoRootName(){
+
+ String jsonString = "";
+ //convert with Jackson
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.setSerializationInclusion(Include.NON_NULL);
+
+ ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
+ try {
+ jsonString = ow.writeValueAsString(this);
+ } catch (Exception e){
+
+ e.printStackTrace();
+ }
+ return jsonString;
+ }
+
+ /**
+ * Returns a string representation of this object.
+ */
+ public String toString() {
+ return this.toJsonString();
+ }
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/mybatis/URNMapping.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/mybatis/URNMapping.java
index 07959cb016..dde51e34df 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/mybatis/URNMapping.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/mybatis/URNMapping.java
@@ -119,4 +119,4 @@ public class URNMapping {
return builder.toString();
}
-}
+} \ No newline at end of file
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java
index ac0c795d7a..7b6d429912 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java
@@ -29,6 +29,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -48,6 +49,7 @@ import javax.xml.xpath.XPathFactory;
import org.openecomp.mso.logger.MsoLogger;
import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
@@ -335,6 +337,48 @@ public final class XmlTool {
}
/**
+ * Parses the XML document String for the first occurrence of the specified element tag.
+ * If found, the value associated with that element tag is replaced with the new value
+ * and a String containing the modified XML document is returned. If the XML passed is
+ * null or the element tag is not found in the document, null will be returned.
+ * @param xml String containing the original XML document.
+ * @param elementTag String containing the tag of the element to be modified.
+ * @param newValue String containing the new value to be used to modify the corresponding element.
+ * @return the contents of the modified XML document as a String or null/empty if the modification failed.
+ * @throws IOException, TransformerException, ParserConfigurationException, SAXException
+ */
+ public static Optional<String> modifyElement(String xml, String elementTag, String newValue) throws IOException, TransformerException,
+ ParserConfigurationException, SAXException {
+
+ if (xml == null || xml.isEmpty()) {
+ // no XML content to be modified, return empty
+ return Optional.empty();
+ }
+
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ dbFactory.setNamespaceAware(true);
+ DocumentBuilder db = dbFactory.newDocumentBuilder();
+ InputSource source = new InputSource(new StringReader(xml));
+ Document doc = db.parse(source);
+
+ Node modNode = doc.getElementsByTagName(elementTag).item(0);
+ if (modNode == null) {
+ // did not find the specified element to be modified, return empty
+ //System.out.println("Did not find element tag " + elementTag + " in XML");
+ return Optional.empty();
+ } else {
+ modNode.setTextContent(newValue);
+ }
+
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ StringWriter writer = new StringWriter();
+ transformer.transform(new DOMSource(doc), new StreamResult(writer));
+ // return the modified String representation of the XML
+ return Optional.of(writer.toString().trim());
+ }
+
+ /**
* Instantiation is not allowed.
*/
private XmlTool() {