diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-02-06 11:51:56 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-02-06 11:51:56 +0000 |
commit | d27b2b875e0e52b8a2d66f27eca4aee2eb8213e1 (patch) | |
tree | 8aa308cf486f6cb28d876c1579a9f643b00d983a /bpmn/MSOCoreBPMN | |
parent | e42d72fb3a557fc66a787d1348d3bd389eb9d9a1 (diff) | |
parent | b7a3cecc8ed9d7bfca90f1ce0a0b429a0ca46043 (diff) |
Merge "Refactor of DecomposeJsonUtils class."
Diffstat (limited to 'bpmn/MSOCoreBPMN')
3 files changed, 130 insertions, 181 deletions
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 index 1e68c84878..0e985cc8f1 100644 --- 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 @@ -31,9 +31,8 @@ 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;
-
+import org.openecomp.mso.bpmn.core.json.JsonDecomposingException;
/**
@@ -50,7 +49,6 @@ import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil; public class ServiceDecomposition extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
- DecomposeJsonUtil jsonUtils = new DecomposeJsonUtil();
@JsonProperty("modelInfo")
private ModelInfo modelInfo;
@@ -67,48 +65,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { 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
-
}
//*****
@@ -278,7 +234,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { * 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
+ * @param resource
*/
public void addResource(Resource resource) {
//create resource based upon type
@@ -299,36 +255,36 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addVnfResource(String jsonResource) {
+ public void addVnfResource(String jsonResource) throws JsonDecomposingException {
VnfResource vnfResource = null;
- vnfResource = DecomposeJsonUtil.JsonToVnfResource(jsonResource);
+ vnfResource = DecomposeJsonUtil.jsonToVnfResource(jsonResource);
this.addVnfResource(vnfResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addNetworkResource(String jsonResource) {
+ public void addNetworkResource(String jsonResource) throws JsonDecomposingException {
NetworkResource networkResource = null;
- networkResource = DecomposeJsonUtil.JsonToNetworkResource(jsonResource);
+ networkResource = DecomposeJsonUtil.jsonToNetworkResource(jsonResource);
this.addVnfResource(networkResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addAllottedResource(String jsonResource) {
+ public void addAllottedResource(String jsonResource) throws JsonDecomposingException {
AllottedResource allottedResource = null;
- allottedResource = DecomposeJsonUtil.JsonToAllottedResource(jsonResource);
+ 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
+ * @param newResource
* @return TRUE if replacement was a success
*/
public boolean replaceResource(Resource newResource){
@@ -365,7 +321,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /**
* Given a resource object ID, locate it in the Service Decomposition by its unique ID, and delete it.
- * @param Resource
+ * @param resource
* @return TRUE if delete was a success
*/
public boolean deleteResource(Resource resource){
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 index 71ef09ce33..dcd9e3b39a 100644 --- 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 @@ -20,139 +20,102 @@ package org.openecomp.mso.bpmn.core.json;
-import java.io.Serializable;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
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.ServiceInstance;
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 {
-import org.openecomp.mso.logger.MsoLogger;
+ private static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
-public class DecomposeJsonUtil implements Serializable {
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+ private DecomposeJsonUtil() {
+ }
- /**
- * 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) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
-
- 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();
+ private static ObjectMapper createObjectMapper() {
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- vnfResource = om.readValue(jsonString, VnfResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
- 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) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- 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) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- return allottedResource;
- }
+ return om;
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, ServiceDecomposition.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to service decomposition", e);
+ }
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @param serviceInstanceId service instance id to be put in decoded ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString, String serviceInstanceId)
+ throws JsonDecomposingException {
+ ServiceDecomposition serviceDecomposition = jsonToServiceDecomposition(jsonString);
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstanceId(serviceInstanceId);
+ serviceDecomposition.setServiceInstance(serviceInstance);
+ return serviceDecomposition;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static VnfResource jsonToVnfResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, VnfResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to vnf resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static NetworkResource jsonToNetworkResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, NetworkResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to network resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static AllottedResource jsonToAllottedResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, AllottedResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
+ }
+ }
}
\ No newline at end of file diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java new file mode 100644 index 0000000000..352979e7dd --- /dev/null +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.core.json; + +import java.io.IOException; + +public class JsonDecomposingException extends IOException { + + public JsonDecomposingException(String message, Throwable cause) { + super(message, cause); + } +} |