Create SVG in UI
[clamp.git] / src / main / java / org / onap / clamp / loop / template / LoopElementModel.java
index 4796059..70cdbe2 100644 (file)
@@ -40,7 +40,12 @@ import javax.persistence.ManyToMany;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
 import org.hibernate.annotations.SortNatural;
+import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
+import org.onap.clamp.loop.Loop;
 import org.onap.clamp.loop.common.AuditEntity;
+import org.onap.clamp.policy.Policy;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.operational.OperationalPolicy;
 
 /**
  * This class represents a micro service/operational/... model for a loop template.
@@ -70,11 +75,12 @@ public class LoopElementModel extends AuditEntity implements Serializable {
     @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
     private String blueprint;
 
-    public static String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE";
-    public static String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE";
+    public static final String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE";
+    public static final String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE";
     /**
      * The type of element.
      */
+    @Expose
     @Column(nullable = false, name = "loop_element_type")
     private String loopElementType;
 
@@ -241,6 +247,23 @@ public class LoopElementModel extends AuditEntity implements Serializable {
         this.blueprint = blueprint;
     }
 
+    /**
+     * Create a policy instance from the current loop element model.
+     *
+     * @return A Policy object.
+     */
+    public Policy createPolicyInstance(Loop loop, ToscaConverterWithDictionarySupport toscaConverter) {
+        if (LoopElementModel.MICRO_SERVICE_TYPE.equals(this.getLoopElementType())) {
+            return new MicroServicePolicy(loop, loop.getModelService(), this, toscaConverter);
+        }
+        else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(this.getLoopElementType())) {
+            return new OperationalPolicy(loop, loop.getModelService(), this, toscaConverter);
+        }
+        else {
+            return null;
+        }
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -265,7 +288,8 @@ public class LoopElementModel extends AuditEntity implements Serializable {
             if (other.name != null) {
                 return false;
             }
-        } else if (!name.equals(other.name)) {
+        }
+        else if (!name.equals(other.name)) {
             return false;
         }
         return true;