2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.tosca.simple.concepts;
24 import java.util.List;
25 import javax.persistence.Column;
26 import javax.persistence.EmbeddedId;
27 import javax.persistence.Entity;
28 import javax.persistence.Inheritance;
29 import javax.persistence.InheritanceType;
30 import javax.persistence.Table;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
34 import org.apache.commons.lang3.StringUtils;
35 import org.onap.policy.common.parameters.annotations.NotNull;
36 import org.onap.policy.common.utils.coder.YamlJsonTranslator;
37 import org.onap.policy.models.base.PfAuthorative;
38 import org.onap.policy.models.base.PfConcept;
39 import org.onap.policy.models.base.PfConceptKey;
40 import org.onap.policy.models.base.PfKey;
41 import org.onap.policy.models.base.PfReferenceKey;
42 import org.onap.policy.models.base.validation.annotations.VerifyKey;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
46 * Class to represent the parameter in TOSCA definition.
49 @Table(name = "ToscaParameter")
50 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
52 @EqualsAndHashCode(callSuper = false)
53 public class JpaToscaParameter extends PfConcept implements PfAuthorative<ToscaParameter> {
54 private static final long serialVersionUID = 1675770231921107988L;
59 private PfReferenceKey key;
64 private PfConceptKey type;
70 * The Default Constructor creates a {@link JpaToscaParameter} object with a null key.
72 public JpaToscaParameter() {
73 this(new PfReferenceKey());
77 * The Key Constructor creates a {@link JpaToscaParameter} object with the given concept key.
81 public JpaToscaParameter(@NonNull final PfReferenceKey key) {
82 this(key, new PfConceptKey());
86 * The Key Constructor creates a {@link JpaToscaParameter} object with the given concept key.
89 * @param type the key of the parameter type
91 public JpaToscaParameter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) {
99 * @param copyConcept the concept to copy from
101 public JpaToscaParameter(final JpaToscaParameter copyConcept) {
103 this.key = new PfReferenceKey(copyConcept.key);
104 this.type = new PfConceptKey(copyConcept.type);
105 this.value = copyConcept.value;
109 * Authorative constructor.
111 * @param authorativeConcept the authorative concept to copy from
113 public JpaToscaParameter(final ToscaParameter authorativeConcept) {
114 this.fromAuthorative(authorativeConcept);
118 public ToscaParameter toAuthorative() {
119 ToscaParameter toscaParameter = new ToscaParameter();
121 toscaParameter.setName(key.getLocalName());
123 toscaParameter.setType(type.getName());
124 toscaParameter.setTypeVersion(type.getVersion());
126 if (!StringUtils.isBlank(value)) {
127 toscaParameter.setValue(new YamlJsonTranslator().fromYaml(value, Object.class));
130 return toscaParameter;
134 public void fromAuthorative(ToscaParameter toscaParameter) {
135 this.setKey(new PfReferenceKey());
136 getKey().setLocalName(toscaParameter.getName());
138 if (toscaParameter.getTypeVersion() != null) {
139 type = new PfConceptKey(toscaParameter.getType(), toscaParameter.getTypeVersion());
141 type = new PfConceptKey(toscaParameter.getType(), PfKey.NULL_KEY_VERSION);
144 value = new YamlJsonTranslator().toYaml(toscaParameter.getValue());
148 public List<PfKey> getKeys() {
149 final List<PfKey> keyList = getKey().getKeys();
151 keyList.addAll(type.getKeys());
157 public void clean() {
163 value = value.trim();
168 public int compareTo(final PfConcept otherConcept) {
169 if (otherConcept == null) {
172 if (this == otherConcept) {
175 if (getClass() != otherConcept.getClass()) {
176 return getClass().getName().compareTo(otherConcept.getClass().getName());
179 final JpaToscaParameter other = (JpaToscaParameter) otherConcept;
180 int result = key.compareTo(other.key);
185 return value.compareTo(other.value);