2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020, 2023 Nordix Foundation.
4 * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.tosca.simple.concepts;
25 import jakarta.persistence.Column;
26 import jakarta.persistence.EmbeddedId;
27 import java.util.List;
29 import lombok.EqualsAndHashCode;
30 import lombok.NonNull;
31 import org.apache.commons.lang3.StringUtils;
32 import org.onap.policy.common.parameters.annotations.NotNull;
33 import org.onap.policy.common.utils.coder.YamlJsonTranslator;
34 import org.onap.policy.models.base.PfAuthorative;
35 import org.onap.policy.models.base.PfConcept;
36 import org.onap.policy.models.base.PfConceptKey;
37 import org.onap.policy.models.base.PfKey;
38 import org.onap.policy.models.base.PfReferenceKey;
39 import org.onap.policy.models.base.validation.annotations.VerifyKey;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
43 * Class to represent the parameter in TOSCA definition.
46 @EqualsAndHashCode(callSuper = false)
47 public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaParameter> {
48 private static final long serialVersionUID = 1675770231921107988L;
53 private PfReferenceKey key;
58 private PfConceptKey type;
64 * The Default Constructor creates a {@link JpaToscaParameter} object with a null key.
66 public JpaToscaParameter() {
67 this(new PfReferenceKey());
71 * The Key Constructor creates a {@link JpaToscaParameter} object with the given concept key.
75 public JpaToscaParameter(@NonNull final PfReferenceKey key) {
76 this(key, new PfConceptKey());
80 * The Key Constructor creates a {@link JpaToscaParameter} object with the given concept key.
83 * @param type the key of the parameter type
85 public JpaToscaParameter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) {
93 * @param copyConcept the concept to copy from
95 public JpaToscaParameter(final JpaToscaParameter copyConcept) {
97 this.key = new PfReferenceKey(copyConcept.key);
98 this.type = new PfConceptKey(copyConcept.type);
99 this.value = copyConcept.value;
103 * Authorative constructor.
105 * @param authorativeConcept the authorative concept to copy from
107 public JpaToscaParameter(final ToscaParameter authorativeConcept) {
108 this.fromAuthorative(authorativeConcept);
112 public ToscaParameter toAuthorative() {
113 var toscaParameter = new ToscaParameter();
115 toscaParameter.setName(key.getLocalName());
117 toscaParameter.setType(type.getName());
118 toscaParameter.setTypeVersion(type.getVersion());
120 if (!StringUtils.isBlank(value)) {
121 toscaParameter.setValue(new YamlJsonTranslator().fromYaml(value, Object.class));
124 return toscaParameter;
128 public void fromAuthorative(ToscaParameter toscaParameter) {
129 this.setKey(new PfReferenceKey());
130 getKey().setLocalName(toscaParameter.getName());
132 if (toscaParameter.getTypeVersion() != null) {
133 type = new PfConceptKey(toscaParameter.getType(), toscaParameter.getTypeVersion());
135 type = new PfConceptKey(toscaParameter.getType(), PfKey.NULL_KEY_VERSION);
138 value = new YamlJsonTranslator().toYaml(toscaParameter.getValue());
142 public List<PfKey> getKeys() {
143 final List<PfKey> keyList = getKey().getKeys();
145 keyList.addAll(type.getKeys());
151 public void clean() {
157 value = value.trim();
162 public int compareTo(final PfConcept otherConcept) {
163 if (otherConcept == null) {
166 if (this == otherConcept) {
169 if (getClass() != otherConcept.getClass()) {
170 return getClass().getName().compareTo(otherConcept.getClass().getName());
173 final JpaToscaParameter other = (JpaToscaParameter) otherConcept;
174 int result = key.compareTo(other.key);
179 return value.compareTo(other.value);