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;
28 import java.io.Serializable;
29 import java.util.HashSet;
31 import java.util.SortedSet;
32 import java.util.TreeSet;
34 import javax.persistence.CascadeType;
35 import javax.persistence.Column;
36 import javax.persistence.Entity;
37 import javax.persistence.FetchType;
38 import javax.persistence.Id;
39 import javax.persistence.JoinColumn;
40 import javax.persistence.JoinTable;
41 import javax.persistence.ManyToMany;
42 import javax.persistence.OneToMany;
43 import javax.persistence.Table;
45 import org.hibernate.annotations.SortNatural;
46 import org.onap.clamp.loop.common.AuditEntity;
49 * This class represents a micro service model for a loop template.
53 @Table(name = "loop_element_models")
54 public class LoopElementModel extends AuditEntity implements Serializable {
55 public static final String DEFAULT_GROUP_NAME = "DEFAULT";
57 * The serial version id.
59 private static final long serialVersionUID = -286522707701376645L;
63 @Column(nullable = false, name = "name", unique = true)
67 * Here we store the blueprint coming from DCAE.
69 @Column(nullable = false, name = "blueprint_yaml")
70 private String blueprint;
75 @Column(nullable = false, name = "loop_element_type")
76 private String loopElementType;
79 * This variable is used to store the type mentioned in the micro-service
83 @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
84 @JoinTable(name = "loopelementmodels_to_policymodels",
85 joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
86 inverseJoinColumns = { @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
87 @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
89 private SortedSet<PolicyModel> policyModels = new TreeSet<>();
91 @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
92 private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
95 * policyModels getter.
97 * @return the policyModel
99 public SortedSet<PolicyModel> getPolicyModels() {
104 * Method to add a new policyModel to the list.
108 public void addPolicyModel(PolicyModel policyModel) {
109 policyModels.add(policyModel);
110 policyModel.getUsedByElementModels().add(this);
118 public String getName() {
125 * @param name the name to set
127 public void setName(String name) {
134 * @return the blueprint
136 public String getBlueprint() {
143 * @param blueprint the blueprint to set
145 public void setBlueprint(String blueprint) {
146 this.blueprint = blueprint;
150 * @return the loopElementType
152 public String getLoopElementType() {
153 return loopElementType;
157 * @param loopElementType the loopElementType to set
159 public void setLoopElementType(String loopElementType) {
160 this.loopElementType = loopElementType;
164 * usedByLoopTemplates getter.
166 * @return the usedByLoopTemplates
168 public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
169 return usedByLoopTemplates;
173 * Default constructor for serialization.
175 public LoopElementModel() {
181 * @param name The name id
182 * @param loopElementType The type of loop element
183 * @param blueprint The blueprint defined for dcae that contains the
186 public LoopElementModel(String name, String loopElementType, String blueprint) {
188 this.loopElementType = loopElementType;
189 this.blueprint = blueprint;
193 public int hashCode() {
194 final int prime = 31;
196 result = prime * result + ((name == null) ? 0 : name.hashCode());
201 public boolean equals(Object obj) {
208 if (getClass() != obj.getClass()) {
211 LoopElementModel other = (LoopElementModel) obj;
213 if (other.name != null) {
216 } else if (!name.equals(other.name)) {