Merge "Rework tosca converter"
[clamp.git] / src / main / java / org / onap / clamp / policy / operational / OperationalPolicy.java
index 82cfcf4..9cf5163 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights
  *                             reserved.
+ * Modifications Copyright (C) 2020 Huawei Technologies Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,14 +45,12 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 import javax.persistence.Transient;
 import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs;
-import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
-import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.tosca.update.UnknownComponentException;
 import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
 import org.onap.clamp.loop.Loop;
 import org.onap.clamp.loop.template.LoopElementModel;
@@ -119,17 +118,15 @@ public class OperationalPolicy extends Policy implements Serializable {
             if (isLegacy()) {
                 // Op policy Legacy case
                 LegacyOperationalPolicy.preloadConfiguration(jsonReturned, loop);
-                this.setJsonRepresentation(
-                        OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
+                jsonReturned =
+                        OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService());
             } else {
                 // Generic Case
-                this.setJsonRepresentation(JsonUtils.GSON
-                        .fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyModel.getPolicyModelTosca(),
-                                policyModel.getPolicyModelType()), JsonObject.class));
+                jsonReturned = Policy.generateJsonRepresentationFromToscaModel(policyModel.getPolicyModelTosca(),
+                        policyModel.getPolicyModelType());
             }
-        } catch (JsonSyntaxException | IOException | NullPointerException e) {
+        } catch (UnknownComponentException | IOException | NullPointerException e) {
             logger.error("Unable to generate the operational policy Schema ... ", e);
-            this.setJsonRepresentation(new JsonObject());
         }
         return jsonReturned;
     }
@@ -220,7 +217,7 @@ public class OperationalPolicy extends Policy implements Serializable {
         metadata.addProperty("policy-id", this.name);
 
         operationalPolicyDetails.add("properties", LegacyOperationalPolicy
-                .reworkPayloadAttributes(this.getConfigurationsJson().get("operational_policy").deepCopy()));
+                .reworkActorAttributes(this.getConfigurationsJson().get("operational_policy").deepCopy()));
 
         DumperOptions options = new DumperOptions();
         options.setIndent(2);