Policy JSON formatting issues in APEX 88/89888/1
authora.sreekumar <ajith.sreekumar@est.tech>
Fri, 14 Jun 2019 13:07:14 +0000 (13:07 +0000)
committera.sreekumar <ajith.sreekumar@est.tech>
Fri, 14 Jun 2019 13:07:14 +0000 (13:07 +0000)
In APEX, the policy model currently needs to be escaped, otherwise
causes json formatting issues. This is fixed.

Change-Id: If9d5043acef0b175494be797fc7acd9c6c4f4494
Issue-ID: POLICY-1839
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java

index 1c94130..8cb3ae1 100644 (file)
@@ -52,19 +52,19 @@ public class ApexEngineHandler {
      * @param properties the properties which contains the policies and configurations received from pap
      * @throws ApexStarterException if the apex engine instantiation failed using the properties passed
      */
-
     public ApexEngineHandler(final Object properties) throws ApexStarterException {
         final StandardCoder standardCoder = new StandardCoder();
-        JsonObject body;
+        String policyModel;
+        String apexConfig;
         try {
-            body = standardCoder.decode(new StringReader(properties.toString()), JsonObject.class);
+            JsonObject body = standardCoder.decode(standardCoder.encode(properties), JsonObject.class);
+            final JsonObject engineServiceParameters = body.get("engineServiceParameters").getAsJsonObject();
+            policyModel = standardCoder.encode(engineServiceParameters.get("policy_type_impl"));
+            engineServiceParameters.remove("policy_type_impl");
+            apexConfig = standardCoder.encode(body);
         } catch (final CoderException e) {
             throw new ApexStarterException(e);
         }
-        final JsonObject engineServiceParameters = body.get("engineServiceParameters").getAsJsonObject();
-        final String policyModel = engineServiceParameters.get("policy_type_impl").toString();
-        engineServiceParameters.remove("policy_type_impl");
-        final String apexConfig = body.toString();
 
         final String modelFilePath = createFile(policyModel, "modelFile");