2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.loop.template;
26 import com.google.gson.annotations.Expose;
28 import java.io.Serializable;
29 import java.util.HashSet;
32 import javax.persistence.Column;
33 import javax.persistence.Entity;
34 import javax.persistence.FetchType;
35 import javax.persistence.Id;
36 import javax.persistence.IdClass;
37 import javax.persistence.ManyToMany;
38 import javax.persistence.Table;
40 import org.onap.clamp.loop.common.AuditEntity;
41 import org.onap.clamp.util.SemanticVersioning;
44 * This class represents the policy model tosca revision that we can have to a
45 * specific microservice.
48 @Table(name = "policy_models")
49 @IdClass(PolicyModelId.class)
50 public class PolicyModel extends AuditEntity implements Serializable, Comparable<PolicyModel> {
53 * The serial version id.
55 private static final long serialVersionUID = -286522705701376645L;
58 * This variable is used to store the type mentioned in the micro-service
63 @Column(nullable = false, name = "policy_model_type")
64 private String policyModelType;
67 * Semantic versioning on policy side.
71 @Column(name = "version")
72 private String version;
74 @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca")
75 private String policyModelTosca;
78 @Column(name = "policy_acronym")
79 private String policyAcronym;
81 @ManyToMany(mappedBy = "policyModels", fetch = FetchType.EAGER)
82 private Set<LoopElementModel> usedByElementModels = new HashSet<>();
85 * @return the usedByElementModels
87 public Set<LoopElementModel> getUsedByElementModels() {
88 return usedByElementModels;
92 * policyModelTosca getter.
94 * @return the policyModelTosca
96 public String getPolicyModelTosca() {
97 return policyModelTosca;
101 * policyModelTosca setter.
103 * @param policyModelTosca the policyModelTosca to set
105 public void setPolicyModelTosca(String policyModelTosca) {
106 this.policyModelTosca = policyModelTosca;
110 * policyModelType getter.
112 * @return the modelType
114 public String getPolicyModelType() {
115 return policyModelType;
119 * policyModelType setter.
121 * @param modelType the modelType to set
123 public void setPolicyModelType(String modelType) {
124 this.policyModelType = modelType;
130 * @return the version
132 public String getVersion() {
139 * @param version the version to set
141 public void setVersion(String version) {
142 // Try to convert it before
143 this.version = version;
147 * policyAcronym getter.
149 * @return the policyAcronym value
151 public String getPolicyAcronym() {
152 return policyAcronym;
156 * policyAcronym setter.
158 * @param policyAcronym The policyAcronym to set
160 public void setPolicyAcronym(String policyAcronym) {
161 this.policyAcronym = policyAcronym;
165 * Default constructor for serialization.
167 public PolicyModel() {
173 * @param policyType The policyType (referenced in the blueprint)
174 * @param policyModelTosca The policy tosca model in yaml
175 * @param version the version like 1.0.0
176 * @param policyVariant Subtype for policy if it exists (could be used by UI)
178 public PolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym) {
179 this.policyModelType = policyType;
180 this.policyModelTosca = policyModelTosca;
181 this.version = version;
182 this.policyAcronym = policyAcronym;
186 public int hashCode() {
187 final int prime = 31;
189 result = prime * result + ((policyModelType == null) ? 0 : policyModelType.hashCode());
190 result = prime * result + ((version == null) ? 0 : version.hashCode());
195 public boolean equals(Object obj) {
202 if (getClass() != obj.getClass()) {
205 PolicyModel other = (PolicyModel) obj;
206 if (policyModelType == null) {
207 if (other.policyModelType != null) {
210 } else if (!policyModelType.equals(other.policyModelType)) {
213 if (version == null) {
214 if (other.version != null) {
217 } else if (!version.equals(other.version)) {
224 public int compareTo(PolicyModel arg0) {
225 // Reverse it, so that by default we have the latest
226 return SemanticVersioning.compare(arg0.getVersion(), this.version);