diff options
author | liamfallon <liam.fallon@est.tech> | 2020-02-17 00:51:13 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-02-17 00:51:16 +0000 |
commit | 170d740e8a1d74875317e86b4266b798ea8baaab (patch) | |
tree | 3903798c85e89d0200185fd90db0e987d331ed1e /models-tosca/src/main | |
parent | 2495f815aaf7ff269bf8978953c0980489b1663f (diff) |
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/main')
-rw-r--r-- | models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java | 15 |
1 files changed, 11 insertions, 4 deletions
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; } /** |