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=109f1f0a873f26f9576e29a9b59ea2e896f9ce9c;hb=refs%2Fchanges%2F29%2F133129%2F4;hp=f1a6a395f7b7d3c8c545b7beb1756e35551ddbab;hpb=9c5d23395918a739b591667edd77e3ced9cd4bfb;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 f1a6a395f..109f1f0a8 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,7 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021,2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,16 +41,14 @@ 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.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; 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; /** @@ -76,38 +74,64 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType()); - List> dataTypeMapList = dataTypes.toAuthorative(); - for (Map dataTypeMap : dataTypeMapList) { - toscaServiceTemplate.getDataTypes().putAll(dataTypeMap); - } + toscaServiceTemplate.setDataTypes(flattenMap(dataTypes.toAuthorative())); + } + + if (capabilityTypes != null) { + toscaServiceTemplate.setCapabilityTypes(flattenMap(capabilityTypes.toAuthorative())); + } + + if (relationshipTypes != null) { + toscaServiceTemplate.setRelationshipTypes(flattenMap(relationshipTypes.toAuthorative())); + } + + if (nodeTypes != null) { + toscaServiceTemplate.setNodeTypes(flattenMap(nodeTypes.toAuthorative())); } if (policyTypes != null) { - toscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>()); - List> policyTypeMapList = policyTypes.toAuthorative(); - for (Map policyTypeMap : policyTypeMapList) { - toscaServiceTemplate.getPolicyTypes().putAll(policyTypeMap); - } + toscaServiceTemplate.setPolicyTypes(flattenMap(policyTypes.toAuthorative())); } if (topologyTemplate != null) { @@ -194,15 +228,31 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType Map flattenMap(List> list) { + Map result = new LinkedHashMap<>(); + + for (Map map : list) { + result.putAll(map); + } + + return result; + } + @Override public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) { super.fromAuthorative(toscaServiceTemplate); - if (PfKey.NULL_KEY_NAME.equals(getKey().getName())) { + if (toscaServiceTemplate.getDefinedName() == null) { getKey().setName(DEFAULT_NAME); } - if (PfKey.NULL_KEY_VERSION.equals(getKey().getVersion())) { + if (toscaServiceTemplate.getDefinedVersion() == null) { getKey().setVersion(DEFAULT_VERSION); } @@ -213,6 +263,21 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType dataTypeKeyCollection, final PfValidationResult result) { + private void validateReferencedDataTypesExists(final Collection dataTypeKeyCollection, + final BeanValidationResult 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")); + addResult(result, "data type", dataTypeKey.getId(), NOT_FOUND); } } } @@ -382,30 +466,24 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType