Merge "updated create task BB"
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
index 6fcad95..03559af 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/Resource.java
@@ -27,6 +27,9 @@
 	private boolean generated;
 	private boolean baseVfModule;
 	private String virtualLinkKey;
+	private String vnfCustomizationId;
+	private String vfModuleCustomizationId;
+	private String cvnfModuleCustomizationId;
 	
 	public Resource(WorkflowType resourceType, String resourceId, boolean generated){
 		this.resourceId = resourceId;
@@ -64,4 +67,22 @@
 	public void setVirtualLinkKey(String virtualLinkKey) {
 		this.virtualLinkKey = virtualLinkKey;
 	}
+	public String getVnfCustomizationId() {
+		return vnfCustomizationId;
+	}
+	public void setVnfCustomizationId(String vnfCustomizationId) {
+		this.vnfCustomizationId = vnfCustomizationId;
+	}
+	public String getVfModuleCustomizationId() {
+		return vfModuleCustomizationId;
+	}
+	public void setVfModuleCustomizationId(String vfModuleCustomizationId) {
+		this.vfModuleCustomizationId = vfModuleCustomizationId;
+	}
+	public String getCvnfModuleCustomizationId() {
+		return cvnfModuleCustomizationId;
+	}
+	public void setCvnfModuleCustomizationId(String cvnfModuleCustomizationId) {
+		this.cvnfModuleCustomizationId = cvnfModuleCustomizationId;
+	}
 }
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
index 57d097e..5809d16 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
@@ -43,6 +43,7 @@
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
@@ -167,9 +168,10 @@
 				} else {
 					key = modelInfo.getModelCustomizationId();
 				}
+				Resource resourceKey = new Resource(resourceType, key, aLaCarte);
 				for (OrchestrationFlow orchFlow : orchFlows) {
-					ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, key, apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null);
+					ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false);
 					flowsToExecute.add(ebb);
 				}
 			} else {
@@ -564,7 +566,10 @@
 											if(!vnfCustomizationUUID.equals("")&&!vfModuleCustomizationUUID.equals("")){
 												List<String> configs = traverseCatalogDbForConfiguration(vnfCustomizationUUID,vfModuleCustomizationUUID);
 												for(String config : configs){
-													resourceCounter.add(new Resource(WorkflowType.CONFIGURATION,config,false));
+													Resource configResource = new Resource(WorkflowType.CONFIGURATION,config,false);
+													resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId());
+													resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId());
+													resourceCounter.add(configResource);
 												}
 											}
 										}
@@ -820,69 +825,73 @@
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					workflowResourceIds.setServiceInstanceId(resourceId);
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.SERVICE == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 			} else if (orchFlow.getFlowName().contains(VNF)) {
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VNF == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 			} else if (orchFlow.getFlowName().contains(NETWORK)
 					&& !orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORK == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					Resource resource = resourceCounter.stream().filter(x -> WorkflowType.VIRTUAL_LINK == x.getResourceType())
 							.collect(Collectors.toList()).get(i);
-					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource.getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, true, resource.getVirtualLinkKey()));
+					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resource, apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, true, resource.getVirtualLinkKey(), false));
 				}
 			} else if (orchFlow.getFlowName().contains(VFMODULE)) {
 				List<Resource> vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType())
 						.collect(Collectors.toList()));
 				for (int i = 0; i < vfModuleResourcesSorted.size(); i++) {
-					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 			} else if (orchFlow.getFlowName().contains(VOLUMEGROUP)) {
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.VOLUMEGROUP == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 			} else if (orchFlow.getFlowName().contains(NETWORKCOLLECTION)) {
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 				}
 			} else if (orchFlow.getFlowName().contains(CONFIGURATION)) {
 				for (int i = 0; i < resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType()).collect(Collectors.toList()).size(); i++) {
 					flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, resourceCounter.stream().filter(x -> WorkflowType.CONFIGURATION == x.getResourceType())
-							.collect(Collectors.toList()).get(i).getResourceId(), apiVersion, resourceId,
-							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+							.collect(Collectors.toList()).get(i), apiVersion, resourceId,
+							requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true));
 				}
 			}else {
-				flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, "", apiVersion, resourceId,
-						requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null));
+				flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, null, apiVersion, resourceId,
+						requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false));
 			}
 		}
 		return flowsToExecute;
 	}
 
