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.IOException;
28 import java.io.Serializable;
29 import java.util.HashSet;
31 import java.util.SortedSet;
32 import java.util.TreeSet;
33 import javax.persistence.CascadeType;
34 import javax.persistence.Column;
35 import javax.persistence.Entity;
36 import javax.persistence.FetchType;
37 import javax.persistence.Id;
38 import javax.persistence.JoinColumn;
39 import javax.persistence.JoinTable;
40 import javax.persistence.ManyToMany;
41 import javax.persistence.OneToMany;
42 import javax.persistence.Table;
43 import org.hibernate.annotations.SortNatural;
44 import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport;
45 import org.onap.clamp.loop.Loop;
46 import org.onap.clamp.loop.common.AuditEntity;
47 import org.onap.clamp.policy.Policy;
48 import org.onap.clamp.policy.microservice.MicroServicePolicy;
49 import org.onap.clamp.policy.operational.OperationalPolicy;
52 * This class represents a micro service/operational/... model for a loop template.
53 * So it's an element in the flow (a box shown in the loop).
57 @Table(name = "loop_element_models")
58 public class LoopElementModel extends AuditEntity implements Serializable {
60 * The serial version id.
62 private static final long serialVersionUID = -286522707701376645L;
66 @Column(nullable = false, name = "name", unique = true)
70 @Column(name = "dcae_blueprint_id")
71 private String dcaeBlueprintId;
74 * Here we store the blueprint coming from DCAE, it can be null if this is not a micro service model.
76 @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml")
77 private String blueprint;
79 public static String MICRO_SERVICE_TYPE = "MICRO_SERVICE_TYPE";
80 public static String OPERATIONAL_POLICY_TYPE = "OPERATIONAL_POLICY_TYPE";
82 * The type of element.
84 @Column(nullable = false, name = "loop_element_type")
85 private String loopElementType;
88 * This variable is used to display the micro-service name in the SVG.
91 @Column(name = "short_name")
92 private String shortName;
95 * This variable is used to store the type mentioned in the micro-service
100 fetch = FetchType.EAGER,
101 cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
103 name = "loopelementmodels_to_policymodels",
104 joinColumns = @JoinColumn(name = "loop_element_name", referencedColumnName = "name"),
105 inverseJoinColumns = {
106 @JoinColumn(name = "policy_model_type", referencedColumnName = "policy_model_type"),
107 @JoinColumn(name = "policy_model_version", referencedColumnName = "version")})
109 private SortedSet<PolicyModel> policyModels = new TreeSet<>();
111 @OneToMany(fetch = FetchType.LAZY, mappedBy = "loopElementModel", orphanRemoval = true)
112 private Set<LoopTemplateLoopElementModel> usedByLoopTemplates = new HashSet<>();
115 * policyModels getter.
117 * @return the policyModel
119 public SortedSet<PolicyModel> getPolicyModels() {
124 * Method to add a new policyModel to the list.
126 * @param policyModel The policy model
128 public void addPolicyModel(PolicyModel policyModel) {
129 policyModels.add(policyModel);
130 policyModel.getUsedByElementModels().add(this);
138 public String getName() {
145 * @param name the name to set
147 public void setName(String name) {
154 * @return the blueprint
156 public String getBlueprint() {
163 * @param blueprint the blueprint to set
165 public void setBlueprint(String blueprint) {
166 this.blueprint = blueprint;
170 * dcaeBlueprintId getter.
172 * @return the dcaeBlueprintId
174 public String getDcaeBlueprintId() {
175 return dcaeBlueprintId;
179 * dcaeBlueprintId setter.
181 * @param dcaeBlueprintId the dcaeBlueprintId to set
183 public void setDcaeBlueprintId(String dcaeBlueprintId) {
184 this.dcaeBlueprintId = dcaeBlueprintId;
188 * loopElementType getter.
190 * @return the loopElementType
192 public String getLoopElementType() {
193 return loopElementType;
197 * loopElementType setter.
199 * @param loopElementType the loopElementType to set
201 public void setLoopElementType(String loopElementType) {
202 this.loopElementType = loopElementType;
208 * @return the shortName
210 public String getShortName() {
215 * @param shortName the shortName to set.
217 public void setShortName(String shortName) {
218 this.shortName = shortName;
222 * usedByLoopTemplates getter.
224 * @return the usedByLoopTemplates
226 public Set<LoopTemplateLoopElementModel> getUsedByLoopTemplates() {
227 return usedByLoopTemplates;
231 * Default constructor for serialization.
233 public LoopElementModel() {
239 * @param name The name id
240 * @param loopElementType The type of loop element
241 * @param blueprint The blueprint defined for dcae that contains the
244 public LoopElementModel(String name, String loopElementType, String blueprint) {
246 this.loopElementType = loopElementType;
247 this.blueprint = blueprint;
251 * Create a policy instance from the current loop element model.
253 * @return A Policy object.
254 * @throws IOException in case of failure when creating an operational policy
256 public Policy createPolicyInstance(Loop loop, ToscaConverterWithDictionarySupport toscaConverter)
258 if (LoopElementModel.MICRO_SERVICE_TYPE.equals(this.getLoopElementType())) {
259 return new MicroServicePolicy(loop, loop.getModelService(), this, toscaConverter);
261 else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(this.getLoopElementType())) {
262 return new OperationalPolicy(loop, loop.getModelService(), this, toscaConverter);
269 public int hashCode() {
270 final int prime = 31;
272 result = prime * result + ((name == null) ? 0 : name.hashCode());
277 public boolean equals(Object obj) {
284 if (getClass() != obj.getClass()) {
287 LoopElementModel other = (LoopElementModel) obj;
289 if (other.name != null) {
293 else if (!name.equals(other.name)) {