Add fields on microservice
[clamp.git] / src / main / java / org / onap / clamp / loop / Loop.java
index ef70ba8..3837830 100644 (file)
@@ -26,10 +26,8 @@ package org.onap.clamp.loop;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 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.util.HashMap;
 import java.util.HashSet;
@@ -58,19 +56,20 @@ 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.common.AuditEntity;
 import org.onap.clamp.loop.components.external.DcaeComponent;
 import org.onap.clamp.loop.components.external.ExternalComponent;
 import org.onap.clamp.loop.components.external.PolicyComponent;
 import org.onap.clamp.loop.log.LoopLog;
 import org.onap.clamp.loop.service.Service;
+import org.onap.clamp.loop.template.LoopTemplate;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
 import org.onap.clamp.policy.operational.OperationalPolicy;
-import org.onap.clamp.policy.operational.OperationalPolicyRepresentationBuilder;
 
 @Entity
 @Table(name = "loops")
 @TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
-public class Loop implements Serializable {
+public class Loop extends AuditEntity implements Serializable {
 
     /**
      * The serial version id.
@@ -100,18 +99,13 @@ public class Loop implements Serializable {
     @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
     private String svgRepresentation;
 
-    @Expose
-    @Type(type = "json")
-    @Column(columnDefinition = "json", name = "operational_policy_schema")
-    private JsonObject operationalPolicySchema;
-
     @Expose
     @Type(type = "json")
     @Column(columnDefinition = "json", name = "global_properties_json")
     private JsonObject globalPropertiesJson;
 
     @Expose
-    @ManyToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
+    @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
     @JoinColumn(name = "service_uuid")
     private Service modelService;
 
@@ -128,19 +122,25 @@ public class Loop implements Serializable {
     private final Map<String, ExternalComponent> components = new HashMap<>();
 
     @Expose
-    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop", orphanRemoval = true)
     private Set<OperationalPolicy> operationalPolicies = new HashSet<>();
 
     @Expose
-    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
-    @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
+    @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
+    @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"),
+            inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
     private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
 
     @Expose
-    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop")
+    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loop", orphanRemoval = true)
     @SortNatural
     private SortedSet<LoopLog> loopLogs = new TreeSet<>();
 
+    @Expose
+    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER)
+    @JoinColumn(name = "loop_template_name")
+    private LoopTemplate loopTemplate;
+
     private void initializeExternalComponents() {
         this.addComponent(new PolicyComponent());
         this.addComponent(new DcaeComponent());
@@ -274,13 +274,6 @@ public class Loop implements Serializable {
 
     void setModelService(Service modelService) {
         this.modelService = modelService;
-        try {
-            this.operationalPolicySchema = OperationalPolicyRepresentationBuilder
-                    .generateOperationalPolicySchema(this.getModelService());
-        } catch (JsonSyntaxException | IOException | NullPointerException e) {
-            logger.error("Unable to generate the operational policy Schema ... ", e);
-            this.operationalPolicySchema = new JsonObject();
-        }
     }
 
     public Map<String, ExternalComponent> getComponents() {
@@ -295,6 +288,14 @@ public class Loop implements Serializable {
         this.components.put(component.getComponentName(), component);
     }
 
+    public LoopTemplate getLoopTemplate() {
+        return loopTemplate;
+    }
+
+    public void setLoopTemplate(LoopTemplate loopTemplate) {
+        this.loopTemplate = loopTemplate;
+    }
+
     /**
      * Generate the loop name.
      *