Merge "Change vFW payload from pg-streams to streams"
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / legacy / mapping / LegacyOperationalPolicyMapper.java
index b6c5d3b..2dddda2 100644 (file)
@@ -25,6 +25,8 @@ import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
@@ -68,7 +70,14 @@ public class LegacyOperationalPolicyMapper
 
         final Map<String, String> propertyMap = new HashMap<>();
         toscaPolicy.setProperties(propertyMap);
-        toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent());
+        try {
+            toscaPolicy.getProperties().put(CONTENT_PROPERTY,
+                    new StandardCoder().encode(legacyOperationalPolicy.getContent()));
+        } catch (CoderException ce) {
+            String errorMessage = "encoding of property \"content\" to JSON failed";
+            LOGGER.warn(errorMessage, ce);
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage, ce);
+        }
 
         final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
         serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
@@ -105,9 +114,17 @@ public class LegacyOperationalPolicyMapper
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
 
-        final String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY);
-        if (toscaPolicy.getProperties() == null) {
-            String errorMessage = "property \"Content\" not defined on TOSCA policy";
+        String content = null;
+        try {
+            content = new StandardCoder().decode(toscaPolicy.getProperties().get(CONTENT_PROPERTY), String.class);
+        } catch (CoderException ce) {
+            String errorMessage = "decoding of property \"content\" from JSON failed";
+            LOGGER.warn(errorMessage, ce);
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage, ce);
+        }
+
+        if (content == null) {
+            String errorMessage = "property \"content\" not defined on TOSCA policy";
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }