X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaServiceTemplate.java;h=aa4f231c0772382e0191152f5a316e8258a3870e;hb=88bcb550c2efd5e43ad3d256fe075a6bf7e90538;hp=83c9dc0cfb25bbcff94770b5ea572b7662a886b8;hpb=fd809717ca774dfabeddd3984fbbbbdfd029601e;p=policy%2Fmodels.git 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..aa4f231c0 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,18 +22,28 @@ package org.onap.policy.models.tosca.simple.concepts; import com.google.gson.annotations.SerializedName; + +import java.util.Collection; +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; import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; import javax.persistence.OneToOne; import javax.persistence.Table; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.common.utils.validation.ParameterValidationUtils; import org.onap.policy.models.base.PfAuthorative; @@ -43,6 +53,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; /** @@ -51,6 +63,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; * * @author Liam Fallon (liam.fallon@est.tech) */ + @Entity @Table(name = "ToscaServiceTemplate") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @@ -64,22 +77,43 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType()); + List> dataTypeMapList = dataTypes.toAuthorative(); + for (Map dataTypeMap : dataTypeMapList) { + toscaServiceTemplate.getDataTypes().putAll(dataTypeMap); + } } if (policyTypes != null) { - toscaServiceTemplate.setPolicyTypes(policyTypes.toAuthorative()); + toscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>()); + List> policyTypeMapList = policyTypes.toAuthorative(); + for (Map policyTypeMap : policyTypeMapList) { + toscaServiceTemplate.getPolicyTypes().putAll(policyTypeMap); + } } if (topologyTemplate != null) { @@ -159,11 +202,11 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType dataTypeKeyCollection, final PfValidationResult result) { + for (PfConceptKey dataTypeKey : dataTypeKeyCollection) { + if (dataTypes == null || dataTypes.get(dataTypeKey) == null) { + result.addValidationMessage(new PfValidationMessage(referencingEntityKey, this.getClass(), + ValidationResult.INVALID, "referenced data type " + dataTypeKey.getId() + " not found")); + } + } + } + + /** + * Validate that all policy types referenced in policies exist. + * + * @param result the validation result object to use for the validation result + * @return the validation result object + */ + private PfValidationResult validatePolicyTypesInPolicies(PfValidationResult result) { + if (topologyTemplate == null || topologyTemplate.getPolicies() == null + || topologyTemplate.getPolicies().getConceptMap().isEmpty()) { return result; } - result = ObjectUtils.compare(policyTypes, other.policyTypes); - if (result != 0) { + if (policyTypes == null || policyTypes.getConceptMap().isEmpty()) { + result.addValidationMessage(new PfValidationMessage(this.getKey(), this.getClass(), + ValidationResult.INVALID, + "no policy types are defined on the service template for the policies in the topology template")); return result; } - return ObjectUtils.compare(topologyTemplate, other.topologyTemplate); + for (JpaToscaPolicy policy : topologyTemplate.getPolicies().getAll(null)) { + if (policyTypes.get(policy.getType()) == null) { + result.addValidationMessage( + new PfValidationMessage(policy.getKey(), this.getClass(), ValidationResult.INVALID, + "policy type " + policy.getType().getId() + " referenced in policy not found")); + } + } + + return result; } }