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.util.LinkedHashMap;
26 import javax.ws.rs.core.Response;
28 import lombok.EqualsAndHashCode;
29 import lombok.NoArgsConstructor;
30 import lombok.ToString;
31 import org.onap.policy.clamp.models.acm.document.base.DocConceptKey;
32 import org.onap.policy.clamp.models.acm.document.base.DocUtil;
33 import org.onap.policy.models.base.PfKey;
34 import org.onap.policy.models.base.PfModelRuntimeException;
35 import org.onap.policy.models.base.PfUtils;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
39 @EqualsAndHashCode(callSuper = true)
42 public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjectProperties> extends DocToscaEntity<T> {
44 private static final long serialVersionUID = 1L;
48 @SerializedName("type_version")
49 private String typeVersion;
51 private Map<String, Object> properties;
56 * @param copyConcept the concept to copy from
58 public DocToscaWithTypeAndStringProperties(final DocToscaWithTypeAndStringProperties<T> copyConcept) {
60 this.type = copyConcept.type;
61 this.typeVersion = copyConcept.typeVersion;
62 this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
66 public T toAuthorative() {
67 var tosca = super.toAuthorative();
70 tosca.setTypeVersion(typeVersion);
72 tosca.setProperties(PfUtils.mapMap(properties, x -> x));
78 public void fromAuthorative(T authorativeConcept) {
79 super.fromAuthorative(authorativeConcept);
80 if (authorativeConcept.getType() == null) {
81 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
82 "Type not specified, the type of this TOSCA entity must be specified in the type field");
84 var key = DocUtil.createDocConceptKey(authorativeConcept.getType(), authorativeConcept.getTypeVersion());
86 typeVersion = key.getVersion();
88 if (PfKey.NULL_KEY_VERSION.equals(typeVersion)) {
89 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
90 "Version not specified, the version of this TOSCA entity must be specified"
91 + " in the type_version field");
94 properties = PfUtils.mapMap(authorativeConcept.getProperties(), x -> x);
97 public DocConceptKey getTypeDocConceptKey() {
98 return new DocConceptKey(type, typeVersion);