Merge "log4j security issue"
diff --git a/pom.xml b/pom.xml
index c82ddc9..02ac6dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -99,7 +99,7 @@
 		<docker.skip.tag>true</docker.skip.tag>
 		<skip.staging.artifacts>false</skip.staging.artifacts>
 		<python.http.proxy.param />
-		<tomcat.version>9.0.27</tomcat.version>
+		<tomcat.version>9.0.33</tomcat.version>
 		<ui.react.src>ui-react</ui.react.src>
 		<ui.react.lib.src>ui-react-lib</ui.react.lib.src>
 		<npm.publish.url>https://nexus3.onap.org/repository/npm.snapshot/</npm.publish.url>
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 605e42f..19a17db 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -57,6 +57,7 @@
 import org.onap.clamp.loop.components.external.DcaeComponent;
 import org.onap.clamp.loop.components.external.ExternalComponent;
 import org.onap.clamp.loop.components.external.PolicyComponent;
+import org.onap.clamp.loop.deploy.DcaeDeployParameters;
 import org.onap.clamp.loop.log.LoopLog;
 import org.onap.clamp.loop.service.Service;
 import org.onap.clamp.loop.template.LoopElementModel;
@@ -173,6 +174,7 @@
                         .createPolicyInstance(this, toscaConverter));
             }
         });
