diff options
author | 2019-10-15 14:40:16 +0000 | |
---|---|---|
committer | 2019-10-15 14:40:16 +0000 | |
commit | 784caaab0f643aecede5b2d8e5f435d896c8ec17 (patch) | |
tree | fa9c36ce4e31554d837616ec4ae26c75491a2898 /src/main/java | |
parent | cbd5538ebdbd993aa88eed18c6f252780656f26b (diff) | |
parent | 297bacd11441130e2f08636c415c561e2f59d607 (diff) |
Merge "Add support for object characteristic type in Service Order"
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java | 53 | ||||
-rw-r--r-- | src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java | 472 |
2 files changed, 296 insertions, 229 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java index fc0494f..649ae22 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java @@ -14,9 +14,11 @@ package org.onap.nbi.apis.servicecatalog; import java.nio.file.Path; -import java.util.*; - -import io.swagger.util.Json; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; @@ -32,6 +34,7 @@ import io.swagger.models.Model; import io.swagger.models.ModelImpl; import io.swagger.models.properties.Property; import io.swagger.models.properties.PropertyBuilder; +import io.swagger.util.Json; @Service public class ToscaInfosProcessor { @@ -47,7 +50,7 @@ public class ToscaInfosProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaInfosProcessor.class); public void buildResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) - throws SdcToscaParserException { + throws SdcToscaParserException { SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false); @@ -66,7 +69,7 @@ public class ToscaInfosProcessor { // If this Input has a default value, then put it in serviceSpecCharacteristicValue if (input.getDefault() != null) { List<LinkedHashMap> serviceSpecCharacteristicValues = - buildServiceSpecCharacteristicsValuesFromSdc(input); + buildServiceSpecCharacteristicsValuesFromSdc(input); mapParameter.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValues); } serviceSpecCharacteristic.add(mapParameter); @@ -76,7 +79,7 @@ public class ToscaInfosProcessor { List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); List<LinkedHashMap> resourceSpecifications = - (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); + (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); for (LinkedHashMap resourceSpecification : resourceSpecifications) { if (resourceSpecification.get("id") != null) { String id = (String) resourceSpecification.get("id"); @@ -91,7 +94,7 @@ public class ToscaInfosProcessor { if (nodeTemplate == null) continue; resourceSpecification.put("modelCustomizationId", - sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); } } } @@ -109,13 +112,14 @@ public class ToscaInfosProcessor { return serviceSpecCharacteristicValues; } - public void buildAndSaveResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) throws SdcToscaParserException { + public void buildAndSaveResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) + throws SdcToscaParserException { SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false); List<Input> inputs = sdcCsarHelper.getServiceInputs(); - Map<String, Model> definitions = new HashMap<String,Model>(); + Map<String, Model> definitions = new HashMap<String, Model>(); Model model = new ModelImpl(); if (inputs != null && inputs.size() > 0) { @@ -134,26 +138,32 @@ public class ToscaInfosProcessor { } String svcCharacteristicsJson = Json.pretty(definitions); - serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson,serviceCatalogResponse); + serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson, + serviceCatalogResponse); LinkedHashMap inputSchemaRef = new LinkedHashMap(); - inputSchemaRef.put("valueType","Object"); - inputSchemaRef.put("@schemaLocation","/serviceSpecification/"+serviceCatalogResponse.get("id")+"/specificationInputSchema"); - inputSchemaRef.put("@type",serviceCatalogResponse.get("name") + "_ServiceCharacteristic"); + // use object to match examples in Specifications + inputSchemaRef.put("valueType", "object"); + inputSchemaRef.put("@schemaLocation", + "/serviceSpecification/" + serviceCatalogResponse.get("id") + "/specificationInputSchema"); + inputSchemaRef.put("@type", serviceCatalogResponse.get("name") + "_ServiceCharacteristic"); LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap(); - serviceSpecCharacteristic.put("name",serviceCatalogResponse.get("name") + "_ServiceCharacteristics"); - serviceSpecCharacteristic.put("description","This object describes all the inputs needed from the client to interact with the " + serviceCatalogResponse.get("name") + " Service Topology"); - serviceSpecCharacteristic.put("valueType", "Object"); - serviceSpecCharacteristic.put("@type","ONAPServiceCharacteristic"); + serviceSpecCharacteristic.put("name", + serviceCatalogResponse.get("name") + "_ServiceCharacteristics"); + serviceSpecCharacteristic.put("description", + "This object describes all the inputs needed from the client to interact with the " + + serviceCatalogResponse.get("name") + " Service Topology"); + serviceSpecCharacteristic.put("valueType", "object"); + serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic"); serviceSpecCharacteristic.put("@schemaLocation", "null"); - serviceSpecCharacteristic.put("serviceSpecCharacteristicValue",inputSchemaRef); + serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", inputSchemaRef); - serviceCatalogResponse.put("serviceSpecCharacteristic",serviceSpecCharacteristic); + serviceCatalogResponse.put("serviceSpecCharacteristic", serviceSpecCharacteristic); List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); List<LinkedHashMap> resourceSpecifications = - (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); + (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); for (LinkedHashMap resourceSpecification : resourceSpecifications) { if (resourceSpecification.get("id") != null) { String id = (String) resourceSpecification.get("id"); @@ -167,7 +177,8 @@ public class ToscaInfosProcessor { } if (nodeTemplate == null) continue; - resourceSpecification.put("modelCustomizationId", sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + resourceSpecification.put("modelCustomizationId", + sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); } } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java index 208a93d..0caa093 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java @@ -1,19 +1,22 @@ /** * Copyright (c) 2018 Orange * - * 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 + * 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. + * 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. */ package org.onap.nbi.apis.serviceorder.workflow; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import org.onap.nbi.apis.serviceorder.SoClient; @@ -46,237 +49,290 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; @Service public class PostSoProcessor { - private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class); - @Value("${onap.lcpCloudRegionId}") - private String lcpCloudRegionId; + @Value("${onap.lcpCloudRegionId}") + private String lcpCloudRegionId; - @Value("${onap.tenantId}") - private String tenantId; + @Value("${onap.tenantId}") + private String tenantId; - @Value("${so.owning.entity.id}") - private String soOwningEntityId; + @Value("${so.owning.entity.id}") + private String soOwningEntityId; - @Value("${so.owning.entity.name}") - private String soOwningEntityName; + @Value("${so.owning.entity.name}") + private String soOwningEntityName; - @Value("${so.project.name}") - private String soProjectName; + @Value("${so.project.name}") + private String soProjectName; - @Autowired - private ServiceOrderService serviceOrderService; + @Autowired + private ServiceOrderService serviceOrderService; - @Autowired - private SoClient soClient; + @Autowired + private SoClient soClient; - public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem) { - ResponseEntity<CreateServiceInstanceResponse> response = null; - try { - response = postSORequest(serviceOrderItem,serviceOrderInfo); - } catch (NullPointerException e) { - LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e); - response = null; - } - return response; + public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem( + ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem) { + ResponseEntity<CreateServiceInstanceResponse> response = null; + try { + response = postSORequest(serviceOrderItem, serviceOrderInfo); + } catch (NullPointerException e) { + LOGGER.error( + "Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), + e); + response = null; } - - public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder) { - ResponseEntity<CreateE2EServiceInstanceResponse> response; - try { - response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder); - } catch (NullPointerException e) { - LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e); - response = null; - } - return response; + return response; + } + + public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem( + ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem, + ServiceOrder serviceOrder) { + ResponseEntity<CreateE2EServiceInstanceResponse> response; + try { + response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder); + } catch (NullPointerException e) { + LOGGER.error( + "Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), + e); + response = null; } - - private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem, - ServiceOrderInfo serviceOrderInfo) { - RequestDetails requestDetails = buildSoRequest(serviceOrderItem, - serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), + return response; + } + + private ResponseEntity<CreateServiceInstanceResponse> postSORequest( + ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo) { + RequestDetails requestDetails = + buildSoRequest( + serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos() + .get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo()); - MSOPayload msoPayload = new MSOPayload(requestDetails); - ResponseEntity<CreateServiceInstanceResponse> response = null; - - switch (serviceOrderItem.getAction()) { - case ADD: - response = soClient.callCreateServiceInstance(msoPayload); - break; - case DELETE: - response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId()); - break; - case MODIFY: - if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) { - response = soClient.callCreateServiceInstance(msoPayload); - } - if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) { - response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId()); - } - break; - default: - break; + MSOPayload msoPayload = new MSOPayload(requestDetails); + ResponseEntity<CreateServiceInstanceResponse> response = null; + + switch (serviceOrderItem.getAction()) { + case ADD: + response = soClient.callCreateServiceInstance(msoPayload); + break; + case DELETE: + response = + soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); + break; + case MODIFY: + if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { + response = soClient.callCreateServiceInstance(msoPayload); } - return response; - } - - private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem, - ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) { - ServiceModel service = buildE2ESoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo(), serviceOrder); - MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service); - ResponseEntity<CreateE2EServiceInstanceResponse> response = null; - switch (serviceOrderItem.getAction()) { - case ADD: - response = soClient.callE2ECreateServiceInstance(msoE2EPayload); - break; - case DELETE: - response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId()); - break; - case MODIFY: - if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) { - response = soClient.callE2ECreateServiceInstance(msoE2EPayload); - } - if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) { - response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId()); - } - break; - default: - break; + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + response = + soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); } - return response; - } - - - - /** - * Build SO CREATE request from the ServiceOrder and catalog informations from SDC - * - * @param orderItem - * @param sdcInfos - * @param subscriberInfo - * @return - */ - private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map<String, Object> sdcInfos, - SubscriberInfo subscriberInfo) { - RequestDetails requestDetails = new RequestDetails(); - - requestDetails.setSubscriberInfo(subscriberInfo); - - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelType("service"); - modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID")); - modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId()); - modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId()); - modelInfo.setModelName((String) sdcInfos.get("name")); - modelInfo.setModelVersion((String) sdcInfos.get("version")); - requestDetails.setModelInfo(modelInfo); - - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setInstanceName(orderItem.getService().getName()); - requestInfo.setSource("VID"); - requestInfo.setSuppressRollback(false); - requestInfo.setRequestorId("NBI"); - requestDetails.setRequestInfo(requestInfo); - - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setSubscriptionServiceType((String) sdcInfos.get("name")); - requestParameters.setUserParams( - retrieveUserParamsFromServiceCharacteristics(orderItem.getService().getServiceCharacteristic())); - requestParameters.setaLaCarte(true); - requestDetails.setRequestParameters(requestParameters); - - CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId); - requestDetails.setCloudConfiguration(cloudConfiguration); - - OwningEntity owningEntity = new OwningEntity(); - owningEntity.setOwningEntityId(soOwningEntityId); - owningEntity.setOwningEntityName(soOwningEntityName); - requestDetails.setOwningEntity(owningEntity); - - Project project = new Project(); - project.setProjectName(soProjectName); - - requestDetails.setProject(project); - - return requestDetails; + break; + default: + break; } - - /** - * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC - * - * @param serviceOrderItem - * @param serviceOrder - * @param sdcInfos - * @return - */ - //ServiceOrderItem serviceOrderItem --> orderItem? - private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, Map<String, Object> sdcInfos, - SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) { - - subscriberInfo.getGlobalSubscriberId(); - ServiceModel service = new ServiceModel(); - service.setName(serviceOrderItem.getService().getName()); - service.setDescription(serviceOrder.getDescription()); - service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId()); - service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID")); - service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId()); - service.setServiceType((String) sdcInfos.get("name")); - - ParametersModel parameters = new ParametersModel(); - ArrayList<ResourceModel> resources = new ArrayList(); - - ArrayList<Object> resourceObjects = (ArrayList<Object>)sdcInfos.get("resourceSpecification"); - - for(int i = 0; i < resourceObjects.size(); i++) { - - ResourceModel resourceModel = new ResourceModel((Map<String, Object>)resourceObjects.get(i)); - ParametersModel resourceParameters = new ParametersModel(); - resourceModel.setParameters(resourceParameters); - resources.add(resourceModel); - + return response; + } + + private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest( + ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo, + ServiceOrder serviceOrder) { + ServiceModel service = + buildE2ESoRequest( + serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos() + .get(serviceOrderItem.getId()).getCatalogResponse(), + serviceOrderInfo.getSubscriberInfo(), serviceOrder); + MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service); + ResponseEntity<CreateE2EServiceInstanceResponse> response = null; + switch (serviceOrderItem.getAction()) { + case ADD: + response = soClient.callE2ECreateServiceInstance(msoE2EPayload); + break; + case DELETE: + response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId()); + break; + case MODIFY: + if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { + response = soClient.callE2ECreateServiceInstance(msoE2EPayload); } - parameters.setResources(resources); - List<UserParams> userParams = retrieveUserParamsFromServiceCharacteristics(serviceOrderItem.getService().getServiceCharacteristic()); - - // If there are ServiceCharacteristics add them to requestInputs - if (!userParams.isEmpty()){ - Map<String, String> requestInputs = new HashMap<String, String>(); - for (int i = 0; i < userParams.size(); i++) { - requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue()); - } - - parameters.setRequestInputs(requestInputs); + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId()); } - service.setParameters(parameters); - - return service; + break; + default: + break; } + return response; + } + + + + /** + * Build SO CREATE request from the ServiceOrder and catalog informations from SDC + * + * @param orderItem + * @param sdcInfos + * @param subscriberInfo + * @return + */ + private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map<String, Object> sdcInfos, + SubscriberInfo subscriberInfo) { + RequestDetails requestDetails = new RequestDetails(); + + requestDetails.setSubscriberInfo(subscriberInfo); + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType("service"); + modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID")); + modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId()); + modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId()); + modelInfo.setModelName((String) sdcInfos.get("name")); + modelInfo.setModelVersion((String) sdcInfos.get("version")); + requestDetails.setModelInfo(modelInfo); + + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setInstanceName(orderItem.getService().getName()); + requestInfo.setSource("VID"); + requestInfo.setSuppressRollback(false); + requestInfo.setRequestorId("NBI"); + requestDetails.setRequestInfo(requestInfo); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType((String) sdcInfos.get("name")); + requestParameters.setUserParams(retrieveUserParamsFromServiceCharacteristics( + orderItem.getService().getServiceCharacteristic())); + requestParameters.setaLaCarte(true); + requestDetails.setRequestParameters(requestParameters); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId); + requestDetails.setCloudConfiguration(cloudConfiguration); + + OwningEntity owningEntity = new OwningEntity(); + owningEntity.setOwningEntityId(soOwningEntityId); + owningEntity.setOwningEntityName(soOwningEntityName); + requestDetails.setOwningEntity(owningEntity); + + Project project = new Project(); + project.setProjectName(soProjectName); + + requestDetails.setProject(project); + + return requestDetails; + } + + /** + * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC + * + * @param serviceOrderItem + * @param serviceOrder + * @param sdcInfos + * @return + */ + // ServiceOrderItem serviceOrderItem --> orderItem? + private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, + Map<String, Object> sdcInfos, SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) { + + subscriberInfo.getGlobalSubscriberId(); + ServiceModel service = new ServiceModel(); + service.setName(serviceOrderItem.getService().getName()); + service.setDescription(serviceOrder.getDescription()); + service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId()); + service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID")); + service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId()); + service.setServiceType((String) sdcInfos.get("name")); + + ParametersModel parameters = new ParametersModel(); + ArrayList<ResourceModel> resources = new ArrayList(); + + ArrayList<Object> resourceObjects = (ArrayList<Object>) sdcInfos.get("resourceSpecification"); + + for (int i = 0; i < resourceObjects.size(); i++) { + + ResourceModel resourceModel = new ResourceModel((Map<String, Object>) resourceObjects.get(i)); + ParametersModel resourceParameters = new ParametersModel(); + resourceModel.setParameters(resourceParameters); + resources.add(resourceModel); - /** - * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from SDC - */ - private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) { - List<UserParams> userParams = new ArrayList<>(); - - if (!CollectionUtils.isEmpty(characteristics)) { - for (ServiceCharacteristic characteristic : characteristics) { - UserParams userParam = new UserParams(characteristic.getName(), - characteristic.getValue().getServiceCharacteristicValue()); - userParams.add(userParam); + } + parameters.setResources(resources); + List<UserParams> userParams = retrieveUserParamsFromServiceCharacteristics( + serviceOrderItem.getService().getServiceCharacteristic()); + + // If there are ServiceCharacteristics add them to requestInputs + if (!userParams.isEmpty()) { + Map<String, String> requestInputs = new HashMap<String, String>(); + for (int i = 0; i < userParams.size(); i++) { + requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue()); + } + + parameters.setRequestInputs(requestInputs); + } + service.setParameters(parameters); + + return service; + } + + /** + * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from + * SDC + */ + private List<UserParams> retrieveUserParamsFromServiceCharacteristics( + List<ServiceCharacteristic> characteristics) { + List<UserParams> userParams = new ArrayList<>(); + UserParams userParam; + + if (!CollectionUtils.isEmpty(characteristics)) { + for (ServiceCharacteristic characteristic : characteristics) { + // Check is the characteristic is of type object, if proceed as before to allow for + // backwards compatibility. + if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty() + && characteristic.getValueType().equals("object")) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = null; + try { + jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue()); + } catch (IOException e) { + LOGGER.error("Failed to read object json {} , exception is ", + characteristic.getValue().getServiceCharacteristicValue(), e.getMessage()); + } + ObjectNode objectNode = (ObjectNode) jsonNode; + Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields(); + while (iter.hasNext()) { + Map.Entry<String, JsonNode> entry = iter.next(); + if (!entry.getValue().isArray()) { + userParam = new UserParams(entry.getKey(), entry.getValue().asText()); + } else { + ArrayNode arrayNode = (ArrayNode) entry.getValue(); + String arrayNodeValueString = arrayNode.toString(); + userParam = new UserParams(entry.getKey(), arrayNodeValueString); } + userParams.add(userParam); + } } - - return userParams; + // as UserParams for all other types, boolean, string, integer etc + else { + userParam = new UserParams(characteristic.getName(), + characteristic.getValue().getServiceCharacteristicValue()); + userParams.add(userParam); + } + } } + return userParams; + } + } |