2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022,2024 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 jakarta.ws.rs.core.Response;
25 import java.io.Serial;
26 import java.util.LinkedHashMap;
29 import lombok.EqualsAndHashCode;
30 import lombok.NoArgsConstructor;
31 import lombok.ToString;
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.PfKey;
35 import org.onap.policy.models.base.PfModelRuntimeException;
36 import org.onap.policy.models.base.PfUtils;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
40 @EqualsAndHashCode(callSuper = true)
43 public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjectProperties> extends DocToscaEntity<T> {
46 private static final long serialVersionUID = 1L;
50 @SerializedName("type_version")
51 private String typeVersion;
53 @SuppressWarnings("squid:S1948")
54 private Map<String, Object> properties;
59 * @param copyConcept the concept to copy from
61 public DocToscaWithTypeAndStringProperties(final DocToscaWithTypeAndStringProperties<T> copyConcept) {
63 this.type = copyConcept.type;
64 this.typeVersion = copyConcept.typeVersion;
65 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
69 public T toAuthorative() {
70 var tosca = super.toAuthorative();
73 tosca.setTypeVersion(typeVersion);
75 tosca.setProperties(PfUtils.mapMap(properties, x -> x));
81 public void fromAuthorative(T authorativeConcept) {
82 super.fromAuthorative(authorativeConcept);
83 if (authorativeConcept.getType() == null) {
84 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
85 "Type not specified, the type of this TOSCA entity must be specified in the type field");
87 var key = DocUtil.createDocConceptKey(authorativeConcept.getType(), authorativeConcept.getTypeVersion());
89 typeVersion = key.getVersion();
91 if (PfKey.NULL_KEY_VERSION.equals(typeVersion)) {
92 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
93 "Version not specified, the version of this TOSCA entity must be specified"
94 + " in the type_version field");
97 properties = PfUtils.mapMap(authorativeConcept.getProperties(), x -> x);
100 public DocConceptKey getTypeDocConceptKey() {
101 return new DocConceptKey(type, typeVersion);