summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-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.
*