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.util.LinkedHashMap;
27 import lombok.EqualsAndHashCode;
28 import org.apache.commons.lang3.ObjectUtils;
29 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
30 import org.onap.policy.common.parameters.annotations.NotBlank;
31 import org.onap.policy.common.parameters.annotations.NotNull;
32 import org.onap.policy.common.parameters.annotations.Valid;
33 import org.onap.policy.models.base.PfKey;
34 import org.onap.policy.models.base.PfUtils;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 @EqualsAndHashCode(callSuper = true)
39 public class DocToscaServiceTemplate extends DocToscaEntity<ToscaServiceTemplate> {
41 private static final long serialVersionUID = 1L;
43 public static final String DEFAULT_TOSCA_DEFINTIONS_VERISON = "tosca_simple_yaml_1_1_0";
44 public static final String DEFAULT_NAME = "tosca";
45 public static final String DEFAULT_VERSION = "1.0.0";
47 @SerializedName("tosca_definitions_version")
50 private String toscaDefinitionsVersion;
52 @SerializedName("data_types")
53 private Map<String, @Valid DocToscaDataType> dataTypes;
55 @SerializedName("capability_types")
56 private Map<String, @Valid DocToscaCapabilityType> capabilityTypes;
58 @SerializedName("node_types")
59 private Map<String, @Valid DocToscaNodeType> nodeTypes;
61 @SerializedName("relationship_types")
62 private Map<String, @Valid DocToscaRelationshipType> relationshipTypes;
64 @SerializedName("policy_types")
65 private Map<String, @Valid DocToscaPolicyType> policyTypes;
67 @SerializedName("topology_template")
69 private DocToscaTopologyTemplate toscaTopologyTemplate;
71 public DocToscaServiceTemplate(ToscaServiceTemplate authorativeConcept) {
72 this.fromAuthorative(authorativeConcept);
76 * The Default Constructor creates a {@link DocToscaServiceTemplate} object with a null key.
78 public DocToscaServiceTemplate() {
80 setName(DEFAULT_NAME);
81 setVersion(DEFAULT_VERSION);
82 setToscaDefinitionsVersion(DEFAULT_TOSCA_DEFINTIONS_VERISON);
88 * @param copyConcept the concept to copy from
90 public DocToscaServiceTemplate(final DocToscaServiceTemplate copyConcept) {
92 this.toscaDefinitionsVersion = copyConcept.toscaDefinitionsVersion;
93 this.dataTypes = PfUtils.mapMap(copyConcept.dataTypes, DocToscaDataType::new, new LinkedHashMap<>());
94 this.capabilityTypes =
95 PfUtils.mapMap(copyConcept.capabilityTypes, DocToscaCapabilityType::new, new LinkedHashMap<>());
96 this.nodeTypes = PfUtils.mapMap(copyConcept.nodeTypes, DocToscaNodeType::new, new LinkedHashMap<>());
97 this.relationshipTypes = PfUtils.mapMap(copyConcept.relationshipTypes, DocToscaRelationshipType::new,
98 new LinkedHashMap<>());
99 this.policyTypes = PfUtils.mapMap(copyConcept.policyTypes, DocToscaPolicyType::new, new LinkedHashMap<>());
100 if (copyConcept.toscaTopologyTemplate != null) {
101 this.toscaTopologyTemplate = new DocToscaTopologyTemplate(copyConcept.toscaTopologyTemplate);
106 public ToscaServiceTemplate toAuthorative() {
107 final var toscaServiceTemplate = new ToscaServiceTemplate();
108 super.setToscaEntity(toscaServiceTemplate);
109 super.toAuthorative();
111 toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion);
112 toscaServiceTemplate.setDataTypes(DocUtil.docMapToMap(dataTypes, DocToscaDataType::toAuthorative));
114 .setCapabilityTypes(DocUtil.docMapToMap(capabilityTypes, DocToscaCapabilityType::toAuthorative));
116 .setRelationshipTypes(DocUtil.docMapToMap(relationshipTypes, DocToscaRelationshipType::toAuthorative));
117 toscaServiceTemplate.setNodeTypes(DocUtil.docMapToMap(nodeTypes, DocToscaNodeType::toAuthorative));
118 toscaServiceTemplate.setPolicyTypes(DocUtil.docMapToMap(policyTypes, DocToscaPolicyType::toAuthorative));
119 toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate.toAuthorative());
121 return toscaServiceTemplate;
125 public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) {
126 super.fromAuthorative(toscaServiceTemplate);
127 if (getVersion() == null || PfKey.NULL_KEY_VERSION.equals(getVersion())) {
128 setVersion(DEFAULT_VERSION);
130 if (getName() == null || PfKey.NULL_KEY_NAME.equals(getName())) {
131 setName(DEFAULT_NAME);
134 toscaDefinitionsVersion = toscaServiceTemplate.getToscaDefinitionsVersion();
136 dataTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getDataTypes(), DocToscaDataType::new);
138 capabilityTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getCapabilityTypes(), DocToscaCapabilityType::new);
141 DocUtil.mapToDocMap(toscaServiceTemplate.getRelationshipTypes(), DocToscaRelationshipType::new);
143 nodeTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getNodeTypes(), DocToscaNodeType::new);
145 if (toscaServiceTemplate.getPolicyTypes() != null) {
146 policyTypes = DocUtil.mapToDocMap(toscaServiceTemplate.getPolicyTypes(), DocToscaPolicyType::new);
149 if (toscaServiceTemplate.getToscaTopologyTemplate() != null) {
150 toscaTopologyTemplate = new DocToscaTopologyTemplate(toscaServiceTemplate.getToscaTopologyTemplate());
155 public int compareTo(DocToscaEntity<ToscaServiceTemplate> otherConcept) {
156 int result = compareToWithoutEntities(otherConcept);
161 final var other = (DocToscaServiceTemplate) otherConcept;
163 result = DocUtil.compareMaps(dataTypes, other.dataTypes);
168 result = DocUtil.compareMaps(capabilityTypes, other.capabilityTypes);
173 result = DocUtil.compareMaps(relationshipTypes, other.relationshipTypes);
178 result = DocUtil.compareMaps(nodeTypes, other.nodeTypes);
183 result = DocUtil.compareMaps(policyTypes, other.policyTypes);
188 return ObjectUtils.compare(toscaTopologyTemplate, other.toscaTopologyTemplate);
192 * Compare this service template to another service template, ignoring contained entitites.
194 * @param otherConcept the other topology template
195 * @return the result of the comparison
197 public int compareToWithoutEntities(final DocToscaEntity<ToscaServiceTemplate> otherConcept) {
198 if (otherConcept == null) {
201 if (this == otherConcept) {
204 if (getClass() != otherConcept.getClass()) {
205 return getClass().getName().compareTo(otherConcept.getClass().getName());
208 final var other = (DocToscaServiceTemplate) otherConcept;
209 if (!super.equals(other)) {
210 return super.compareTo(other);
213 return ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);