2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.models.acm.document.concepts;
23 import com.google.gson.annotations.SerializedName;
24 import java.io.Serial;
25 import java.util.LinkedHashMap;
28 import lombok.EqualsAndHashCode;
29 import org.apache.commons.lang3.ObjectUtils;
30 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
31 import org.onap.policy.common.parameters.annotations.NotBlank;
32 import org.onap.policy.common.parameters.annotations.NotNull;
33 import org.onap.policy.common.parameters.annotations.Valid;
34 import org.onap.policy.models.base.PfKey;
35 import org.onap.policy.models.base.PfUtils;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
39 @EqualsAndHashCode(callSuper = true)
40 public class DocToscaServiceTemplate extends DocToscaEntity<ToscaServiceTemplate> {
43 private static final long serialVersionUID = 1L;
45 public static final String DEFAULT_TOSCA_DEFINTIONS_VERISON = "tosca_simple_yaml_1_1_0";
46 public static final String DEFAULT_NAME = "tosca";
47 public static final String DEFAULT_VERSION = "1.0.0";
49 @SerializedName("tosca_definitions_version")
52 private String toscaDefinitionsVersion;
54 @SerializedName("data_types")
55 private Map<String, @Valid DocToscaDataType> dataTypes;
57 @SerializedName("capability_types")
58 private Map<String, @Valid DocToscaCapabilityType> capabilityTypes;
60 @SerializedName("node_types")
61 private Map<String, @Valid DocToscaNodeType> nodeTypes;
63 @SerializedName("relationship_types")
64 private Map<String, @Valid DocToscaRelationshipType> relationshipTypes;
66 @SerializedName("policy_types")
67 private Map<String, @Valid DocToscaPolicyType> policyTypes;
69 @SerializedName("topology_template")
71 private DocToscaTopologyTemplate toscaTopologyTemplate;
73 public DocToscaServiceTemplate(ToscaServiceTemplate authorativeConcept) {
74 this.fromAuthorative(authorativeConcept);
78 * The Default Constructor creates a {@link DocToscaServiceTemplate} object with a null key.
80 public DocToscaServiceTemplate() {
82 setName(DEFAULT_NAME);
83 setVersion(DEFAULT_VERSION);
84 setToscaDefinitionsVersion(DEFAULT_TOSCA_DEFINTIONS_VERISON);
90 * @param copyConcept the concept to copy from
92 public DocToscaServiceTemplate(final DocToscaServiceTemplate copyConcept) {
94 this.toscaDefinitionsVersion = copyConcept.toscaDefinitionsVersion;
95 this.dataTypes = PfUtils.mapMap(copyConcept.dataTypes, DocToscaDataType::new, new LinkedHashMap<>());
96 this.capabilityTypes =
97 PfUtils.mapMap(copyConcept.capabilityTypes, DocToscaCapabilityType::new, new LinkedHashMap<>());
98 this.nodeTypes = PfUtils.mapMap(copyConcept.nodeTypes, DocToscaNodeType::new, new LinkedHashMap<>());
99 this.relationshipTypes = PfUtils.mapMap(copyConcept.relationshipTypes, DocToscaRelationshipType::new,
100 new LinkedHashMap<>());
101 this.policyTypes = PfUtils.mapMap(copyConcept.policyTypes, DocToscaPolicyType::new, new LinkedHashMap<>());
102 if (copyConcept.toscaTopologyTemplate != null) {
103 this.toscaTopologyTemplate = new DocToscaTopologyTemplate(copyConcept.toscaTopologyTemplate);
108 public ToscaServiceTemplate toAuthorative() {
109 final var toscaServiceTemplate = new ToscaServiceTemplate();
110 super.setToscaEntity(toscaServiceTemplate);
111 super.toAuthorative();
113 toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion);
114 toscaServiceTemplate.setDataTypes(DocUtil.docMapToMap(dataTypes, DocToscaDataType::toAuthorative));
116 .setCapabilityTypes(DocUtil.docMapToMap(capabilityTypes, DocToscaCapabilityType::toAuthorative));
118 .setRelationshipTypes(DocUtil.docMapToMap(relationshipTypes, DocToscaRelationshipType::toAuthorative));
119 toscaServiceTemplate.setNodeTypes(DocUtil.docMapToMap(nodeTypes, DocToscaNodeType::toAuthorative));
120 toscaServiceTemplate.setPolicyTypes(DocUtil.docMapToMap(policyTypes, DocToscaPolicyType::toAuthorative));
121 toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate.toAuthorative());
123 return toscaServiceTemplate;
127 public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) {
128 super.fromAuthorative(toscaServiceTemplate);
129 if (getVersion() == null || PfKey.NULL_KEY_VERSION.equals(getVersion())) {
130 setVersion(DEFAULT_VERSION);
132 if (getName() == null || PfKey.NULL_KEY_NAME.equals(getName())) {
133 setName(DEFAULT_NAME);
136 toscaDefinitionsVersion = toscaServiceTemplate.getToscaDefinitionsVersion();
138 dataTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getDataTypes(), DocToscaDataType::new);
140 capabilityTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getCapabilityTypes(), DocToscaCapabilityType::new);
143 DocUtil.mapToDocMap(toscaServiceTemplate.getRelationshipTypes(), DocToscaRelationshipType::new);
145 nodeTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getNodeTypes(), DocToscaNodeType::new);
147 if (toscaServiceTemplate.getPolicyTypes() != null) {
148 policyTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getPolicyTypes(), DocToscaPolicyType::new);
151 if (toscaServiceTemplate.getToscaTopologyTemplate() != null) {
152 toscaTopologyTemplate = new DocToscaTopologyTemplate(toscaServiceTemplate.getToscaTopologyTemplate());
157 public int compareTo(DocToscaEntity<ToscaServiceTemplate> otherConcept) {
158 int result = compareToWithoutEntities(otherConcept);
163 final var other = (DocToscaServiceTemplate) otherConcept;
165 result = DocUtil.compareMaps(dataTypes, other.dataTypes);
170 result = DocUtil.compareMaps(capabilityTypes, other.capabilityTypes);
175 result = DocUtil.compareMaps(relationshipTypes, other.relationshipTypes);
180 result = DocUtil.compareMaps(nodeTypes, other.nodeTypes);
185 result = DocUtil.compareMaps(policyTypes, other.policyTypes);
190 return ObjectUtils.compare(toscaTopologyTemplate, other.toscaTopologyTemplate);
194 * Compare this service template to another service template, ignoring contained entitites.
196 * @param otherConcept the other topology template
197 * @return the result of the comparison
199 public int compareToWithoutEntities(final DocToscaEntity<ToscaServiceTemplate> otherConcept) {
200 if (otherConcept == null) {
203 if (this == otherConcept) {
206 if (getClass() != otherConcept.getClass()) {
207 return getClass().getName().compareTo(otherConcept.getClass().getName());
210 final var other = (DocToscaServiceTemplate) otherConcept;
211 if (!super.equals(other)) {
212 return super.compareTo(other);
215 return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);