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 @Column(name = "dcae_blueprint_id")
68 private String dcaeBlueprintId;
71 * Here we store the blueprint coming from DCAE.
73 @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
74 private String blueprint;
77 * The type of element.
79 @Column(nullable = false, name = "loop_element_type")
80 private String loopElementType;
83 * This variable is used to store the type mentioned in the micro-service
87 @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
88 @JoinTable(name = "loopelementmodels_to_policymodels",
89 joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
90 inverseJoinColumns = { @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
91 @JoinColumn(name = "policy_model_version", referencedColumnName = "version") })
93 private SortedSet<PolicyModel> policyModels = new TreeSet<>();
95 @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
96 private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
99 * policyModels getter.
101 * @return the policyModel
103 public SortedSet<PolicyModel> getPolicyModels() {
108 * Method to add a new policyModel to the list.
110 * @param policyModel The policy model
112 public void addPolicyModel(PolicyModel policyModel) {
113 policyModels.add(policyModel);
114 policyModel.getUsedByElementModels().add(this);
122 public String getName() {
129 * @param name the name to set
131 public void setName(String name) {
138 * @return the blueprint
140 public String getBlueprint() {
147 * @param blueprint the blueprint to set
149 public void setBlueprint(String blueprint) {
150 this.blueprint = blueprint;
154 * loopElementType getter.
156 * dcaeBlueprintId getter.
158 * @return the dcaeBlueprintId
160 public String getDcaeBlueprintId() {
161 return dcaeBlueprintId;
165 * dcaeBlueprintId setter.
167 * @param dcaeBlueprintId the dcaeBlueprintId to set
169 public void setDcaeBlueprintId(String dcaeBlueprintId) {
170 this.dcaeBlueprintId = dcaeBlueprintId;
174 * @return the loopElementType
176 public String getLoopElementType() {
177 return loopElementType;
181 * loopElementType setter.
183 * @param loopElementType the loopElementType to set
185 public void setLoopElementType(String loopElementType) {
186 this.loopElementType = loopElementType;
190 * usedByLoopTemplates getter.
192 * @return the usedByLoopTemplates
194 public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
195 return usedByLoopTemplates;
199 * Default constructor for serialization.
201 public LoopElementModel() {
207 * @param name The name id
208 * @param loopElementType The type of loop element
209 * @param blueprint The blueprint defined for dcae that contains the
212 public LoopElementModel(String name, String loopElementType, String blueprint) {
214 this.loopElementType = loopElementType;
215 this.blueprint = blueprint;
219 public int hashCode() {
220 final int prime = 31;
222 result = prime * result + ((name == null) ? 0 : name.hashCode());
227 public boolean equals(Object obj) {
234 if (getClass() != obj.getClass()) {
237 LoopElementModel other = (LoopElementModel) obj;
239 if (other.name != null) {
242 } else if (!name.equals(other.name)) {