From 52567cb059f90bb3114c4d4db3c758dd98b7b18b Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 10 Apr 2019 17:01:22 +0000 Subject: Add policy ID and version to metadata Adds the policy-id and policy-version of the policy to the policy metadata, duplicating the policy key in therre. Issue-ID: POLICY-1095 Change-Id: I49603766141f5dee47573edc9f05d2ee2cf9da52 Signed-off-by: liamfallon --- .../policy/models/tosca/simple/concepts/JpaToscaPolicy.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 3bc472243..7655eb96a 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -69,6 +69,10 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; public class JpaToscaPolicy extends JpaToscaEntityType implements PfAuthorative { private static final long serialVersionUID = 3265174757061982805L; + // Tags for metadata + private static final String METADATA_POLICY_ID_TAG = "policy-id"; + private static final String METADATA_POLICY_VERSION_TAG = "policy-version"; + // @formatter:off @Column @AttributeOverrides({ @@ -184,6 +188,15 @@ public class JpaToscaPolicy extends JpaToscaEntityType implements P properties.put(propertyEntry.getKey(), propertyEntry.getValue().toString()); } } + + // Add the property metadata if it doesn't exist already + if (toscaPolicy.getMetadata() == null) { + toscaPolicy.setMetadata(new LinkedHashMap<>()); + } + + // Add the policy name and version fields to the metadata + toscaPolicy.getMetadata().put(METADATA_POLICY_ID_TAG, getKey().getName()); + toscaPolicy.getMetadata().put(METADATA_POLICY_VERSION_TAG, Integer.toString(getKey().getMajorVersion())); } @Override -- cgit 1.2.3-korg