2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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;
27 import java.io.Serializable;
28 import java.util.HashSet;
30 import java.util.SortedSet;
31 import java.util.TreeSet;
32 import javax.persistence.CascadeType;
33 import javax.persistence.Column;
34 import javax.persistence.Entity;
35 import javax.persistence.FetchType;
36 import javax.persistence.Id;
37 import javax.persistence.JoinColumn;
38 import javax.persistence.JoinTable;
39 import javax.persistence.ManyToMany;
40 import javax.persistence.OneToMany;
41 import javax.persistence.Table;
42 import org.hibernate.annotations.SortNatural;
43 import org.onap.clamp.loop.common.AuditEntity;
46 * This class represents a micro service model for a loop template.
50 @Table(name = "loop_element_models")
51 public class LoopElementModel extends AuditEntity implements Serializable {
52 public static final String DEFAULT_GROUP_NAME = "DEFAULT";
54 * The serial version id.
56 private static final long serialVersionUID = -286522707701376645L;
60 @Column(nullable = false, name = "name", unique = true)
64 @Column(name = "dcae_blueprint_id")
65 private String dcaeBlueprintId;
68 * Here we store the blueprint coming from DCAE.
70 @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
71 private String blueprint;
74 * The type of element.
76 @Column(nullable = false, name = "loop_element_type")
77 private String loopElementType;
80 * This variable is used to display the micro-service name in the SVG.
83 @Column(name = "short_name")
84 private String shortName;
87 * This variable is used to store the type mentioned in the micro-service
92 fetch = FetchType.EAGER,
93 cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
95 name = "loopelementmodels_to_policymodels",
96 joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
97 inverseJoinColumns = {
98 @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
99 @JoinColumn(name = "policy_model_version", referencedColumnName = "version")})
101 private SortedSet<PolicyModel> policyModels = new TreeSet<>();
103 @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
104 private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
107 * policyModels getter.
109 * @return the policyModel
111 public SortedSet<PolicyModel> getPolicyModels() {
116 * Method to add a new policyModel to the list.
118 * @param policyModel The policy model
120 public void addPolicyModel(PolicyModel policyModel) {
121 policyModels.add(policyModel);
122 policyModel.getUsedByElementModels().add(this);
130 public String getName() {
137 * @param name the name to set
139 public void setName(String name) {
146 * @return the blueprint
148 public String getBlueprint() {
155 * @param blueprint the blueprint to set
157 public void setBlueprint(String blueprint) {
158 this.blueprint = blueprint;
162 * dcaeBlueprintId getter.
164 * @return the dcaeBlueprintId
166 public String getDcaeBlueprintId() {
167 return dcaeBlueprintId;
171 * dcaeBlueprintId setter.
173 * @param dcaeBlueprintId the dcaeBlueprintId to set
175 public void setDcaeBlueprintId(String dcaeBlueprintId) {
176 this.dcaeBlueprintId = dcaeBlueprintId;
180 * loopElementType getter.
182 * @return the loopElementType
184 public String getLoopElementType() {
185 return loopElementType;
189 * loopElementType setter.
191 * @param loopElementType the loopElementType to set
193 public void setLoopElementType(String loopElementType) {
194 this.loopElementType = loopElementType;
200 * @return the shortName
202 public String getShortName() {
207 * @param shortName the shortName to set.
209 public void setShortName(String shortName) {
210 this.shortName = shortName;
214 * usedByLoopTemplates getter.
216 * @return the usedByLoopTemplates
218 public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
219 return usedByLoopTemplates;
223 * Default constructor for serialization.
225 public LoopElementModel() {
231 * @param name The name id
232 * @param loopElementType The type of loop element
233 * @param blueprint The blueprint defined for dcae that contains the
236 public LoopElementModel(String name, String loopElementType, String blueprint) {
238 this.loopElementType = loopElementType;
239 this.blueprint = blueprint;
243 public int hashCode() {
244 final int prime = 31;
246 result = prime * result + ((name == null) ? 0 : name.hashCode());
251 public boolean equals(Object obj) {
258 if (getClass() != obj.getClass()) {
261 LoopElementModel other = (LoopElementModel) obj;
263 if (other.name != null) {
266 } else if (!name.equals(other.name)) {