-	protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, String key,
+	protected ExecuteBuildingBlock buildExecuteBuildingBlock(OrchestrationFlow orchFlow, String requestId, Resource resource,
 			String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType,
-			WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isVirtualLink, String virtualLinkKey) {
+			WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean isVirtualLink, String virtualLinkKey, boolean isConfiguration) {
 		ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
 		BuildingBlock buildingBlock = new BuildingBlock();
 		buildingBlock.setBpmnFlowName(orchFlow.getFlowName());
 		buildingBlock.setMsoId(UUID.randomUUID().toString());
-		buildingBlock.setKey(key);
+		if(resource == null){
+			buildingBlock.setKey("");
+		}else{
+			buildingBlock.setKey(resource.getResourceId());
+		}
 		buildingBlock.setIsVirtualLink(isVirtualLink);
 		buildingBlock.setVirtualLinkKey(virtualLinkKey);
 		executeBuildingBlock.setApiVersion(apiVersion);
@@ -894,6 +903,13 @@
 		executeBuildingBlock.setRequestId(requestId);
 		executeBuildingBlock.setBuildingBlock(buildingBlock);
 		executeBuildingBlock.setRequestDetails(requestDetails);
+		if(isConfiguration){
+			ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
+			configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
+			configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
+			configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
+			executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
+		}
 		return executeBuildingBlock;
 	}
 
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
index e9dc374..e13a765 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java
@@ -148,6 +148,18 @@
         AAIResourceUri vpnBindingURI = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnId);
         injectionHelper.getAaiClient().connect(configurationURI, vpnBindingURI);
     }
+    
+    public void connectConfigurationToVfModule(String configurationId, String vfModuleId, String vnfId){
+    	 AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId);
+    	 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
+    	 injectionHelper.getAaiClient().connect(configurationURI, vfModuleURI);
+    }
+    
+    public void connectConfigurationToVnfc(String configurationId, String vnfcName){
+    	 AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId);
+    	 AAIResourceUri vnfcURI = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfcName);
+    	 injectionHelper.getAaiClient().connect(configurationURI, vnfcURI);
+    }
     /**
      * method to delete Configuration details in A&AI
      *
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java
index 5948c66..3dc9a4d 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java
@@ -43,6 +43,7 @@
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
 import org.onap.so.client.aai.AAIObjectType;
 import org.onap.so.client.aai.AAIResourcesClient;
@@ -63,6 +64,7 @@
     private ServiceInstance serviceInstance;
     private GenericVnf genericVnf;
     private VpnBinding vpnBinding;
+    private VfModule vfModule;
     
 	@Mock
 	protected AAIResourcesClient MOCK_aaiResourcesClient;
@@ -82,6 +84,7 @@
         serviceProxy = buildServiceProxy();
         serviceInstance = buildServiceInstance();
         genericVnf = buildGenericVnf();
+        vfModule = buildVfModule();
         vpnBinding = buildVpnBinding();
         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
     }
@@ -126,6 +129,20 @@
         aaiConfigurationResources.connectConfigurationToGenericVnf(configuration.getConfigurationId(), genericVnf.getVnfId());
         verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
     }
+    
+    @Test
+    public void connectConfigurationToVfModuleTest() {
+        doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
+        aaiConfigurationResources.connectConfigurationToVfModule(configuration.getConfigurationId(), vfModule.getVfModuleId(),genericVnf.getVnfId());
+        verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
+    }
+    
+    @Test
+    public void connectConfigurationToVnfcTest() {
+        doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class));
+        aaiConfigurationResources.connectConfigurationToVnfc(configuration.getConfigurationId(), "vnfcName");
+        verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
+    }
 
     @Test
     public void connectConfigurationToVpnBindingTest() {