From 94a863e0a9b5f65b804cf26936c67ee815e49850 Mon Sep 17 00:00:00 2001 From: Chenfei Gao Date: Fri, 7 Jun 2019 11:14:16 -0400 Subject: Fix version field to represent policy version instead of type version Added changes to make version field in return of GET guard policy call represent the version of guard policy instead of its type version. Issue-ID: POLICY-1809 Change-Id: Ie8db6e89d8439576ee5f6ee99c3222386775b195 Signed-off-by: Chenfei Gao --- .../tosca/legacy/mapping/LegacyGuardPolicyMapper.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'models-tosca/src/main') 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 1c414ee17..a664010b8 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 @@ -115,7 +115,7 @@ public class LegacyGuardPolicyMapper final LegacyGuardPolicyOutput legacyGuardPolicyOutput = new LegacyGuardPolicyOutput(); legacyGuardPolicyOutput.setType(toscaPolicy.getType().getName()); - legacyGuardPolicyOutput.setVersion(toscaPolicy.getType().getVersion()); + legacyGuardPolicyOutput.setVersion(toscaPolicy.getKey().getVersion()); if (toscaPolicy.getMetadata() == null) { String errorMessage = "no metadata defined on TOSCA policy"; @@ -123,14 +123,11 @@ public class LegacyGuardPolicyMapper throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } - final Map metadata = new LinkedHashMap<>(); - for (Entry 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()); - } - } + final Map metadata = new LinkedHashMap<>(toscaPolicy.getMetadata()); + + // if version exists, convert it to int + metadata.computeIfPresent(POLICY_VERSION, (key,val) -> Integer.parseInt(val.toString())); + legacyGuardPolicyOutput.setMetadata(metadata); if (toscaPolicy.getProperties() == null) { -- cgit 1.2.3-korg