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.Serializable;
25 import java.util.List;
27 import lombok.NoArgsConstructor;
28 import org.apache.commons.lang3.ObjectUtils;
29 import org.onap.policy.clamp.models.acm.document.base.DocConceptKey;
30 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
31 import org.onap.policy.models.base.PfAuthorative;
32 import org.onap.policy.models.base.PfUtils;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
37 public class DocToscaSchemaDefinition
38 implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<DocToscaSchemaDefinition> {
40 private static final long serialVersionUID = 1L;
45 @SerializedName("type_version")
46 private String typeVersion;
48 private String description;
49 private List<DocToscaConstraint> constraints;
51 public DocToscaSchemaDefinition(ToscaSchemaDefinition toscaEntrySchema) {
52 fromAuthorative(toscaEntrySchema);
58 * @param copyConcept the concept to copy from
60 public DocToscaSchemaDefinition(final DocToscaSchemaDefinition copyConcept) {
61 this.name = copyConcept.name;
62 this.type = copyConcept.type;
63 this.typeVersion = copyConcept.typeVersion;
64 this.description = copyConcept.description;
65 this.constraints = PfUtils.mapList(copyConcept.constraints, DocToscaConstraint::new);
69 public ToscaSchemaDefinition toAuthorative() {
70 var toscaEntrySchema = new ToscaSchemaDefinition();
72 toscaEntrySchema.setName(name);
73 toscaEntrySchema.setType(type);
74 toscaEntrySchema.setTypeVersion(typeVersion);
75 toscaEntrySchema.setDescription(description);
77 if (constraints != null) {
78 toscaEntrySchema.setConstraints(PfUtils.mapList(constraints, DocToscaConstraint::toAuthorative));
81 return toscaEntrySchema;
85 public void fromAuthorative(ToscaSchemaDefinition toscaEntrySchema) {
86 name = toscaEntrySchema.getName();
88 var key = DocUtil.createDocConceptKey(toscaEntrySchema.getType(), toscaEntrySchema.getTypeVersion());
90 typeVersion = key.getVersion();
92 description = toscaEntrySchema.getDescription();
94 if (toscaEntrySchema.getConstraints() != null) {
95 constraints = PfUtils.mapList(toscaEntrySchema.getConstraints(), DocToscaConstraint::new);
100 public DocConceptKey getTypeDocConceptKey() {
101 return new DocConceptKey(type, typeVersion);
105 public int compareTo(DocToscaSchemaDefinition other) {
113 int result = ObjectUtils.compare(description, other.description);
118 return PfUtils.compareCollections(constraints, other.constraints);