aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java
diff options
context:
space:
mode:
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());
+ }
+ }
+ }
+
}