Create SVG in UI
[clamp.git] / src / main / java / org / onap / clamp / loop / template / LoopTemplate.java
index 3e90c1e..6f896f3 100644 (file)
 package org.onap.clamp.loop.template;
 
 import com.google.gson.annotations.Expose;
-
 import java.io.Serializable;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
-
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
@@ -39,7 +38,6 @@ import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToMany;
 import javax.persistence.Table;
-
 import org.hibernate.annotations.SortNatural;
 import org.onap.clamp.loop.common.AuditEntity;
 import org.onap.clamp.loop.service.Service;
@@ -70,16 +68,19 @@ public class LoopTemplate extends AuditEntity implements Serializable {
     @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
     private String blueprint;
 
-    @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
-    private String svgRepresentation;
-
     @Expose
-    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loopTemplate", orphanRemoval = true)
+    @OneToMany(
+            cascade = CascadeType.ALL,
+            fetch = FetchType.EAGER,
+            mappedBy = "loopTemplate",
+            orphanRemoval = true)
     @SortNatural
     private SortedSet<LoopTemplateLoopElementModel> loopElementModelsUsed = new TreeSet<>();
 
     @Expose
-    @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
+    @ManyToOne(
+            fetch = FetchType.EAGER,
+            cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
     @JoinColumn(name = "service_uuid")
     private Service modelService;
 
@@ -91,9 +92,17 @@ public class LoopTemplate extends AuditEntity implements Serializable {
     @Column(name = "unique_blueprint", columnDefinition = "boolean default false")
     private boolean uniqueBlueprint;
 
+    /**
+     * Type of Loop allowed to be created.
+     */
+    @Expose
+    @Column(name = "allowed_loop_type")
+    @Convert(converter = LoopTypeConvertor.class)
+    private LoopType allowedLoopType = LoopType.CLOSED;
+
     /**
      * name getter.
-     * 
+     *
      * @return the name
      */
     public String getName() {
@@ -102,7 +111,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * name setter.
-     * 
+     *
      * @param name the name to set
      */
     public void setName(String name) {
@@ -111,7 +120,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * blueprint getter.
-     * 
+     *
      * @return the blueprint
      */
     public String getBlueprint() {
@@ -120,7 +129,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * dcaeBlueprintId getter.
-     * 
+     *
      * @return the dcaeBlueprintId
      */
     public String getDcaeBlueprintId() {
@@ -129,7 +138,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * dcaeBlueprintId setter.
-     * 
+     *
      * @param dcaeBlueprintId the dcaeBlueprintId to set
      */
     public void setDcaeBlueprintId(String dcaeBlueprintId) {
@@ -138,7 +147,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * blueprint setter.
-     * 
+     *
      * @param blueprint the blueprint to set
      */
     public void setBlueprint(String blueprint) {
@@ -150,27 +159,9 @@ public class LoopTemplate extends AuditEntity implements Serializable {
         }
     }
 
-    /**
-     * svgRepresentation getter.
-     * 
-     * @return the svgRepresentation
-     */
-    public String getSvgRepresentation() {
-        return svgRepresentation;
-    }
-
-    /**
-     * svgRepresentation setter.
-     * 
-     * @param svgRepresentation the svgRepresentation to set
-     */
-    public void setSvgRepresentation(String svgRepresentation) {
-        this.svgRepresentation = svgRepresentation;
-    }
-
     /**
      * loopElementModelsUsed getter.
-     * 
+     *
      * @return the loopElementModelsUsed
      */
     public SortedSet<LoopTemplateLoopElementModel> getLoopElementModelsUsed() {
@@ -179,7 +170,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * maximumInstancesAllowed getter.
-     * 
+     *
      * @return the maximumInstancesAllowed
      */
     public Integer getMaximumInstancesAllowed() {
@@ -188,17 +179,35 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * maximumInstancesAllowed setter.
-     * 
+     *
      * @param maximumInstancesAllowed the maximumInstancesAllowed to set
      */
     public void setMaximumInstancesAllowed(Integer maximumInstancesAllowed) {
         this.maximumInstancesAllowed = maximumInstancesAllowed;
     }
 
+    /**
+     * allowedLoopType getter.
+     *
+     * @return the allowedLoopType Type of Loop allowed to be created
+     */
+    public LoopType getAllowedLoopType() {
+        return allowedLoopType;
+    }
+
+    /**
+     * allowedLoopType setter.
+     *
+     * @param allowedLoopType the allowedLoopType to set
+     */
+    public void setAllowedLoopType(LoopType allowedLoopType) {
+        this.allowedLoopType = allowedLoopType;
+    }
+
     /**
      * Add list of loopElements to the current template, each loopElementModel is
      * added at the end of the list so the flowOrder is computed automatically.
-     * 
+     *
      * @param loopElementModels The loopElementModel set to add
      */
     public void addLoopElementModels(Set<LoopElementModel> loopElementModels) {
@@ -210,33 +219,30 @@ public class LoopTemplate extends AuditEntity implements Serializable {
     /**
      * Add a loopElement to the current template, the loopElementModel is added at
      * the end of the list so the flowOrder is computed automatically.
-     * 
+     *
      * @param loopElementModel The loopElementModel to add
      */
     public void addLoopElementModel(LoopElementModel loopElementModel) {
-        LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
-                this.loopElementModelsUsed.size());
-        this.loopElementModelsUsed.add(jointEntry);
-        loopElementModel.getUsedByLoopTemplates().add(jointEntry);
+        this.addLoopElementModel(loopElementModel,this.loopElementModelsUsed.size());
     }
 
     /**
      * Add a loopElement model to the current template, the flow order must be
      * specified manually.
-     * 
+     *
      * @param loopElementModel The loopElementModel to add
      * @param listPosition     The position in the flow
      */
     public void addLoopElementModel(LoopElementModel loopElementModel, Integer listPosition) {
-        LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
-                listPosition);
+        LoopTemplateLoopElementModel jointEntry =
+                new LoopTemplateLoopElementModel(this, loopElementModel, listPosition);
         this.loopElementModelsUsed.add(jointEntry);
         loopElementModel.getUsedByLoopTemplates().add(jointEntry);
     }
 
     /**
      * modelService getter.
-     * 
+     *
      * @return the modelService
      */
     public Service getModelService() {
@@ -245,7 +251,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * modelService setter.
-     * 
+     *
      * @param modelService the modelService to set
      */
     public void setModelService(Service modelService) {
@@ -254,7 +260,7 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * uniqueBlueprint getter.
-     * 
+     *
      * @return the uniqueBlueprint
      */
     public boolean getUniqueBlueprint() {
@@ -270,20 +276,17 @@ public class LoopTemplate extends AuditEntity implements Serializable {
 
     /**
      * Constructor.
-     * 
+     *
      * @param name                The loop template name id
      * @param blueprint           The blueprint containing all microservices (legacy
      *                            case)
-     * @param svgRepresentation   The svg representation of that loop template
      * @param maxInstancesAllowed The maximum number of instances that can be
      *                            created from that template
      * @param service             The service associated to that loop template
      */
-    public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed,
-            Service service) {
+    public LoopTemplate(String name, String blueprint, Integer maxInstancesAllowed, Service service) {
         this.name = name;
         this.setBlueprint(blueprint);
-        this.svgRepresentation = svgRepresentation;
 
         this.maximumInstancesAllowed = maxInstancesAllowed;
         this.modelService = service;
@@ -328,8 +331,8 @@ public class LoopTemplate extends AuditEntity implements Serializable {
      * @param blueprintFileName The blueprint file name
      * @return The generated loop template name
      */
-    public static String generateLoopTemplateName(String serviceName, String serviceVersion, String resourceName,
-            String blueprintFileName) {
+    public static String generateLoopTemplateName(String serviceName, String serviceVersion,
+                                                  String resourceName, String blueprintFileName) {
         StringBuilder buffer = new StringBuilder("LOOP_TEMPLATE_").append(serviceName).append("_v")
                 .append(serviceVersion).append("_").append(resourceName).append("_")
                 .append(blueprintFileName.replaceAll(".yaml", ""));