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 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 private Map<String, Object> properties;
58 * @param copyConcept the concept to copy from
60 public DocToscaWithTypeAndStringProperties(final DocToscaWithTypeAndStringProperties<T> copyConcept) {
62 this.type = copyConcept.type;
63 this.typeVersion = copyConcept.typeVersion;
64 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
68 public T toAuthorative() {
69 var tosca = super.toAuthorative();
72 tosca.setTypeVersion(typeVersion);
74 tosca.setProperties(PfUtils.mapMap(properties, x -> x));
80 public void fromAuthorative(T authorativeConcept) {
81 super.fromAuthorative(authorativeConcept);
82 if (authorativeConcept.getType() == null) {
83 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
84 "Type not specified, the type of this TOSCA entity must be specified in the type field");
86 var key = DocUtil.createDocConceptKey(authorativeConcept.getType(), authorativeConcept.getTypeVersion());
88 typeVersion = key.getVersion();
90 if (PfKey.NULL_KEY_VERSION.equals(typeVersion)) {
91 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
92 "Version not specified, the version of this TOSCA entity must be specified"
93 + " in the type_version field");
96 properties = PfUtils.mapMap(authorativeConcept.getProperties(), x -> x);
99 public DocConceptKey getTypeDocConceptKey() {
100 return new DocConceptKey(type, typeVersion);