2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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.models.tosca;
23 import com.google.gson.annotations.SerializedName;
25 import java.util.ArrayList;
26 import java.util.List;
28 import java.util.Map.Entry;
29 import java.util.TreeMap;
31 import javax.persistence.CascadeType;
32 import javax.persistence.Column;
33 import javax.persistence.EmbeddedId;
34 import javax.persistence.Entity;
35 import javax.persistence.Inheritance;
36 import javax.persistence.InheritanceType;
37 import javax.persistence.OneToMany;
38 import javax.persistence.Table;
41 import lombok.EqualsAndHashCode;
42 import lombok.NonNull;
44 import org.onap.policy.common.utils.validation.Assertions;
45 import org.onap.policy.models.base.PfConcept;
46 import org.onap.policy.models.base.PfConceptKey;
47 import org.onap.policy.models.base.PfKey;
48 import org.onap.policy.models.base.PfValidationResult;
51 * Class to represent the EntrySchema of list/map property in TOSCA definition.
54 @Table(name = "ToscaEntityType")
55 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
57 @EqualsAndHashCode(callSuper = false)
58 public class ToscaEntityType extends PfConcept {
59 private static final long serialVersionUID = -1330661834220739393L;
63 private PfConceptKey key = PfConceptKey.getNullKey();
65 @SerializedName("derived_from")
66 @Column(name = "derivedFrom")
67 private PfConceptKey derivedFrom;
69 @OneToMany(cascade = CascadeType.ALL)
70 private Map<String, String> metadata;
72 @Column(name = "description")
73 private String description;
76 * The Default Constructor creates a {@link ToscaEntityType} object with a null key.
78 public ToscaEntityType() {
79 this(new PfConceptKey());
83 * The Key Constructor creates a {@link ToscaEntityType} object with the given concept key.
87 public ToscaEntityType(@NonNull final PfConceptKey key) {
94 * @param copyConcept the concept to copy from
96 public ToscaEntityType(final ToscaEntityType copyConcept) {
101 public List<PfKey> getKeys() {
102 final List<PfKey> keyList = new ArrayList<>();
103 keyList.add(getKey());
108 public void clean() {
109 description = description.trim();
111 for (Entry<String, String> metadataEntry : metadata.entrySet()) {
112 metadataEntry.setValue(metadataEntry.getValue().trim());
117 public PfValidationResult validate(PfValidationResult result) {
122 public int compareTo(final PfConcept otherConcept) {
123 if (otherConcept == null) {
126 if (this == otherConcept) {
129 if (getClass() != otherConcept.getClass()) {
130 return this.hashCode() - otherConcept.hashCode();
133 final ToscaEntityType other = (ToscaEntityType) otherConcept;
134 if (!key.equals(other.key)) {
135 return key.compareTo(other.key);
138 if (!derivedFrom.equals(other.derivedFrom)) {
139 return derivedFrom.compareTo(other.derivedFrom);
142 if (!metadata.equals(other.metadata)) {
143 return (metadata.hashCode() - other.metadata.hashCode());
146 return description.compareTo(other.description);
150 public PfConcept copyTo(@NonNull PfConcept target) {
151 final Object copyObject = target;
152 Assertions.instanceOf(copyObject, PfConcept.class);
154 final ToscaEntityType copy = ((ToscaEntityType) copyObject);
155 copy.key = new PfConceptKey(key);
156 copy.derivedFrom = new PfConceptKey(derivedFrom);
158 final Map<String, String> newMatadata = new TreeMap<>();
159 for (final Entry<String, String> metadataEntry : metadata.entrySet()) {
160 newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue());
162 copy.metadata = newMatadata;
164 copy.description = description;