From 170d740e8a1d74875317e86b4266b798ea8baaab Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 17 Feb 2020 00:51:13 +0000 Subject: Fix return building on policy get The service template that is being returned for the "get" has to be built up in the correct order. A policy and the policy types and data types it is referencing must be added together. Before, all the policies were added at once and then the policy types and data types for the policies were added afterwards. This means that if the service template is validated during the service template build, validation may fail, depending on the order of building of the template. Issue-ID: POLICY-1402 Change-Id: Ia4fb9ee3819dccfc8c346c682545b2d27ebc4058 Signed-off-by: liamfallon --- .../models/tosca/simple/provider/SimpleToscaProvider.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'models-tosca/src/main/java/org/onap') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index d19dbf9aa..c537bbcb5 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -377,7 +377,9 @@ public class SimpleToscaProvider { throws PfModelException { LOGGER.debug("->getPolicies: name={}, version={}", name, version); - JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao); + JpaToscaServiceTemplate dbServiceTemplate = getServiceTemplate(dao); + + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(dbServiceTemplate); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); @@ -393,15 +395,20 @@ public class SimpleToscaProvider { "policies for " + name + ":" + version + DO_NOT_EXIST); } + JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate); + returnServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); + for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) { JpaToscaServiceTemplate referencedEntitiesServiceTemplate = getPolicyTypes(dao, policy.getType().getName(), policy.getType().getVersion()); - serviceTemplate = ToscaServiceTemplateUtils.addFragment(serviceTemplate, referencedEntitiesServiceTemplate); + returnServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy); + returnServiceTemplate = + ToscaServiceTemplateUtils.addFragment(returnServiceTemplate, referencedEntitiesServiceTemplate); } - LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate); - return serviceTemplate; + LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, returnServiceTemplate); + return returnServiceTemplate; } /** -- cgit 1.2.3-korg