Rework the submit operation
[clamp.git] / src / main / java / org / onap / clamp / loop / Loop.java
index 910c5aa..cc04ce5 100644 (file)
@@ -46,10 +46,10 @@ import javax.persistence.Table;
 import org.hibernate.annotations.Type;
 import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 import org.onap.clamp.loop.log.LoopLog;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
 import org.onap.clamp.policy.operational.OperationalPolicy;
-import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 
 @Entity
 @Table(name = "loops")
@@ -57,7 +57,7 @@ import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 public class Loop implements Serializable {
 
     /**
-     *
+     * The serial version id.
      */
     private static final long serialVersionUID = -286522707701388642L;
 
@@ -78,7 +78,7 @@ public class Loop implements Serializable {
     @Column(name = "dcae_blueprint_id")
     private String dcaeBlueprintId;
 
-    @Column(name = "svg_representation")
+    @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
     private String svgRepresentation;
 
     @Expose
@@ -86,7 +86,12 @@ public class Loop implements Serializable {
     @Column(columnDefinition = "json", name = "global_properties_json")
     private JsonObject globalPropertiesJson;
 
-    @Column(nullable = false, name = "blueprint_yaml")
+    @Expose
+    @Type(type = "json")
+    @Column(columnDefinition = "json", name = "model_properties_json")
+    private JsonObject modelPropertiesJson;
+
+    @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
     private String blueprint;
 
     @Expose
@@ -100,7 +105,8 @@ public class Loop implements Serializable {
 
     @Expose
     @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
-    @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
+    @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), 
+       inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
     private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
 
     @Expose
@@ -110,6 +116,9 @@ public class Loop implements Serializable {
     public Loop() {
     }
 
+    /**
+     * Constructor.
+     */
     public Loop(String name, String blueprint, String svgRepresentation) {
         this.name = name;
         this.svgRepresentation = svgRepresentation;
@@ -130,7 +139,7 @@ public class Loop implements Serializable {
         return dcaeDeploymentId;
     }
 
-    void setDcaeDeploymentId(String dcaeDeploymentId) {
+    public void setDcaeDeploymentId(String dcaeDeploymentId) {
         this.dcaeDeploymentId = dcaeDeploymentId;
     }
 
@@ -138,7 +147,7 @@ public class Loop implements Serializable {
         return dcaeDeploymentStatusUrl;
     }
 
-    void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
+    public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
         this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
     }
 
@@ -158,11 +167,11 @@ public class Loop implements Serializable {
         this.blueprint = blueprint;
     }
 
-    LoopState getLastComputedState() {
+    public LoopState getLastComputedState() {
         return lastComputedState;
     }
 
-    void setLastComputedState(LoopState lastComputedState) {
+    public void setLastComputedState(LoopState lastComputedState) {
         this.lastComputedState = lastComputedState;
     }
 
@@ -174,7 +183,7 @@ public class Loop implements Serializable {
         this.operationalPolicies = operationalPolicies;
     }
 
-    Set<MicroServicePolicy> getMicroServicePolicies() {
+    public Set<MicroServicePolicy> getMicroServicePolicies() {
         return microServicePolicies;
     }
 
@@ -217,10 +226,33 @@ public class Loop implements Serializable {
         return dcaeBlueprintId;
     }
 
-    public void setDcaeBlueprintId(String dcaeBlueprintId) {
+    void setDcaeBlueprintId(String dcaeBlueprintId) {
         this.dcaeBlueprintId = dcaeBlueprintId;
     }
 
+    public JsonObject getModelPropertiesJson() {
+        return modelPropertiesJson;
+    }
+
+    void setModelPropertiesJson(JsonObject modelPropertiesJson) {
+        this.modelPropertiesJson = modelPropertiesJson;
+    }
+
+    /**
+     * Generate the loop name.
+     * @param serviceName The service name
+     * @param serviceVersion The service version
+     * @param resourceName The resource name
+     * @param blueprintFileName The blueprint file name
+     * @return The generated loop name
+     */
+    public static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
+        String blueprintFilename) {
+        StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion)
+            .append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", ""));
+        return buffer.toString().replace('.', '_').replaceAll(" ", "");
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -231,18 +263,23 @@ public class Loop implements Serializable {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         Loop other = (Loop) obj;
         if (name == null) {
-            if (other.name != null)
+            if (other.name != null) {
                 return false;
-        } else if (!name.equals(other.name))
+            }
+        } else if (!name.equals(other.name)) {
             return false;
+        }
         return true;
     }