2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022,2026 OpenInfra Foundation Europe. All rights reserved.
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.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import java.io.Serial;
27 import java.io.Serializable;
28 import java.util.List;
30 import lombok.NoArgsConstructor;
31 import org.apache.commons.lang3.ObjectUtils;
32 import org.onap.policy.clamp.models.acm.document.base.DocConceptKey;
33 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
34 import org.onap.policy.models.base.PfAuthorative;
35 import org.onap.policy.models.base.PfUtils;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
40 @JsonIgnoreProperties({"typeDocConceptKey"})
41 public class DocToscaSchemaDefinition
42 implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<DocToscaSchemaDefinition> {
45 private static final long serialVersionUID = 1L;
50 @JsonProperty("type_version")
51 private String typeVersion;
53 private String description;
54 private List<DocToscaConstraint> constraints;
56 public DocToscaSchemaDefinition(ToscaSchemaDefinition toscaEntrySchema) {
57 fromAuthorative(toscaEntrySchema);
63 * @param copyConcept the concept to copy from
65 public DocToscaSchemaDefinition(final DocToscaSchemaDefinition copyConcept) {
66 this.name = copyConcept.name;
67 this.type = copyConcept.type;
68 this.typeVersion = copyConcept.typeVersion;
69 this.description = copyConcept.description;
70 this.constraints = PfUtils.mapList(copyConcept.constraints, DocToscaConstraint::new);
74 public ToscaSchemaDefinition toAuthorative() {
75 var toscaEntrySchema = new ToscaSchemaDefinition();
77 toscaEntrySchema.setName(name);
78 toscaEntrySchema.setType(type);
79 toscaEntrySchema.setTypeVersion(typeVersion);
80 toscaEntrySchema.setDescription(description);
82 if (constraints != null) {
83 toscaEntrySchema.setConstraints(PfUtils.mapList(constraints, DocToscaConstraint::toAuthorative));
86 return toscaEntrySchema;
90 public void fromAuthorative(ToscaSchemaDefinition toscaEntrySchema) {
91 name = toscaEntrySchema.getName();
93 var key = DocUtil.createDocConceptKey(toscaEntrySchema.getType(), toscaEntrySchema.getTypeVersion());
95 typeVersion = key.getVersion();
97 description = toscaEntrySchema.getDescription();
99 if (toscaEntrySchema.getConstraints() != null) {
100 constraints = PfUtils.mapList(toscaEntrySchema.getConstraints(), DocToscaConstraint::new);
106 public DocConceptKey getTypeDocConceptKey() {
107 return new DocConceptKey(type, typeVersion);
111 public int compareTo(DocToscaSchemaDefinition other) {
119 int result = ObjectUtils.compare(description, other.description);
124 return PfUtils.compareCollections(constraints, other.constraints);