Add policy model id in tosca parser
[clamp.git] / src / main / java / org / onap / clamp / policy / microservice / MicroServicePolicy.java
index 332b20a..2943c39 100644 (file)
@@ -23,6 +23,8 @@
 
 package org.onap.clamp.policy.microservice;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonArray;
@@ -40,6 +42,7 @@ import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.ManyToMany;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 import org.hibernate.annotations.Type;
 import org.hibernate.annotations.TypeDef;
@@ -61,6 +64,9 @@ public class MicroServicePolicy implements Serializable, Policy {
      */
     private static final long serialVersionUID = 6271238288583332616L;
 
+    @Transient
+    private static final EELFLogger logger = EELFManager.getInstance().getLogger(MicroServicePolicy.class);
+
     @Expose
     @Id
     @Column(nullable = false, name = "name", unique = true)
@@ -98,25 +104,20 @@ public class MicroServicePolicy implements Serializable, Policy {
      * The constructor that create the json representation from the policyTosca
      * using the ToscaYamlToJsonConvertor.
      *
-     * @param name
-     *        The name of the MicroService
-     * @param type
-     *        The model type of the MicroService
-     * @param policyTosca
-     *        The policy Tosca of the MicroService
-     * @param shared
-     *        The flag indicate whether the MicroService is shared
-     * @param usedByLoops
-     *        The list of loops that uses this MicroService
+     * @param name        The name of the MicroService
+     * @param modelType   The model type of the MicroService
+     * @param policyTosca The policy Tosca of the MicroService
+     * @param shared      The flag indicate whether the MicroService is shared
+     * @param usedByLoops The list of loops that uses this MicroService
      */
     public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared,
-        Set<Loop> usedByLoops) {
+            Set<Loop> usedByLoops) {
         this.name = name;
         this.modelType = modelType;
         this.policyTosca = policyTosca;
         this.shared = shared;
         this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
-            .fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class);
+                .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyTosca, modelType), JsonObject.class);
         this.usedByLoops = usedByLoops;
     }
 
@@ -130,21 +131,16 @@ public class MicroServicePolicy implements Serializable, Policy {
      * The constructor that does not make use of ToscaYamlToJsonConvertor but take
      * the jsonRepresentation instead.
      *
-     * @param name
-     *        The name of the MicroService
-     * @param type
-     *        The model type of the MicroService
-     * @param policyTosca
-     *        The policy Tosca of the MicroService
-     * @param shared
-     *        The flag indicate whether the MicroService is shared
-     * @param jsonRepresentation
-     *        The UI representation in json format
-     * @param usedByLoops
-     *        The list of loops that uses this MicroService
+     * @param name               The name of the MicroService
+     * @param modelType          The model type of the MicroService
+     * @param policyTosca        The policy Tosca of the MicroService
+     * @param shared             The flag indicate whether the MicroService is
+     *                           shared
+     * @param jsonRepresentation The UI representation in json format
+     * @param usedByLoops        The list of loops that uses this MicroService
      */
     public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared,
-        JsonObject jsonRepresentation, Set<Loop> usedByLoops) {
+            JsonObject jsonRepresentation, Set<Loop> usedByLoops) {
         this.name = name;
         this.modelType = modelType;
         this.policyTosca = policyTosca;
@@ -239,7 +235,7 @@ public class MicroServicePolicy implements Serializable, Policy {
 
     private String getMicroServicePropertyNameFromTosca(JsonObject object) {
         return object.getAsJsonObject("policy_types").getAsJsonObject(this.modelType).getAsJsonObject("properties")
-            .keySet().toArray(new String[1])[0];
+                .keySet().toArray(new String[1])[0];
     }
 
     @Override
@@ -271,7 +267,9 @@ public class MicroServicePolicy implements Serializable, Policy {
         JsonObject policyProperties = new JsonObject();
         policyDetails.add("properties", policyProperties);
         policyProperties.add(this.getMicroServicePropertyNameFromTosca(toscaJson), this.getProperties());
-        return new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult);
+        String policyPayload = new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult);
+        logger.info("Micro service policy payload: " + policyPayload);
+        return policyPayload;
     }
 
 }