summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-04-26 13:04:08 +0200
committersebdet <sebastien.determe@intl.att.com>2019-04-26 13:04:08 +0200
commit5415b26467f198856b3149c11827a93e2ed8a72a (patch)
tree71546e21f21b3a0fe1b373bf291d69e0d9caa101 /src/main/java
parent373b07b5c7f7e74cffb3a7250a691cb649856b94 (diff)
Change Yaml to Json payload
Change the operational policy payload from Yaml to a JSon, yaml being embedded as URLEncoded Issue-ID: CLAMP-359 Change-Id: I8c97bb155e6136ce37c29a65a7d9d85e21fedd61 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java4
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java16
2 files changed, 17 insertions, 3 deletions
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index f4efab0d7..fc097bd60 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -25,13 +25,15 @@ package org.onap.clamp.policy;
import com.google.gson.JsonObject;
+import java.io.UnsupportedEncodingException;
+
public interface Policy {
String getName();
JsonObject getJsonRepresentation();
- String createPolicyPayload();
+ String createPolicyPayload() throws UnsupportedEncodingException;
/**
* Generate the policy name.
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 1e35ad6c4..b2f6109f7 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -31,6 +31,9 @@ import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -150,8 +153,7 @@ public class OperationalPolicy implements Serializable, Policy {
return true;
}
- @Override
- public String createPolicyPayload() {
+ public String createPolicyPayloadYaml() {
JsonObject policyPayloadResult = new JsonObject();
policyPayloadResult.addProperty("tosca_definitions_version", "tosca_simple_yaml_1_0_0");
@@ -181,6 +183,16 @@ public class OperationalPolicy implements Serializable, Policy {
return (new Yaml()).dump(jsonMap);
}
+ @Override
+ public String createPolicyPayload() throws UnsupportedEncodingException {
+
+ // Now the Yaml payload must be injected in a json ...
+ JsonObject payload = new JsonObject();
+ payload.addProperty("policy-id", this.getName());
+ payload.addProperty("content", URLEncoder.encode(createPolicyPayloadYaml(), StandardCharsets.UTF_8.toString()));
+ return new GsonBuilder().setPrettyPrinting().create().toJson(payload);
+ }
+
/**
* Return a map containing all Guard policies indexed by Guard policy Name.
*