aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-06-14 07:38:26 +0000
committerliamfallon <liam.fallon@est.tech>2019-06-14 07:38:26 +0000
commit10c11e142feb1d040612fed695aaf76d007294da (patch)
tree58d4b61c8ceed0ee660b65b9331bbb3c4b67cbc2 /models-tosca/src/main
parent2d69f0ed6b0a59bacd4e7986c23281e4a9006c93 (diff)
Allow multiple versions of entities to be returned
Fix .gitreviw file to point at "master" rather than "dublin" Allow return of multiple versions of policy types and data types in TOSCA service templates and multiple policies in TOSCA topology templates. Because the return type is a list of singleton maps, utility methods were added to return flat maps of poliicy types, data types, and policies keyed by a compound ToscaEntityKey name/version key. Issue-ID: POLICY-1807 Change-Id: I355038aaca26f41064d0e3cb3b45b1de2294cf5f 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.java40
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityKey.java38
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java4
4 files changed, 90 insertions, 0 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 f5a178a37..c0f40f159 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
@@ -25,12 +25,17 @@ package org.onap.policy.models.tosca.authorative.concepts;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
+import javax.ws.rs.core.Response;
+
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfNameVersion;
/**
@@ -71,4 +76,39 @@ public class ToscaEntity implements PfNameVersion {
}
}
}
+
+ /**
+ * Get a key for this entity.
+ *
+ * @return a ToscaEntityKey for this entry
+ */
+ public ToscaEntityKey getKey() {
+ return new ToscaEntityKey(name, version);
+ }
+
+ /**
+ * Convert a list of maps of TOSCA entities into a regular map.
+ *
+ * @param listOfMapsOfEntities 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> getEntityListMapAsMap(
+ List<Map<String, T>> listOfMapsOfEntities) {
+ // Declare the return map
+ Map<ToscaEntityKey, T> entityMap = new LinkedHashMap<>();
+
+ for (Map<String, T> mapOfEntities : listOfMapsOfEntities) {
+ 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/ToscaEntityKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityKey.java
new file mode 100644
index 000000000..adde63b60
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityKey.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.concepts;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * This class is a compound key for Tosca entity keying on maps.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ToscaEntityKey {
+ private String name;
+ private String version;
+}
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 0b19708dc..21b15a8ae 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
@@ -54,4 +54,12 @@ public class ToscaServiceTemplate extends ToscaEntity {
@ApiModelProperty(name = "data_types")
@SerializedName("data_types")
private List<Map<String, ToscaDataType>> dataTypes;
+
+ public Map<ToscaEntityKey, ToscaPolicyType> getPolicyTypesAsMap() {
+ return ToscaEntity.getEntityListMapAsMap(policyTypes);
+ }
+
+ public Map<ToscaEntityKey, ToscaDataType> getDataTypesAsMap() {
+ return ToscaEntity.getEntityListMapAsMap(dataTypes);
+ }
} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java
index ebb53e177..74ebf07e0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java
@@ -37,4 +37,8 @@ public class ToscaTopologyTemplate {
private String description;
private List<Map<String, ToscaPolicy>> policies;
+
+ public Map<ToscaEntityKey, ToscaPolicy> getPoliciesAsMap() {
+ return ToscaEntity.getEntityListMapAsMap(policies);
+ }
}