Fix duplicate thresholds
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / tca / TcaRequestFormatter.java
index 4a07ca3..1478342 100644 (file)
@@ -69,6 +69,8 @@ public class TcaRequestFormatter {
             String service = modelProperties.getGlobal().getService();
             Tca tca = modelProperties.getType(Tca.class);
             modelProperties.setCurrentModelElementId(tca.getId());
+            // Always one tcaItem so must be set to id 0
+            modelProperties.setPolicyUniqueId("0");
             ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.policy.template", service);
             String policyName = modelProperties.getCurrentPolicyScopeAndPolicyName();
             rootNode.put("policyName", policyName);
@@ -155,10 +157,9 @@ public class TcaRequestFormatter {
     private static void addThresholds(ClampProperties refProp, String service, ObjectNode appendToNode, TcaItem tcaItem,
             ModelProperties modelProperties) {
         ArrayNode tcaNodes = appendToNode.withArray("thresholds");
-        ObjectNode tcaNode;
         try {
-            tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
             for (TcaThreshold tcaThreshold : tcaItem.getTcaThresholds()) {
+                ObjectNode tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
                 tcaNode.put("closedLoopControlName", modelProperties.getControlNameAndPolicyUniqueId());
                 tcaNode.put("fieldPath", tcaThreshold.getFieldPath());
                 tcaNode.put("thresholdValue", tcaThreshold.getThreshold());