aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-18 17:27:13 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-23 16:11:33 +0000
commitaba3f2a1c64d755bfed2f278d40a74f9a4f9ab1e (patch)
treedc1f5bc7ee0ae1541aeb3aa990c7cc5f6b8653e3 /main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
parentbeef773a297cbeb5c5abfb5e75e678e39d3d1523 (diff)
Add support for populating metadataSet in PAP tosca policy
MetadataSet fetched from the db and added to the policy metadata map with the key "metadataSet" before sending to PDPs Issue-ID: POLICY-3832 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I14064d82ba6877bd7560af7de7572b4813a98385
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java b/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
index e71045f6..ef0fc603 100644
--- a/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
+++ b/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +33,7 @@ import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
@@ -51,8 +53,14 @@ public class ToscaServiceTemplateService {
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateService.class);
+ private static final String METADATASET_NAME = "metadataSetName";
+ private static final String METADATASET_VERSION = "metadataSetVersion";
+ private static final String METADATASET = "metadataSet";
+
private final ToscaServiceTemplateRepository serviceTemplateRepository;
+ private final ToscaNodeTemplateService nodeTemplateService;
+
/**
* Get policies.
*
@@ -71,6 +79,7 @@ public class ToscaServiceTemplateService {
List<Map<String, ToscaPolicy>> policies = getToscaServiceTemplate(name, version, "policy").toAuthorative()
.getToscaTopologyTemplate().getPolicies();
policyList = policies.stream().flatMap(policy -> policy.values().stream()).collect(Collectors.toList());
+ populateMetadataSet(policyList);
} catch (PfModelRuntimeException pfme) {
return handlePfModelRuntimeException(pfme);
} catch (Exception exc) {
@@ -186,4 +195,20 @@ public class ToscaServiceTemplateService {
}
}
+ /**
+ * Populates metadataSet in policy->metadata if metadataSet reference is provided.
+ *
+ * @param policies List of policies
+ */
+ private void populateMetadataSet(List<ToscaPolicy> policies) {
+ for (ToscaPolicy policy : policies) {
+ if (policy.getMetadata().keySet().containsAll(List.of(METADATASET_NAME, METADATASET_VERSION))) {
+ var name = String.valueOf(policy.getMetadata().get(METADATASET_NAME));
+ var version = String.valueOf(policy.getMetadata().get(METADATASET_VERSION));
+ policy.getMetadata().putIfAbsent(METADATASET,
+ nodeTemplateService.getToscaNodeTemplate(name, version).getMetadata());
+ }
+ }
+ }
+
}