+        this.setGlobalPropertiesJson(DcaeDeployParameters.getDcaeDeploymentParametersInJson(this));
     }
 
     public String getName() {
diff --git a/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java b/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java
index 48349e7..e2b16e6 100644
--- a/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java
+++ b/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java
@@ -26,11 +26,9 @@
 import com.google.gson.JsonObject;
 
 import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
-import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
 import org.onap.clamp.clds.util.JsonUtils;
 import org.onap.clamp.loop.Loop;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
@@ -41,32 +39,27 @@
  */
 public class DcaeDeployParameters {
 
-    private static LinkedHashMap<String, JsonObject> init(Set<BlueprintArtifact> blueprintArtifactList, Loop loop) {
+    private static LinkedHashMap<String, JsonObject> init(Loop loop) {
         LinkedHashMap<String, JsonObject> deploymentParamMap = new LinkedHashMap<>();
-        String microServiceName = ((MicroServicePolicy) loop.getMicroServicePolicies().toArray()[0]).getName();
-        // Add index to the microservice name from the 2nd blueprint artifact for now.
-        // Update the microservice names, when able to link the microserivce <->
-        // blueprint in the future
-        int index = 0;
-        for (BlueprintArtifact blueprintArtifact : blueprintArtifactList) {
-            if (index > 0) {
-                deploymentParamMap.put(microServiceName + index,
-                        generateDcaeDeployParameter(blueprintArtifact, microServiceName));
-            } else {
-                deploymentParamMap.put(microServiceName,
-                        generateDcaeDeployParameter(blueprintArtifact, microServiceName));
-            }
-            index++;
+        Set<MicroServicePolicy> microServiceList = loop.getMicroServicePolicies();
+
+        for (MicroServicePolicy microService : microServiceList) {
+                deploymentParamMap.put(microService.getName(),
+                        generateDcaeDeployParameter(microService));
         }
         return deploymentParamMap;
     }
 
-    private static JsonObject generateDcaeDeployParameter(BlueprintArtifact blueprintArtifact,
-            String microServiceName) {
+    private static JsonObject generateDcaeDeployParameter(MicroServicePolicy microService) {
+        return generateDcaeDeployParameter(microService.getLoopElementModel().getBlueprint(),
+                microService.getName());
+    }
+
+    private static JsonObject generateDcaeDeployParameter(String blueprint, String tabName) {
         JsonObject deployJsonBody = new JsonObject();
         Yaml yaml = new Yaml();
         Map<String, Object> inputsNodes = ((Map<String, Object>) ((Map<String, Object>) yaml
-                .load(blueprintArtifact.getDcaeBlueprint())).get("inputs"));
+                .load(blueprint)).get("inputs"));
         inputsNodes.entrySet().stream().filter(e -> !e.getKey().contains("policy_id")).forEach(elem -> {
             Object defaultValue = ((Map<String, Object>) elem.getValue()).get("default");
             if (defaultValue != null) {
@@ -76,7 +69,7 @@
             }
         });
         // For Dublin only one micro service is expected
-        deployJsonBody.addProperty("policy_id", microServiceName);
+        deployJsonBody.addProperty("policy_id", tabName);
         return deployJsonBody;
     }
 
@@ -99,27 +92,20 @@
      *
      * @return The deploymentParameters in Json
      */
-    public static JsonObject getDcaeDeploymentParametersInJson(Set<BlueprintArtifact> blueprintArtifactList,
-            Loop loop) {
-        LinkedHashMap<String, JsonObject> deploymentParamMap = init(blueprintArtifactList, loop);
-
+    public static JsonObject getDcaeDeploymentParametersInJson(Loop loop) {
         JsonObject globalProperties = new JsonObject();
         JsonObject deployParamJson = new JsonObject();
-        for (Map.Entry<String, JsonObject> mapElement : deploymentParamMap.entrySet()) {
-            deployParamJson.add(mapElement.getKey(), mapElement.getValue());
+        if (loop.getLoopTemplate().getUniqueBlueprint()) {
+            String tabName = "loop template blueprint";
+            deployParamJson.add(tabName, generateDcaeDeployParameter(loop.getLoopTemplate().getBlueprint(), tabName));
+        } else {
+            LinkedHashMap<String, JsonObject> deploymentParamMap = init(loop);
+            for (Map.Entry<String, JsonObject> mapElement : deploymentParamMap.entrySet()) {
+                deployParamJson.add(mapElement.getKey(), mapElement.getValue());
+            }
         }
         globalProperties.add("dcaeDeployParameters", deployParamJson);
         return globalProperties;
     }
 
-    /**
-     * Convert the object in Json.
-     *
-     * @return The deploymentParameters in Json
-     */
-    public static JsonObject getDcaeDeploymentParametersInJson(BlueprintArtifact blueprintArtifact, Loop loop) {
-        LinkedHashSet<BlueprintArtifact> blueprintArtifactList = new LinkedHashSet<>();
-        blueprintArtifactList.add(blueprintArtifact);
-        return getDcaeDeploymentParametersInJson(blueprintArtifactList, loop);
-    }
 }
diff --git a/src/main/resources/clds/camel/routes/loop-flows.xml b/src/main/resources/clds/camel/routes/loop-flows.xml
index a4b6e29..8c22743 100644
--- a/src/main/resources/clds/camel/routes/loop-flows.xml
+++ b/src/main/resources/clds/camel/routes/loop-flows.xml
@@ -59,10 +59,10 @@
 				<simple>${body.getName()}</simple>
 			</setProperty>
 			<setProperty propertyName="policyType">
-				<simple>onap.policies.controlloop.Operational</simple>
+				<simple>${body.getPolicyModel().getPolicyModelType()}</simple>
 			</setProperty>
 			<setProperty propertyName="policyVersion">
-				<simple>1</simple>
+				<simple>1.0.0</simple>
 			</setProperty>
 			<setProperty propertyName="operationalPolicy">
 				<simple>${body}</simple>
diff --git a/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java b/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java
index 75ca25c..a580a6a 100644
--- a/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java
+++ b/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java
@@ -34,52 +34,79 @@
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
 import org.onap.clamp.clds.util.JsonUtils;
 import org.onap.clamp.clds.util.ResourceFileUtil;
 import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.LoopElementModel;
+import org.onap.clamp.loop.template.LoopTemplate;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
 
 public class BlueprintInputParametersTest {
 
-    private BlueprintArtifact buildFakeBuildprintArtifact(String blueprintFilePath) throws IOException {
-        BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class);
-        Mockito.when(blueprintArtifact.getDcaeBlueprint())
-                .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath));
-        return blueprintArtifact;
-    }
+    @Test
+    public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException {
+        Loop loop = Mockito.mock(Loop.class);
 
-    private LinkedHashSet<BlueprintArtifact> buildFakeCsarHandler() throws IOException, SdcToscaParserException {
+        MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
+        Mockito.when(umService1.getName()).thenReturn("testName1");
 
-        LinkedHashSet<BlueprintArtifact> blueprintSet = new LinkedHashSet<BlueprintArtifact>();
+        LoopElementModel loopElement = Mockito.mock(LoopElementModel.class);
+        String blueprint1 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
+        Mockito.when(loopElement.getBlueprint()).thenReturn(blueprint1);
+        Mockito.when(umService1.getLoopElementModel()).thenReturn(loopElement);
 
-        BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca.yaml");
+        MicroServicePolicy umService2 = Mockito.mock(MicroServicePolicy.class);
+        Mockito.when(umService2.getName()).thenReturn("testName2");
 
-        blueprintSet.add(blueprintArtifact);
-        // Create fake blueprint artifact 2 on resource2
-        blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca_2.yaml");
-        blueprintSet.add(blueprintArtifact);
+        LoopElementModel loopElement2 = Mockito.mock(LoopElementModel.class);
+        String blueprint2 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_2.yaml");
+        Mockito.when(loopElement2.getBlueprint()).thenReturn(blueprint2);
+        Mockito.when(umService2.getLoopElementModel()).thenReturn(loopElement2);
 
-        // Create fake blueprint artifact 3 on resource 1 so that it's possible to
-        // test multiple CL deployment per Service/vnf
-        blueprintArtifact = buildFakeBuildprintArtifact("example/sdc/blueprint-dcae/tca_3.yaml");
-        blueprintSet.add(blueprintArtifact);
-        return blueprintSet;
+        MicroServicePolicy umService3 = Mockito.mock(MicroServicePolicy.class);
+        Mockito.when(umService3.getName()).thenReturn("testName3");
+
+        LoopElementModel loopElement3 = Mockito.mock(LoopElementModel.class);
+        String blueprint3 = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca_3.yaml");
+        Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3);
+        Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3);
+
+        LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
+        umServiceSet.add(umService1);
+        umServiceSet.add(umService2);
+        umServiceSet.add(umService3);
+        Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
+
+        LoopTemplate template = Mockito.mock(LoopTemplate.class);
+        Mockito.when(template.getUniqueBlueprint()).thenReturn(false);
+        Mockito.when(loop.getLoopTemplate()).thenReturn(template);
+
+        JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
+
+        Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
+            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-multi-blueprints.json"));
     }
 
     @Test
-    public void getDeploymentParametersinJsonTest() throws IOException, SdcToscaParserException {
+    public void getDeploymentParametersinJsonSingleBlueprintTest() throws IOException, SdcToscaParserException {
         Loop loop = Mockito.mock(Loop.class);
-        MicroServicePolicy umService = Mockito.mock(MicroServicePolicy.class);
+
+        MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class);
+        Mockito.when(umService1.getName()).thenReturn("testName1");
         LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>();
-        Mockito.when(umService.getName()).thenReturn("testName");
-        umServiceSet.add(umService);
+        umServiceSet.add(umService1);
         Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet);
 
-        JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(buildFakeCsarHandler(), loop);
+        LoopTemplate template = Mockito.mock(LoopTemplate.class);
+        Mockito.when(template.getUniqueBlueprint()).thenReturn(true);
+        String blueprint = ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml");
+        Mockito.when(template.getBlueprint()).thenReturn(blueprint);
+        Mockito.when(loop.getLoopTemplate()).thenReturn(template);
 
-        Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson), 
-            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters.json"));
+        JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop);
+
+        Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson),
+            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-single-blueprint.json"));
     }
 }
