summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-09-05 21:10:46 +0000
committerliamfallon <liam.fallon@est.tech>2019-09-05 21:10:46 +0000
commitb0e460abe43d40528da4856f2f3d5ee162ac1830 (patch)
tree6cbacdbe977abab77e2b65d9e62d650d1433c21e /models-tosca/src/main
parentff4c8525a70ef5b514d803b5093b91e45564f973 (diff)
Repair policy types in TOSCA service template
Changed policy types from a list of maps to a map. Changed data types from a list of maps to a map. Made all knock on changes to adapters and tests. Updated Issue ID. Added onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml policy type that is required to be preloaded in policy-api. Issue-ID: POLICY-2047 Change-Id: Ic8e809eab248fd7242f0e565fa2e3da75bcfbdeb 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/authorative/concepts/ToscaEntity.java24
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java9
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java29
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java23
4 files changed, 70 insertions, 15 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
index c0f40f159..0a8fa2788 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
@@ -111,4 +111,28 @@ public class ToscaEntity implements PfNameVersion {
return entityMap;
}
+
+ /**
+ * Convert a map of TOSCA entities into a regular map.
+ *
+ * @param mapOfEntities the incoming list of maps of entities
+ * @return The entities on a regular map
+ * @throws PfModelException on duplicate entity entries
+ */
+ public static <T extends ToscaEntity> Map<ToscaEntityKey, T> getEntityMapAsMap(Map<String, T> mapOfEntities) {
+ // Declare the return map
+ Map<ToscaEntityKey, T> entityMap = new LinkedHashMap<>();
+
+ for (T entityEntry : mapOfEntities.values()) {
+ if (entityMap.containsKey(entityEntry.getKey())) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "list of map of entities contains more than one entity with key " + entityEntry.getKey());
+ }
+
+ entityMap.put(entityEntry.getKey(), entityEntry);
+ }
+
+ return entityMap;
+ }
+
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java
index 21b15a8ae..17391964e 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java
@@ -25,7 +25,6 @@ package org.onap.policy.models.tosca.authorative.concepts;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
-import java.util.List;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -49,17 +48,17 @@ public class ToscaServiceTemplate extends ToscaEntity {
@ApiModelProperty(name = "policy_types")
@SerializedName("policy_types")
- private List<Map<String, ToscaPolicyType>> policyTypes;
+ private Map<String, ToscaPolicyType> policyTypes;
@ApiModelProperty(name = "data_types")
@SerializedName("data_types")
- private List<Map<String, ToscaDataType>> dataTypes;
+ private Map<String, ToscaDataType> dataTypes;
public Map<ToscaEntityKey, ToscaPolicyType> getPolicyTypesAsMap() {
- return ToscaEntity.getEntityListMapAsMap(policyTypes);
+ return ToscaEntity.getEntityMapAsMap(policyTypes);
}
public Map<ToscaEntityKey, ToscaDataType> getDataTypesAsMap() {
- return ToscaEntity.getEntityListMapAsMap(dataTypes);
+ return ToscaEntity.getEntityMapAsMap(dataTypes);
}
} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
index e41281d7f..8c6e492f7 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
@@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
+
import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
@@ -83,8 +85,8 @@ public class AuthorativeToscaProvider {
LOGGER.debug("->getPolicyTypeList: name={}, version={}", name, version);
- List<ToscaPolicyType> policyTypeList = asConceptList(
- new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative().getPolicyTypes());
+ List<ToscaPolicyType> policyTypeList = new ArrayList<>(
+ new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative().getPolicyTypes().values());
LOGGER.debug("<-getPolicyTypeList: name={}, version={}, policyTypeList={}", name, version, policyTypeList);
return policyTypeList;
@@ -106,7 +108,7 @@ public class AuthorativeToscaProvider {
ToscaServiceTemplate serviceTemplate =
new SimpleToscaProvider().getPolicyTypes(dao, null, null).toAuthorative();
- List<ToscaPolicyType> filteredPolicyTypes = asConceptList(serviceTemplate.getPolicyTypes());
+ List<ToscaPolicyType> filteredPolicyTypes = new ArrayList<>(serviceTemplate.getPolicyTypes().values());
filteredPolicyTypes = filter.filter(filteredPolicyTypes);
serviceTemplate.setPolicyTypes(asConceptMap(filteredPolicyTypes));
@@ -257,7 +259,7 @@ public class AuthorativeToscaProvider {
List<ToscaPolicy> filteredPolicies = asConceptList(serviceTemplate.getToscaTopologyTemplate().getPolicies());
filteredPolicies = filter.filter(filteredPolicies);
- serviceTemplate.getToscaTopologyTemplate().setPolicies(asConceptMap(filteredPolicies));
+ serviceTemplate.getToscaTopologyTemplate().setPolicies(asConceptMapList(filteredPolicies));
LOGGER.debug("<-getFilteredPolicies: filter={}, serviceTemplate={}", filter, serviceTemplate);
return serviceTemplate;
@@ -368,14 +370,29 @@ public class AuthorativeToscaProvider {
* @param conceptList the concept list
* @return the list of concept map
*/
- private <T extends ToscaEntity> List<Map<String, T>> asConceptMap(List<T> conceptList) {
+ private <T extends ToscaEntity> List<Map<String, T>> asConceptMapList(List<T> conceptList) {
List<Map<String, T>> toscaEntityMapList = new ArrayList<>();
for (T concept : conceptList) {
- Map<String, T> conceptMap = new LinkedHashMap<>();
+ Map<String, T> conceptMap = new TreeMap<>();
conceptMap.put(concept.getName(), concept);
toscaEntityMapList.add(conceptMap);
}
return toscaEntityMapList;
}
+
+ /**
+ * Return the contents of a list of concepts as map of concepts.
+ *
+ * @param conceptList the concept list
+ * @return the list of concept map
+ */
+ private <T extends ToscaEntity> Map<String, T> asConceptMap(List<T> conceptList) {
+ Map<String, T> conceptMap = new LinkedHashMap<>();
+ for (T concept : conceptList) {
+ conceptMap.put(concept.getName(), concept);
+ }
+
+ return conceptMap;
+ }
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
index 83c9dc0cf..e07894cd8 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
@@ -22,7 +22,12 @@
package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -43,6 +48,8 @@ import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfValidationMessage;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
@@ -141,11 +148,19 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion);
if (dataTypes != null) {
- toscaServiceTemplate.setDataTypes(dataTypes.toAuthorative());
+ toscaServiceTemplate.setDataTypes(new LinkedHashMap<>());
+ List<Map<String, ToscaDataType>> dataTypeMapList = dataTypes.toAuthorative();
+ for (Map<String, ToscaDataType> dataTypeMap : dataTypeMapList) {
+ toscaServiceTemplate.getDataTypes().putAll(dataTypeMap);
+ }
}
if (policyTypes != null) {
- toscaServiceTemplate.setPolicyTypes(policyTypes.toAuthorative());
+ toscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>());
+ List<Map<String, ToscaPolicyType>> policyTypeMapList = policyTypes.toAuthorative();
+ for (Map<String, ToscaPolicyType> policyTypeMap : policyTypeMapList) {
+ toscaServiceTemplate.getPolicyTypes().putAll(policyTypeMap);
+ }
}
if (topologyTemplate != null) {
@@ -171,12 +186,12 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
if (toscaServiceTemplate.getDataTypes() != null) {
dataTypes = new JpaToscaDataTypes();
- dataTypes.fromAuthorative(toscaServiceTemplate.getDataTypes());
+ dataTypes.fromAuthorative(Collections.singletonList(toscaServiceTemplate.getDataTypes()));
}
if (toscaServiceTemplate.getPolicyTypes() != null) {
policyTypes = new JpaToscaPolicyTypes();
- policyTypes.fromAuthorative(toscaServiceTemplate.getPolicyTypes());
+ policyTypes.fromAuthorative(Collections.singletonList(toscaServiceTemplate.getPolicyTypes()));
}