2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
15 package org.onap.nbi.apis.serviceorder.workflow;
17 import java.io.IOException;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
23 import java.util.Map.Entry;
24 import java.util.stream.Collectors;
26 import org.onap.nbi.apis.servicecatalog.ServiceSpecificationService;
27 import org.onap.nbi.apis.serviceorder.SoClient;
28 import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic;
29 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
30 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
31 import org.onap.nbi.apis.serviceorder.model.StateType;
32 import org.onap.nbi.apis.serviceorder.model.ServiceStateType;
33 import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration;
34 import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
35 import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse;
36 import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
37 import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EPayload;
38 import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload;
39 import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo;
40 import org.onap.nbi.apis.serviceorder.model.consumer.OwningEntity;
41 import org.onap.nbi.apis.serviceorder.model.consumer.ParametersModel;
42 import org.onap.nbi.apis.serviceorder.model.consumer.Project;
43 import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails;
44 import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo;
45 import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters;
46 import org.onap.nbi.apis.serviceorder.model.consumer.ResourceModel;
47 import org.onap.nbi.apis.serviceorder.model.consumer.ServiceModel;
48 import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
49 import org.onap.nbi.apis.serviceorder.model.consumer.UserParams;
50 import org.onap.nbi.apis.serviceorder.model.consumer.VFModelInfo;
51 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
52 import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.beans.factory.annotation.Value;
57 import org.springframework.http.ResponseEntity;
58 import org.springframework.stereotype.Service;
59 import org.springframework.util.CollectionUtils;
60 import com.fasterxml.jackson.databind.JsonNode;
61 import com.fasterxml.jackson.databind.ObjectMapper;
62 import com.fasterxml.jackson.databind.node.ArrayNode;
63 import com.fasterxml.jackson.databind.node.ObjectNode;
66 public class PostSoProcessor {
68 private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class);
70 @Value("${onap.lcpCloudRegionId}")
71 private String lcpCloudRegionId;
73 @Value("${onap.tenantId}")
74 private String tenantId;
76 @Value("${so.owning.entity.id}")
77 private String soOwningEntityId;
79 @Value("${so.owning.entity.name}")
80 private String soOwningEntityName;
82 @Value("${so.project.name}")
83 private String soProjectName;
85 @Value("${onap.cloudOwner}")
86 private String cloudOwner;
88 @Value("${onap.k8sCloudOwner}")
89 private String k8sCloudOwner;
91 @Value("${onap.k8sCloudRegionId}")
92 private String k8sCloudRegionId;
94 @Value("${k8s-rb-profile-name}")
95 private String k8sRbProfileName;
98 private ServiceOrderService serviceOrderService;
101 private SoClient soClient;
104 ServiceSpecificationService serviceSpecificationService;
106 public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
107 ServiceOrderItem serviceOrderItem) {
108 ResponseEntity<CreateServiceInstanceResponse> response = null;
110 response = postSORequest(serviceOrderItem, serviceOrderInfo);
111 } catch (NullPointerException e) {
112 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
118 public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
119 ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder) {
120 ResponseEntity<CreateE2EServiceInstanceResponse> response;
122 response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder);
123 } catch (NullPointerException e) {
124 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
130 public ResponseEntity<CreateMacroServiceInstanceResponse> postMacroServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
131 ServiceOrderItem serviceOrderItem) {
132 ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
135 response = postSOMacroRequest(serviceOrderItem, serviceOrderInfo);
136 } catch (NullPointerException e) {
137 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
143 private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem,
144 ServiceOrderInfo serviceOrderInfo) {
145 RequestDetails requestDetails = buildSoRequest(serviceOrderItem, serviceOrderInfo);
146 MSOPayload msoPayload = new MSOPayload(requestDetails);
147 ResponseEntity<CreateServiceInstanceResponse> response = null;
149 switch (serviceOrderItem.getAction()) {
151 response = soClient.callCreateServiceInstance(msoPayload);
154 response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId());
157 if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
158 response = soClient.callCreateServiceInstance(msoPayload);
160 if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
161 response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId());
170 private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem,
171 ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) {
172 ServiceModel service = buildE2ESoRequest(serviceOrderItem,
173 serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(),
174 serviceOrderInfo.getSubscriberInfo(), serviceOrder);
175 MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service);
176 ResponseEntity<CreateE2EServiceInstanceResponse> response = null;
177 switch (serviceOrderItem.getAction()) {
179 response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
182 response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(),
183 service.getServiceType(), serviceOrderItem.getService().getId());
186 //EXT-API supports E2E service activation/deactivation with action=modify and seviceState=active/inactive
187 boolean isActivateReq = ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState() ||
188 ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState();
190 if (ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState()) {
191 response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(),
192 service.getServiceType(), serviceOrderItem.getService().getId(),"activate");
194 if (ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState()) {
195 response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(),
196 service.getServiceType(), serviceOrderItem.getService().getId(),"deactivate");
198 //Other E2E service modification follows Deletion followed by activation.
199 //For service modification, do not send serviceState=active/inactive
200 if (!isActivateReq && StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
201 response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
203 if (!isActivateReq && StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
204 response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(),
205 service.getServiceType(), serviceOrderItem.getService().getId());
214 private ResponseEntity<CreateMacroServiceInstanceResponse> postSOMacroRequest(ServiceOrderItem serviceOrderItem,
215 ServiceOrderInfo serviceOrderInfo) {
217 String serviceModuleName = (String) serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId())
218 .getCatalogResponse().get("name");
220 RequestDetails requestDetails = buildSoMacroRequest(serviceOrderItem, serviceOrderInfo);
221 MSOPayload msoMacroPayload = new MSOPayload(requestDetails);
222 ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
224 switch (serviceOrderItem.getAction()) {
226 response = soClient.callMacroCreateServiceInstance(msoMacroPayload);
229 response = soClient.callMacroDeleteServiceInstance(msoMacroPayload,
230 serviceOrderItem.getService().getId());
233 if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
234 // response = soClient.callCreateServiceInstance(msoPayload);
236 if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
237 // response = soClient.callDeleteServiceInstance(msoPayload,
238 // serviceOrderItem.getService().getId());
248 * Build SO MACRO CREATE request from the ServiceOrder and catalog informations from SDC
251 * @param serviceOrderInfo
252 * @param subscriberInfo
255 private RequestDetails buildSoMacroRequest(ServiceOrderItem orderItem, ServiceOrderInfo serviceOrderInfo) {
257 RequestDetails requestDetails = new RequestDetails();
258 Map<String, Object> sdcInfos = serviceOrderInfo.getServiceOrderItemInfos().get(orderItem.getId())
259 .getCatalogResponse();
261 String id = orderItem.getService().getServiceSpecification().getId();
262 Map responseChildRes = serviceSpecificationService.get(id);
263 ArrayList<Map<String, Object>> resourseSpecificationArray = (ArrayList<Map<String, Object>>) responseChildRes
264 .get("resourceSpecification");
266 Map<String, Object> resourseSpecificationMap = resourseSpecificationArray.get(0);
268 Map serviceInstanceParam = (Map) resourseSpecificationMap.get("serviceInstanceParams");
269 Map instanceSpecification = (Map) resourseSpecificationMap.get("InstanceSpecification");
270 ArrayList<VFModelInfo> childResourceSpecification = (ArrayList<VFModelInfo>) resourseSpecificationMap
271 .get("childResourceSpecification");
273 HashMap<String, Object> instanceParamsFromServiceCharacteristics = retrieveInstanceParamsFromServiceCharacteristics(
274 orderItem.getService().getServiceCharacteristic());
276 HashMap<String, Object> instanceParams = (HashMap<String, Object>) buildAndDistinguishServiceAndVnfLevelParams(
277 instanceParamsFromServiceCharacteristics, instanceSpecification, serviceInstanceParam);
279 HashMap<String, Object> vnfInstanceParams = (HashMap<String, Object>) instanceParams.get("vnf");
280 List<Object> serviceObject = new ArrayList<>();
282 ArrayList<Object> vnfInstanceParam = new ArrayList<>();
284 //Differentiating vnf with cnf(Can be discussed and improved)
285 if (instanceSpecification.get("public_net_id") != null) {
286 Map<String, Object> instanceParam = new HashMap<>();
287 //Merge instanceSpecification with vnfInstanceParams
288 instanceSpecification.putAll(vnfInstanceParams);
289 vnfInstanceParam.add(instanceSpecification);
291 vnfInstanceParams.put("k8s-rb-profile-name", k8sRbProfileName);
292 vnfInstanceParam.add(vnfInstanceParams);
295 List resSpec = (ArrayList) sdcInfos.get("resourceSpecification");
296 Map resSpecMap = (Map) resSpec.get(0);
298 Map<String, String> vnfInfoObject = new HashMap<>();
299 vnfInfoObject.put("modelName", (String) resSpecMap.get("name"));
300 vnfInfoObject.put("modelVersionId", (String) resSpecMap.get("id"));
301 vnfInfoObject.put("modelInvariantUuid", (String) resSpecMap.get("resourceInvariantUUID"));
302 vnfInfoObject.put("modelVersion", (String) resSpecMap.get("version"));
303 vnfInfoObject.put("modelCustomizationId", (String) resSpecMap.get("modelCustomizationId"));
304 vnfInfoObject.put("modelInstanceName", (String) resSpecMap.get("resourceInstanceName"));
307 CloudConfiguration cloudConfiguration = null;
309 //Differentiating vnf with cnf(Can be discussed and improved)
310 if (instanceSpecification.get("public_net_id") != null) {
311 cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner);
313 cloudConfiguration = new CloudConfiguration(k8sCloudRegionId, tenantId, k8sCloudOwner);
316 Map<String, String> platformName = new HashMap<>();
317 platformName.put("platformName", "test");
319 Map<String, String> lob = new HashMap<>();
320 lob.put("lineOfBusinessName", "LOB-Demonstration");
322 Map<String, Object> vnfModel = new HashMap<>();
323 vnfModel.put("modelInfo", vnfInfoObject);
324 vnfModel.put("cloudConfiguration", cloudConfiguration);
325 vnfModel.put("platform", platformName);
326 vnfModel.put("lineOfBusiness", lob);
327 vnfModel.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
328 vnfModel.put("instanceName", (String) resSpecMap.get("resourceInstanceName"));
329 vnfModel.put("instanceParams", vnfInstanceParam);
331 List<Object> vfModulesObjects = new ArrayList<>();
332 ArrayList<Map<String, Object>> vfInstanceParam = new ArrayList<>();
334 //Differentiate CNF from VNF
335 if (instanceSpecification.get("public_net_id") != null) {
336 vfInstanceParam.add(instanceSpecification);
339 Map<String, Object> instanceParam = new HashMap<>();
340 instanceParam.put("k8s-rb-profile-name", k8sRbProfileName);
341 vfInstanceParam.add(instanceParam);
344 for (VFModelInfo crsObject : childResourceSpecification) {
345 Map<String, Object> vfModuleObject = new HashMap<>();
346 Map<String, String> vfModuleInfo = new HashMap<>();
348 vfModuleInfo.put("modelName", crsObject.getModelName());
349 vfModuleInfo.put("modelVersionId", crsObject.getModelUuid());
350 vfModuleInfo.put("modelInvariantUuid", crsObject.getModelInvariantUuid());
351 vfModuleInfo.put("modelVersion", crsObject.getModelVersion());
352 vfModuleInfo.put("modelCustomizationId", crsObject.getModelCustomizationUuid());
353 vfModuleObject.put("modelInfo", vfModuleInfo);
354 vfModuleObject.put("instanceName", crsObject.getModelName());
355 vfModuleObject.put("instanceParams", vfInstanceParam);
357 vfModulesObjects.add(vfModuleObject);
359 vnfModel.put("vfModules", vfModulesObjects);
361 List<Object> vnfObjects = new ArrayList<>();
362 vnfObjects.add(vnfModel);
364 Map<String, Object> vnfData = new HashMap<>();
365 vnfData.put("vnfs", vnfObjects);
367 ModelInfo serviceModelInfo = new ModelInfo();
368 serviceModelInfo.setModelType("service");
369 serviceModelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
370 serviceModelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
371 serviceModelInfo.setModelName((String) sdcInfos.get("name"));
372 serviceModelInfo.setModelVersion((String) sdcInfos.get("version"));
374 // Adding List of instanceParams for service
375 // We can add instanceParams Key Value in Map Object and add it to the List, for
376 // For now it is empty to comply with so request
378 List<Map<String, String>> listOfServiceLevelInstanceParams = new ArrayList<>();
379 Map<String, String> serviceInstanceParams = (HashMap<String, String>) instanceParams.get("service");
380 listOfServiceLevelInstanceParams.add(serviceInstanceParams);
382 Map<String, Object> serviceData = new HashMap<>();
383 serviceData.put("instanceParams", listOfServiceLevelInstanceParams);
384 serviceData.put("instanceName", orderItem.getService().getName());
385 serviceData.put("resources", vnfData);
386 serviceData.put("modelInfo", serviceModelInfo);
388 Map<String, String> homingObject = new HashMap<>();
389 homingObject.put("Homing_Solution", "none");
390 serviceObject.add(homingObject);
392 Map<String, Object> serviceObject1 = new HashMap<>();
393 serviceObject1.put("service", serviceData);
394 serviceObject.add(serviceObject1);
395 requestDetails.setSubscriberInfo(serviceOrderInfo.getSubscriberInfo());
397 ModelInfo modelInfo = new ModelInfo();
398 modelInfo.setModelType("service");
399 modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
400 modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
401 modelInfo.setModelName((String) sdcInfos.get("name"));
402 modelInfo.setModelVersion((String) sdcInfos.get("version"));
403 requestDetails.setModelInfo(modelInfo);
405 RequestInfo requestInfo = new RequestInfo();
406 requestInfo.setInstanceName(orderItem.getService().getName());
407 requestInfo.setSource("VID");
408 requestInfo.setSuppressRollback(false);
409 requestInfo.setRequestorId("NBI");
410 requestInfo.setProductFamilyId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
411 requestDetails.setRequestInfo(requestInfo);
413 // We are taking RequestParameters as map because it has UserParams which gives value as
414 // "name" : "service"
415 // "value" : "", which SO is not accepting
416 Map<String, Object> requestParameters = new HashMap<>();
418 // Get value from serviceOrder request or generate one
419 String serviceTypeFromJson = orderItem.getService().getServicetype();
420 requestParameters.put("subscriptionServiceType",
421 serviceTypeFromJson != null ? serviceTypeFromJson : (String) sdcInfos.get("name"));
422 requestParameters.put("userParams", serviceObject);
423 requestParameters.put("aLaCarte", false);
424 requestDetails.setRequestParameters(requestParameters);
425 requestDetails.setCloudConfiguration(cloudConfiguration);
427 OwningEntity owningEntity = new OwningEntity();
428 owningEntity.setOwningEntityId(soOwningEntityId);
429 owningEntity.setOwningEntityName(soOwningEntityName);
430 requestDetails.setOwningEntity(owningEntity);
432 Project project = new Project();
433 project.setProjectName(soProjectName);
435 requestDetails.setProject(project);
436 return requestDetails;
440 * Build SO CREATE request from the ServiceOrder and catalog informations from SDC
443 * @param serviceOrderInfo
446 private RequestDetails buildSoRequest(ServiceOrderItem orderItem, ServiceOrderInfo serviceOrderInfo) {
447 RequestDetails requestDetails = new RequestDetails();
449 requestDetails.setSubscriberInfo(serviceOrderInfo.getSubscriberInfo());
450 Map<String, Object> sdcInfos =
451 serviceOrderInfo.getServiceOrderItemInfos().get(orderItem.getId()).getCatalogResponse();
452 ModelInfo modelInfo = new ModelInfo();
453 modelInfo.setModelType("service");
454 modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
455 modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId());
456 modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
457 modelInfo.setModelName((String) sdcInfos.get("name"));
458 modelInfo.setModelVersion((String) sdcInfos.get("version"));
459 requestDetails.setModelInfo(modelInfo);
461 RequestInfo requestInfo = new RequestInfo();
462 requestInfo.setInstanceName(orderItem.getService().getName());
463 requestInfo.setSource("VID");
464 requestInfo.setSuppressRollback(false);
465 requestInfo.setRequestorId("NBI");
466 requestDetails.setRequestInfo(requestInfo);
468 RequestParameters requestParameters = new RequestParameters();
470 String serviceTypeFromJson = orderItem.getService().getServicetype();
471 requestParameters.setSubscriptionServiceType(serviceTypeFromJson != null ? serviceTypeFromJson:(String) sdcInfos.get("name"));
472 requestParameters.setUserParams(
473 retrieveUserParamsFromServiceCharacteristics(orderItem.getService().getServiceCharacteristic()));
474 requestParameters.setaLaCarte(true);
475 requestParameters.setTestApi("GR_API");
476 requestDetails.setRequestParameters(requestParameters);
478 CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner);
479 requestDetails.setCloudConfiguration(cloudConfiguration);
481 OwningEntity owningEntity = new OwningEntity();
482 owningEntity.setOwningEntityId(serviceOrderInfo.getOwningEntityId());
483 owningEntity.setOwningEntityName(soOwningEntityName);
484 requestDetails.setOwningEntity(owningEntity);
486 Project project = new Project();
487 project.setProjectName(soProjectName);
489 requestDetails.setProject(project);
491 return requestDetails;
495 * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC
497 * @param serviceOrderItem
498 * @param serviceOrder
502 // ServiceOrderItem serviceOrderItem --> orderItem?
503 private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, Map<String, Object> sdcInfos,
504 SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) {
506 subscriberInfo.getGlobalSubscriberId();
507 ServiceModel service = new ServiceModel();
508 service.setName(serviceOrderItem.getService().getName());
509 service.setDescription(serviceOrder.getDescription());
510 service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId());
511 service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID"));
512 service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId());
513 String serviceTypeFromJson = serviceOrderItem.getService().getServicetype();
514 service.setServiceType(serviceTypeFromJson != null ? serviceTypeFromJson : (String) sdcInfos.get("name"));
515 ParametersModel parameters = new ParametersModel();
516 ArrayList<ResourceModel> resources = new ArrayList();
518 ArrayList<Object> resourceObjects = (ArrayList<Object>) sdcInfos.get("resourceSpecification");
520 for (int i = 0; i < resourceObjects.size(); i++) {
522 ResourceModel resourceModel = new ResourceModel((Map<String, Object>) resourceObjects.get(i));
523 ParametersModel resourceParameters = new ParametersModel();
524 resourceModel.setParameters(resourceParameters);
525 resources.add(resourceModel);
528 parameters.setResources(resources);
529 List<UserParams> userParams =
530 retrieveUserParamsFromServiceCharacteristics(serviceOrderItem.getService().getServiceCharacteristic());
532 // If there are ServiceCharacteristics add them to requestInputs
533 if (!userParams.isEmpty()) {
534 Map<String, String> requestInputs = new HashMap<String, String>();
535 for (int i = 0; i < userParams.size(); i++) {
536 requestInputs.put(userParams.get(i).getName(), (String) userParams.get(i).getValue());
539 parameters.setRequestInputs(requestInputs);
541 service.setParameters(parameters);
547 * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from
550 private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) {
551 List<UserParams> userParams = new ArrayList<>();
552 UserParams userParam;
554 if (!CollectionUtils.isEmpty(characteristics)) {
555 for (ServiceCharacteristic characteristic : characteristics) {
556 // Check is the characteristic is of type object, if proceed as before to allow for
557 // backwards compatibility.
558 if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty()
559 && characteristic.getValueType().equals("object")) {
560 ObjectMapper mapper = new ObjectMapper();
561 JsonNode jsonNode = null;
563 jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue());
564 } catch (IOException e) {
565 LOGGER.error("Failed to read object json {} , exception is ",
566 characteristic.getValue().getServiceCharacteristicValue(), e.getMessage());
568 ObjectNode objectNode = (ObjectNode) jsonNode;
569 Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
570 while (iter.hasNext()) {
571 Map.Entry<String, JsonNode> entry = iter.next();
572 if (!entry.getValue().isArray()) {
573 userParam = new UserParams(entry.getKey(), entry.getValue().asText());
575 ArrayNode arrayNode = (ArrayNode) entry.getValue();
576 String arrayNodeValueString = arrayNode.toString();
577 userParam = new UserParams(entry.getKey(), arrayNodeValueString);
579 userParams.add(userParam);
582 // as UserParams for all other types, boolean, string, integer etc
584 userParam = new UserParams(characteristic.getName(),
585 characteristic.getValue().getServiceCharacteristicValue());
586 userParams.add(userParam);
595 * Build a list of InstanceParams for the SO Macro request by browsing a list of
596 * ServiceCharacteristics
598 private HashMap<String, Object> retrieveInstanceParamsFromServiceCharacteristics(
599 List<ServiceCharacteristic> characteristics) {
601 HashMap<String, Object> instanceParams = new HashMap<>();
603 if (!CollectionUtils.isEmpty(characteristics)) {
604 for (ServiceCharacteristic characteristic : characteristics) {
605 // Check is the characteristic is of type object, if proceed as before to allow
607 // backwards compatibility.
608 if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty()
609 && characteristic.getValueType().equals("object")) {
610 ObjectMapper mapper = new ObjectMapper();
611 JsonNode jsonNode = null;
613 jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue());
614 } catch (IOException e) {
615 LOGGER.error("Failed to read object json {} , exception is ",
616 characteristic.getValue().getServiceCharacteristicValue(), e.getMessage());
618 ObjectNode objectNode = (ObjectNode) jsonNode;
619 Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
620 while (iter.hasNext()) {
621 Map.Entry<String, JsonNode> entry = iter.next();
622 if (!entry.getValue().isArray()) {
623 instanceParams.put(entry.getKey(), entry.getValue().asText());
625 ArrayNode arrayNode = (ArrayNode) entry.getValue();
626 String arrayNodeValueString = arrayNode.toString();
627 instanceParams.put(entry.getKey(), arrayNodeValueString);
631 instanceParams.put(characteristic.getName(),
632 characteristic.getValue().getServiceCharacteristicValue());
637 return instanceParams;
641 * Build and distinguish InstanceParams at VNF Level and Service level and overwrite values from ServiceOrder JSON Request.
642 * Can be used as buildAndDistinguishServiceAndVnfLevelParams.get("vnf"); or buildAndDistinguishServiceAndVnfLevelParams.get("cnf");
644 private Map<String, Object> buildAndDistinguishServiceAndVnfLevelParams(
645 Map<String, Object> instanceParamsFromServiceCharacteristic, Map<String, Object> existingVNFParams,
646 Map<String, Object> existingServiceParams) {
648 //To be used by passing key as "vnf" or "service" for respective instanceParams
649 Map<String, Object> serviceAndVNFLevelInstanceParams = new HashMap<>();
651 Map<String, Object> resultVNFParams = new HashMap<>();
652 Map<String, Object> resultServiceParams = new HashMap<>();
654 // First Filter VNF level Params From Service Characteristics and overwrite
656 resultVNFParams = instanceParamsFromServiceCharacteristic.entrySet().stream()
657 .filter(entry -> existingVNFParams.containsKey(entry.getKey()))
658 .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
660 //Add it as VNF level Params
661 serviceAndVNFLevelInstanceParams.put("vnf", resultVNFParams);
663 // Filter VNF level Params From Service Level
664 existingServiceParams.entrySet().removeIf(e -> existingVNFParams.containsKey(e.getKey()));
666 // Filter Service level Params From Service Characteristics and overwrite values
667 resultServiceParams = instanceParamsFromServiceCharacteristic.entrySet().stream()
668 .filter(entry -> existingServiceParams.containsKey(entry.getKey()))
669 .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
671 //Add it as Service level params
672 serviceAndVNFLevelInstanceParams.put("service", resultServiceParams);
674 return serviceAndVNFLevelInstanceParams;