X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fauthorative%2Fconcepts%2FToscaEntity.java;h=e588a59fe703978980a31930c9e239f671403130;hb=9c5d23395918a739b591667edd77e3ced9cd4bfb;hp=e89b31635188cfb84dd8b86a27d626b1bc1fba80;hpb=69bc7db0edc751d3936b92c4bdf1ee74dfa4da57;p=policy%2Fmodels.git 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 e89b31635..e588a59fe 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,14 @@ 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; /** @@ -54,7 +56,7 @@ public class ToscaEntity implements PfNameVersion { private String description; /** - * Copy COnstructor. + * Copy Constructor. * * @param copyObject object to copy from */ @@ -71,4 +73,63 @@ 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 Map getEntityListMapAsMap( + List> listOfMapsOfEntities) { + // Declare the return map + Map entityMap = new LinkedHashMap<>(); + + for (Map 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; + } + + /** + * 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 Map getEntityMapAsMap(Map mapOfEntities) { + // Declare the return map + Map 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; + } + }