diff options
author | Rashmi Pujar <rashmi.pujar@bell.ca> | 2019-11-25 12:56:24 -0500 |
---|---|---|
committer | Rashmi Pujar <rashmi.pujar@bell.ca> | 2019-11-26 13:27:37 -0500 |
commit | 281f653d38161409b553ff01b30f80a6903827b5 (patch) | |
tree | 11b17c1add60dd00089f9e2cb5a74128967b310a /models-interactions/model-actors/actor.cds/src/main | |
parent | 0ca7816c5f88288ed72f7b69f0813c8da3b63ebe (diff) |
CDS actor payload to be JSON object when applicable
When the policy-payload supplied by CLAMP is a valid JSON string
the CDS Blueprint payload must be a JSON object, else retain the
CDS Blueprint payload to be a string.
Issue-ID: POLICY-2253
Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca>
Change-Id: I6380ab0424339603ecf52d298e4f6f0cd8df754b
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/main')
2 files changed, 17 insertions, 4 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java index 8f929c83e..0dc5bfb34 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/constants/CdsActorConstants.java @@ -32,6 +32,7 @@ public class CdsActorConstants { // CDS blueprint archive parameters public static final String KEY_CBA_NAME = "artifact_name"; public static final String KEY_CBA_VERSION = "artifact_version"; + public static final String KEY_POLICY_PAYLOAD_DATA = "data"; public static final String KEY_RESOLUTION_KEY = "resolution-key"; public static final String CDS_REQUEST_SUFFIX = "-request"; public static final String CDS_REQUEST_PROPERTIES_SUFFIX = "-properties"; diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java index 4193db59f..e362fe874 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/request/CdsActionRequest.java @@ -57,14 +57,26 @@ public class CdsActionRequest implements Serializable { * @throws CoderException if error occurs when serializing to JSON string */ public String generateCdsPayload() throws CoderException { - // 1. Build the innermost object to include AAI properties and policy payload information - Map<String, String> cdsActionPropsMap = new LinkedHashMap<>(); - cdsActionPropsMap.putAll(aaiProperties); - cdsActionPropsMap.putAll(policyPayload); + // 1a. Build the innermost object to include AAI properties + Map<String, Object> cdsActionPropsMap = new LinkedHashMap<>(aaiProperties); if (additionalEventParams != null) { cdsActionPropsMap.putAll(additionalEventParams); } + // 1b. Build the innermost object to include policy payload. + // If the policy payload data is a valid JSON string convert to an object else retain as a string. + if (policyPayload != null && !policyPayload.isEmpty()) { + String payload = policyPayload.get(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA); + try { + Object payloadObj = CODER.decode(payload, Object.class); + cdsActionPropsMap.put(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, payloadObj); + } catch (CoderException e) { + cdsActionPropsMap.put(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, payload); + } + } else { + cdsActionPropsMap.put(CdsActorConstants.KEY_POLICY_PAYLOAD_DATA, ""); + } + // 2. Build the enclosing CDS action request properties object to contain (1) and the resolution-key Map<String, Object> cdsActionRequestMap = new LinkedHashMap<>(); cdsActionRequestMap.put(CdsActorConstants.KEY_RESOLUTION_KEY, resolutionKey); |