Fix bug in operational policy
[clamp.git] / src / main / java / org / onap / clamp / policy / operational / OperationalPolicy.java
index 0825ea9..1c78405 100644 (file)
@@ -32,7 +32,6 @@ import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonSyntaxException;
 import com.google.gson.annotations.Expose;
-
 import java.io.IOException;
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
@@ -40,7 +39,6 @@ import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
@@ -50,11 +48,11 @@ import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 import javax.persistence.Transient;
-
 import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs;
 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.LoopElementModel;
 import org.onap.clamp.loop.template.PolicyModel;
 import org.onap.clamp.policy.Policy;
 import org.yaml.snakeyaml.DumperOptions;
@@ -99,13 +97,18 @@ public class OperationalPolicy extends Policy implements Serializable {
      * @param configurationsJson The operational policy property in the format of
      *                           json
      * @param policyModel        The policy model associated if any, can be null
+     * @param loopElementModel   The loop element from which this instance is supposed to be created
      */
-    public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel) {
+    public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel,
+                             LoopElementModel loopElementModel) {
         this.name = name;
         this.loop = loop;
         this.setPolicyModel(policyModel);
         this.setConfigurationsJson(configurationsJson);
-        LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
+        this.setLoopElementModel(loopElementModel);
+        if (policyModel != null && policyModel.getPolicyModelType().contains("legacy")) {
+            LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
+        }
         try {
             this.setJsonRepresentation(
                     OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));