diff --git a/src/test/resources/example/sdc/expected-result/deployment-parameters.json b/src/test/resources/example/sdc/expected-result/deployment-parameters-multi-blueprints.json
similarity index 92%
rename from src/test/resources/example/sdc/expected-result/deployment-parameters.json
rename to src/test/resources/example/sdc/expected-result/deployment-parameters-multi-blueprints.json
index 2e10ac3..6ebaa07 100644
--- a/src/test/resources/example/sdc/expected-result/deployment-parameters.json
+++ b/src/test/resources/example/sdc/expected-result/deployment-parameters-multi-blueprints.json
@@ -1,11 +1,11 @@
 {
   "dcaeDeployParameters": {
-    "testName": {
+    "testName1": {
       "location_id": "",
       "service_id": "",
-      "policy_id": "testName"
+      "policy_id": "testName1"
     },
-    "testName1": {
+    "testName2": {
       "aaiEnrichmentHost": "aai.onap.svc.cluster.local",
       "aaiEnrichmentPort": "8443",
       "enableAAIEnrichment": true,
@@ -20,9 +20,9 @@
       "cbs_port": "10000",
       "external_port": "32012",
       "policy_model_id": "onap.policies.monitoring.cdap.tca.hi.lo.app",
-      "policy_id": "testName"
+      "policy_id": "testName2"
     },
-    "testName2": {
+    "testName3": {
       "aaiEnrichmentHost": "aai.onap.svc.cluster.local",
       "aaiEnrichmentPort": "8443",
       "enableAAIEnrichment": true,
@@ -37,7 +37,7 @@
       "cbs_port": "10000",
       "external_port": "32012",
       "policy_model_id": "onap.policies.monitoring.cdap.tca.hi.lo.app",
-      "policy_id": "testName"
+      "policy_id": "testName3"
     }
   }
 }
\ No newline at end of file
diff --git a/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json b/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json
new file mode 100644
index 0000000..494c2e4
--- /dev/null
+++ b/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json
@@ -0,0 +1,9 @@
+{
+  "dcaeDeployParameters": {
+    "loop template blueprint": {
+      "location_id": "",
+      "service_id": "",
+      "policy_id": "loop template blueprint"
+    }
+  }
+}
\ No newline at end of file