Fix the new tosca converter
[clamp.git] / src / main / java / org / onap / clamp / loop / service / Service.java
index ac1216b..338032a 100644 (file)
@@ -27,24 +27,21 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.google.gson.JsonObject;
 import com.google.gson.annotations.Expose;
-
 import java.io.Serializable;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 import javax.persistence.Transient;
-
 import org.hibernate.annotations.Type;
 import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs;
+import org.onap.clamp.clds.util.JsonUtils;
 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 
-
 @Entity
 @Table(name = "services")
-@TypeDefs({ @TypeDef(name = "json", typeClass = StringJsonUserType.class) })
+@TypeDefs({@TypeDef(name = "json", typeClass = StringJsonUserType.class)})
 public class Service implements Serializable {
 
     /**
@@ -62,6 +59,9 @@ public class Service implements Serializable {
     @Column(nullable = false, name = "name")
     private String name;
 
+    @Column(name = "version")
+    private String version;
+
     @Expose
     @Type(type = "json")
     @Column(columnDefinition = "json", name = "service_details")
@@ -73,19 +73,31 @@ public class Service implements Serializable {
     private JsonObject resourceDetails;
 
     /**
-     * Public constructor.
+     * Default constructor for serialization.
      */
     public Service() {
     }
 
     /**
-     * Constructor.
+     * Constructor with string.
+     */
+    public Service(String serviceDetails, String resourceDetails) {
+        JsonObject serviceDetailsJson = JsonUtils.GSON.fromJson(serviceDetails, JsonObject.class);
+        this.name = serviceDetailsJson.get("name").getAsString();
+        this.serviceUuid = serviceDetailsJson.get("UUID").getAsString();
+        this.serviceDetails = serviceDetailsJson;
+        this.resourceDetails = JsonUtils.GSON.fromJson(resourceDetails, JsonObject.class);
+    }
+
+    /**
+     * Constructor with Json Object.
      */
-    public Service(JsonObject serviceDetails, JsonObject resourceDetails) {
+    public Service(JsonObject serviceDetails, JsonObject resourceDetails, String version) {
         this.name = serviceDetails.get("name").getAsString();
         this.serviceUuid = serviceDetails.get("UUID").getAsString();
         this.serviceDetails = serviceDetails;
         this.resourceDetails = resourceDetails;
+        this.version = version;
     }
 
     public String getServiceUuid() {
@@ -104,6 +116,24 @@ public class Service implements Serializable {
         return (JsonObject) resourceDetails.get(type);
     }
 
+    /**
+     * Name getter.
+     *
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Version getter.
+     *
+     * @return the version
+     */
+    public String getVersion() {
+        return version;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -128,7 +158,8 @@ public class Service implements Serializable {
             if (other.serviceUuid != null) {
                 return false;
             }
-        } else if (!serviceUuid.equals(other.serviceUuid)) {
+        }
+        else if (!serviceUuid.equals(other.serviceUuid)) {
             return false;
         }
         return true;