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.clds.tosca.update.ToscaConverterWithDictionarySupport;
44 import org.onap.clamp.loop.Loop;
45 import org.onap.clamp.loop.common.AuditEntity;
46 import org.onap.clamp.policy.Policy;
47 import org.onap.clamp.policy.microservice.MicroServicePolicy;
48 import org.onap.clamp.policy.operational.OperationalPolicy;
51 * This class represents a micro service/operational/... model for a loop template.
52 * So it's an element in the flow (a box shown in the loop).
56 @Table(name = "loop_element_models")
57 public class LoopElementModel extends AuditEntity implements Serializable {
59 * The serial version id.
61 private static final long serialVersionUID = -286522707701376645L;
65 @Column(nullable = false, name = "name", unique = true)
69 @Column(name = "dcae_blueprint_id")
70 private String dcaeBlueprintId;
73 * Here we store the blueprint coming from DCAE, it can be null if this is not a micro service model.
75 @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
76 private String blueprint;
78 public static final String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE";
79 public static final String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE";
81 * The type of element.
83 @Column(nullable = false, name = "loop_element_type")
84 private String loopElementType;
87 * This variable is used to display the micro-service name in the SVG.
90 @Column(name = "short_name")
91 private String shortName;
94 * This variable is used to store the type mentioned in the micro-service
99 fetch = FetchType.EAGER,
100 cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
102 name = "loopelementmodels_to_policymodels",
103 joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
104 inverseJoinColumns = {
105 @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
106 @JoinColumn(name = "policy_model_version", referencedColumnName = "version")})
108 private SortedSet<PolicyModel> policyModels = new TreeSet<>();
110 @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
111 private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
114 * policyModels getter.
116 * @return the policyModel
118 public SortedSet<PolicyModel> getPolicyModels() {
123 * Method to add a new policyModel to the list.
125 * @param policyModel The policy model
127 public void addPolicyModel(PolicyModel policyModel) {
128 policyModels.add(policyModel);
129 policyModel.getUsedByElementModels().add(this);
137 public String getName() {
144 * @param name the name to set
146 public void setName(String name) {
153 * @return the blueprint
155 public String getBlueprint() {
162 * @param blueprint the blueprint to set
164 public void setBlueprint(String blueprint) {
165 this.blueprint = blueprint;
169 * dcaeBlueprintId getter.
171 * @return the dcaeBlueprintId
173 public String getDcaeBlueprintId() {
174 return dcaeBlueprintId;
178 * dcaeBlueprintId setter.
180 * @param dcaeBlueprintId the dcaeBlueprintId to set
182 public void setDcaeBlueprintId(String dcaeBlueprintId) {
183 this.dcaeBlueprintId = dcaeBlueprintId;
187 * loopElementType getter.
189 * @return the loopElementType
191 public String getLoopElementType() {
192 return loopElementType;
196 * loopElementType setter.
198 * @param loopElementType the loopElementType to set
200 public void setLoopElementType(String loopElementType) {
201 this.loopElementType = loopElementType;
207 * @return the shortName
209 public String getShortName() {
214 * @param shortName the shortName to set.
216 public void setShortName(String shortName) {
217 this.shortName = shortName;
221 * usedByLoopTemplates getter.
223 * @return the usedByLoopTemplates
225 public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
226 return usedByLoopTemplates;
230 * Default constructor for serialization.
232 public LoopElementModel() {
238 * @param name The name id
239 * @param loopElementType The type of loop element
240 * @param blueprint The blueprint defined for dcae that contains the
243 public LoopElementModel(String name, String loopElementType, String blueprint) {
245 this.loopElementType = loopElementType;
246 this.blueprint = blueprint;
250 * Create a policy instance from the current loop element model.
252 * @return A Policy object.
254 public Policy createPolicyInstance(Loop loop, ToscaConverterWithDictionarySupport toscaConverter) {
255 if (LoopElementModel.MICRO_SERVICE_TYPE.equals(this.getLoopElementType())) {
256 return new MicroServicePolicy(loop, loop.getModelService(), this, toscaConverter);
258 else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(this.getLoopElementType())) {
259 return new OperationalPolicy(loop, loop.getModelService(), this, toscaConverter);
267 public int hashCode() {
268 final int prime = 31;
270 result = prime * result + ((name == null) ? 0 : name.hashCode());
275 public boolean equals(Object obj) {
282 if (getClass() != obj.getClass()) {
285 LoopElementModel other = (LoopElementModel) obj;
287 if (other.name != null) {
291 else if (!name.equals(other.name)) {