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;
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.Id;
33 import javax.persistence.IdClass;
34 import javax.persistence.Table;
36 import org.onap.clamp.loop.common.AuditEntity;
37 import org.onap.clamp.util.SemanticVersioning;
40 * This class represents the policy model tosca revision that we can have to a
41 * specific microservice.
44 @Table(name = "policy_models")
45 @IdClass(PolicyModelId.class)
46 public class PolicyModel extends AuditEntity implements Serializable, Comparable<PolicyModel> {
49 * The serial version id.
51 private static final long serialVersionUID = -286522705701376645L;
54 * This variable is used to store the type mentioned in the micro-service
59 @Column(nullable = false, name = "policy_model_type")
60 private String policyModelType;
63 * Semantic versioning on policy side.
67 @Column(name = "version")
68 private String version;
70 @Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca")
71 private String policyModelTosca;
74 @Column(name = "policy_acronym")
75 private String policyAcronym;
78 @Column(name = "policy_variant")
79 private String policyVariant;
82 * policyModelTosca getter.
84 * @return the policyModelTosca
86 public String getPolicyModelTosca() {
87 return policyModelTosca;
91 * policyModelTosca setter.
93 * @param policyModelTosca the policyModelTosca to set
95 public void setPolicyModelTosca(String policyModelTosca) {
96 this.policyModelTosca = policyModelTosca;
100 * policyModelType getter.
102 * @return the modelType
104 public String getPolicyModelType() {
105 return policyModelType;
109 * policyModelType setter.
111 * @param modelType the modelType to set
113 public void setPolicyModelType(String modelType) {
114 this.policyModelType = modelType;
120 * @return the version
122 public String getVersion() {
129 * @param version the version to set
131 public void setVersion(String version) {
132 // Try to convert it before
133 this.version = version;
137 * policyAcronym getter.
139 * @return the policyAcronym value
141 public String getPolicyAcronym() {
142 return policyAcronym;
146 * policyAcronym setter.
148 * @param policyAcronym The policyAcronym to set
150 public void setPolicyAcronym(String policyAcronym) {
151 this.policyAcronym = policyAcronym;
155 * policyVariant getter.
157 * @return the policyVariant value
159 public String getPolicyVariant() {
160 return policyVariant;
164 * policyVariant setter.
166 * @param policyVariant The policyVariant to set
168 public void setPolicyVariant(String policyVariant) {
169 this.policyVariant = policyVariant;
173 * Default constructor for serialization.
175 public PolicyModel() {
181 * @param policyType The policyType (referenced in the blueprint)
182 * @param policyModelTosca The policy tosca model in yaml
183 * @param version the version like 1.0.0
184 * @param policyAcronym Short policy name if it exists
185 * @param policyVariant Subtype for policy if it exists (could be used by UI)
187 public PolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
188 String policyVariant) {
189 this.policyModelType = policyType;
190 this.policyModelTosca = policyModelTosca;
191 this.version = version;
192 this.policyAcronym = policyAcronym;
193 this.policyVariant = policyVariant;
197 public int hashCode() {
198 final int prime = 31;
200 result = prime * result + ((policyModelType == null) ? 0 : policyModelType.hashCode());
201 result = prime * result + ((version == null) ? 0 : version.hashCode());
206 public boolean equals(Object obj) {
213 if (getClass() != obj.getClass()) {
216 PolicyModel other = (PolicyModel) obj;
217 if (policyModelType == null) {
218 if (other.policyModelType != null) {
221 } else if (!policyModelType.equals(other.policyModelType)) {
224 if (version == null) {
225 if (other.version != null) {
228 } else if (!version.equals(other.version)) {
235 public int compareTo(PolicyModel arg0) {
236 // Reverse it, so that by default we have the latest
237 return SemanticVersioning.compare(arg0.getVersion(), this.version);