aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java68
1 files changed, 58 insertions, 10 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
index 0766dae8e1..fb79880572 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2019 Bell Canada
* ================================================================================
+ * Modifications Copyright (c) 2020 Nordix
+ * ================================================================================
* 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
@@ -20,6 +22,7 @@
package org.onap.so.client.cds;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
@@ -34,8 +37,9 @@ import java.util.UUID;
public class GeneratePayloadForCds {
private static final String ORIGINATOR_ID = "SO";
- private static final String MODE = "sync";
private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String DEFAULT_SYNC_MODE = "sync";
+ private static final String MSO_REQUEST_ID = "msoRequestId";
@Autowired
private VnfCDSRequestProvider vnfCDSRequestProvider;
@@ -49,8 +53,12 @@ public class GeneratePayloadForCds {
@Autowired
private ExtractPojosForBB extractPojosForBB;
+ @Autowired
+ private PnfCDSRequestProvider pnfCDSRequestProvider;
+
/**
- * Build properties like (blueprint name, version, action etc..) along with the request payload.
+ * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module
+ * and service.
*
* @param execution - A building block execution object.
* @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
@@ -61,8 +69,9 @@ public class GeneratePayloadForCds {
ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
- String scope = buildingBlock.getBpmnScope();
- String action = buildingBlock.getBpmnAction();
+ final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
+ final String scope = buildingBlock.getBpmnScope();
+ final String action = buildingBlock.getBpmnAction();
CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
@@ -71,7 +80,35 @@ public class GeneratePayloadForCds {
final String requestPayload = requestProvider.buildRequestPayload(action)
.orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
- final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
+ return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE);
+ }
+
+ /**
+ * Build properties like (blueprint name, version, action etc..) along with the request payload for pnf.
+ *
+ * @param execution - A building block execution object.
+ * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
+ * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
+ */
+ public AbstractCDSPropertiesBean buildCdsPropertiesBean(DelegateExecution execution)
+ throws PayloadGenerationException {
+
+ final String scope = String.valueOf(execution.getVariable(PayloadConstants.SCOPE));
+ final String action = String.valueOf(execution.getVariable(PayloadConstants.ACTION));
+ final String requestId = String.valueOf(execution.getVariable(MSO_REQUEST_ID));
+ final String mode = extractAndSetMode(execution);
+
+ CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
+ requestProvider.setExecutionObject(execution);
+
+ final String requestPayload = requestProvider.buildRequestPayload(action)
+ .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
+
+ return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, mode);
+ }
+
+ private AbstractCDSPropertiesBean prepareAndSetCdsPropertyBean(CDSRequestProvider requestProvider,
+ String requestPayload, String requestId, String action, String mode) {
final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean();
cdsPropertiesBean.setRequestObject(requestPayload);
cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName());
@@ -80,23 +117,34 @@ public class GeneratePayloadForCds {
cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID);
cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
cdsPropertiesBean.setActionName(action);
- cdsPropertiesBean.setMode(MODE);
-
+ cdsPropertiesBean.setMode(mode);
return cdsPropertiesBean;
}
+ private String extractAndSetMode(DelegateExecution execution) {
+ String mode = DEFAULT_SYNC_MODE;
+ Object obj = execution.getVariable(PayloadConstants.MODE);
+ if (obj != null && !String.valueOf(obj).isEmpty()) {
+ mode = String.valueOf(obj);
+ }
+ return mode;
+ }
+
private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException {
CDSRequestProvider requestProvider;
switch (scope) {
- case "vnf":
+ case PayloadConstants.VNF_SCOPE:
requestProvider = vnfCDSRequestProvider;
break;
- case "vfModule":
+ case PayloadConstants.VF_MODULE_SCOPE:
requestProvider = vfModuleCDSRequestProvider;
break;
- case "service":
+ case PayloadConstants.SERVICE_SCOPE:
requestProvider = serviceCDSRequestProvider;
break;
+ case PayloadConstants.PNF_SCOPE:
+ requestProvider = pnfCDSRequestProvider;
+ break;
default:
throw new PayloadGenerationException("No scope defined with " + scope);
}