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 java.io.Serial;
24 import java.util.Collection;
25 import java.util.LinkedHashMap;
26 import java.util.LinkedHashSet;
29 import java.util.stream.Collectors;
31 import lombok.EqualsAndHashCode;
32 import lombok.NoArgsConstructor;
33 import org.apache.commons.collections4.CollectionUtils;
34 import org.onap.policy.clamp.models.acm.document.base.DocConceptKey;
35 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
36 import org.onap.policy.common.parameters.annotations.NotBlank;
37 import org.onap.policy.common.parameters.annotations.NotNull;
38 import org.onap.policy.common.parameters.annotations.Valid;
39 import org.onap.policy.models.base.PfUtils;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaWithToscaProperties;
41 import org.onap.policy.models.tosca.utils.ToscaUtils;
44 @EqualsAndHashCode(callSuper = true)
46 public class DocToscaWithToscaProperties<T extends ToscaWithToscaProperties> extends DocToscaEntity<T> {
49 private static final long serialVersionUID = 1L;
51 @SuppressWarnings("squid:S1948")
52 private Map<@NotNull @NotBlank String, @NotNull @Valid DocToscaProperty> properties;
57 * @param copyConcept the concept to copy from
59 public DocToscaWithToscaProperties(DocToscaWithToscaProperties<T> copyConcept) {
61 this.properties = PfUtils.mapMap(copyConcept.properties, DocToscaProperty::new);
65 public T toAuthorative() {
66 var tosca = super.toAuthorative();
67 tosca.setProperties(PfUtils.mapMap(properties, DocToscaProperty::toAuthorative));
72 public void fromAuthorative(T authorativeConcept) {
73 super.fromAuthorative(authorativeConcept);
76 if (authorativeConcept.getProperties() != null) {
77 properties = new LinkedHashMap<>();
78 for (var toscaPropertyEntry : authorativeConcept.getProperties().entrySet()) {
79 var jpaProperty = new DocToscaProperty(toscaPropertyEntry.getValue());
80 jpaProperty.setName(toscaPropertyEntry.getKey());
81 properties.put(toscaPropertyEntry.getKey(), jpaProperty);
87 * Get the referenced data types.
89 * @return the referenced data types
91 public Collection<DocConceptKey> getReferencedDataTypes() {
92 if (properties == null) {
93 return CollectionUtils.emptyCollection();
96 Set<DocConceptKey> referencedDataTypes = new LinkedHashSet<>();
98 for (var property : properties.values()) {
99 referencedDataTypes.add(property.getTypeDocConceptKey());
101 if (property.getEntrySchema() != null) {
102 referencedDataTypes.add(property.getEntrySchema().getTypeDocConceptKey());
106 var set = ToscaUtils.getPredefinedDataTypes().stream().map(DocConceptKey::new).collect(Collectors.toSet());
107 referencedDataTypes.removeAll(set);
108 return referencedDataTypes;
112 public int compareTo(final DocToscaEntity<T> otherConcept) {
113 int result = super.compareTo(otherConcept);
118 final var other = (DocToscaWithToscaProperties<T>) otherConcept;
120 return DocUtil.compareMaps(properties, other.properties);