2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.SortedSet;
30 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.ManyToOne;
39 import javax.persistence.OneToMany;
40 import javax.persistence.Table;
42 import org.hibernate.annotations.SortNatural;
43 import org.onap.clamp.loop.common.AuditEntity;
44 import org.onap.clamp.loop.service.Service;
47 @Table(name = "loop_templates")
48 public class LoopTemplate extends AuditEntity implements Serializable {
51 * The serial version id.
53 private static final long serialVersionUID = -286522707701388642L;
57 @Column(nullable = false, name = "name", unique = true)
61 * This field is used when we have a blueprint defining all microservices. The
62 * other option would be to have independent blueprint for each microservices.
63 * In that case they are stored in each MicroServiceModel
65 @Column(columnDefinition = "MEDIUMTEXT", nullable = false, name = "blueprint_yaml")
66 private String blueprint;
69 @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation")
70 private String svgRepresentation;
73 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "loopTemplate", orphanRemoval = true)
75 private SortedSet<LoopTemplateLoopElementModel> loopElementModelsUsed = new TreeSet<>();
78 @ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
79 @JoinColumn(name = "service_uuid")
80 private Service modelService;
83 @Column(name = "maximum_instances_allowed")
84 private Integer maximumInstancesAllowed;
91 public String getName() {
98 * @param name the name to set
100 public void setName(String name) {
107 * @return the blueprint
109 public String getBlueprint() {
116 * @param blueprint the blueprint to set
118 public void setBlueprint(String blueprint) {
119 this.blueprint = blueprint;
123 * svgRepresentation getter.
125 * @return the svgRepresentation
127 public String getSvgRepresentation() {
128 return svgRepresentation;
132 * svgRepresentation setter.
134 * @param svgRepresentation the svgRepresentation to set
136 public void setSvgRepresentation(String svgRepresentation) {
137 this.svgRepresentation = svgRepresentation;
141 * loopElementModelsUsed getter.
143 * @return the loopElementModelsUsed
145 public SortedSet<LoopTemplateLoopElementModel> getLoopElementModelsUsed() {
146 return loopElementModelsUsed;
150 * maximumInstancesAllowed getter.
152 * @return the maximumInstancesAllowed
154 public Integer getMaximumInstancesAllowed() {
155 return maximumInstancesAllowed;
159 * maximumInstancesAllowed setter.
161 * @param maximumInstancesAllowed the maximumInstancesAllowed to set
163 public void setMaximumInstancesAllowed(Integer maximumInstancesAllowed) {
164 this.maximumInstancesAllowed = maximumInstancesAllowed;
168 * Add a loopElement to the current template, the loopElementModel is added at
169 * the end of the list so the flowOrder is computed automatically.
171 * @param loopElementModel The loopElementModel to add
173 public void addLoopElementModel(LoopElementModel loopElementModel) {
174 LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
175 this.loopElementModelsUsed.size());
176 this.loopElementModelsUsed.add(jointEntry);
177 loopElementModel.getUsedByLoopTemplates().add(jointEntry);
181 * Add a loopElement model to the current template, the flow order must be
182 * specified manually.
184 * @param loopElementModel The loopElementModel to add
185 * @param listPosition The position in the flow
187 public void addLoopElementModel(LoopElementModel loopElementModel, Integer listPosition) {
188 LoopTemplateLoopElementModel jointEntry = new LoopTemplateLoopElementModel(this, loopElementModel,
190 this.loopElementModelsUsed.add(jointEntry);
191 loopElementModel.getUsedByLoopTemplates().add(jointEntry);
195 * modelService getter.
197 * @return the modelService
199 public Service getModelService() {
204 * modelService setter.
206 * @param modelService the modelService to set
208 public void setModelService(Service modelService) {
209 this.modelService = modelService;
213 * Default constructor for serialization.
215 public LoopTemplate() {
222 * @param name The loop template name id
223 * @param blueprint The blueprint containing all microservices (legacy
225 * @param svgRepresentation The svg representation of that loop template
226 * @param maxInstancesAllowed The maximum number of instances that can be
227 * created from that template
228 * @param service The service associated to that loop template
230 public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed,
233 this.blueprint = blueprint;
234 this.svgRepresentation = svgRepresentation;
236 this.maximumInstancesAllowed = maxInstancesAllowed;
237 this.modelService = service;
241 public int hashCode() {
242 final int prime = 31;
244 result = prime * result + ((name == null) ? 0 : name.hashCode());
249 public boolean equals(Object obj) {
256 if (getClass() != obj.getClass()) {
259 LoopTemplate other = (LoopTemplate) obj;
261 if (other.name != null) {
264 } else if (!name.equals(other.name)) {