aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-05-02 16:53:57 +0000
committerliamfallon <liam.fallon@est.tech>2019-05-02 16:53:57 +0000
commit41ce3cd080630e0206478c34d39eac1e4d1fc09d (patch)
treee6a9c32918f9681ccdeadb2c805624ed3f8b107a /models-tosca/src/main
parentf469cc7dd370df6d3f25db79a62d47b1ae01b2c9 (diff)
Fix bug in guard policy metadata creation
Issue-ID: POLICY-1728 Change-Id: Ie33a30a811fcd8c128dfac87c17dcb37da6d42b4 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/main')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java28
1 files changed, 25 insertions, 3 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
index 85b5e6df8..01bd83d86 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
@@ -22,6 +22,7 @@ package org.onap.policy.models.tosca.legacy.mapping;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
import javax.ws.rs.core.Response;
@@ -46,6 +47,11 @@ import org.slf4j.LoggerFactory;
*/
public class LegacyGuardPolicyMapper
implements JpaToscaServiceTemplateMapper<LegacyGuardPolicyInput, Map<String, LegacyGuardPolicyOutput>> {
+
+ // Tag for metadata fields
+ private static final String POLICY_ID = "policy-id";
+ private static final String POLICY_VERSION = "policy-version";
+
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyGuardPolicyMapper.class);
private static final Map<String, PfConceptKey> GUARD_POLICY_TYPE_MAP = new LinkedHashMap<>();
@@ -84,8 +90,13 @@ public class LegacyGuardPolicyMapper
toscaPolicy.setType(guardPolicyType);
toscaPolicy.setProperties(legacyGuardPolicyInput.getContent().getAsPropertyMap());
+ final Map<String, String> metadata = new LinkedHashMap<>();
+ metadata.put(POLICY_ID, toscaPolicy.getKey().getName());
+ metadata.put(POLICY_VERSION, Integer.toString(toscaPolicy.getKey().getMajorVersion()));
+ toscaPolicy.setMetadata(metadata);
+
final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
- serviceTemplate.setToscaDefinitionsVersion("tosca_simimport java.util.HashMap;\n" + "ple_yaml_1_0");
+ serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
@@ -109,9 +120,20 @@ public class LegacyGuardPolicyMapper
legacyGuardPolicyOutput.setType(toscaPolicy.getType().getName());
legacyGuardPolicyOutput.setVersion(toscaPolicy.getType().getVersion());
+ if (toscaPolicy.getMetadata() == null) {
+ String errorMessage = "no metadata defined on TOSCA policy";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+
final Map<String, Object> metadata = new LinkedHashMap<>();
- metadata.put("policy-id", toscaPolicy.getKey().getName());
- metadata.put("policy-version", toscaPolicy.getKey().getMajorVersion());
+ for (Entry<String, String> metadataEntry : toscaPolicy.getMetadata().entrySet()) {
+ if (POLICY_VERSION.equals(metadataEntry.getKey())) {
+ metadata.put(POLICY_VERSION, Integer.parseInt(metadataEntry.getValue()));
+ } else {
+ metadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+ }
+ }
legacyGuardPolicyOutput.setMetadata(metadata);
if (toscaPolicy.getProperties() == null) {