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<TemplateMicroServiceModel> microServiceModelUsed = 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 * microServiceModelUsed getter.
143 * @return the microServiceModelUsed
145 public SortedSet<TemplateMicroServiceModel> getMicroServiceModelUsed() {
146 return microServiceModelUsed;
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 microService model to the current template, the microservice is added
169 * at the end of the list so the flowOrder is computed automatically.
171 * @param microServiceModel The microserviceModel to add
173 public void addMicroServiceModel(MicroServiceModel microServiceModel) {
174 TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel,
175 this.microServiceModelUsed.size());
176 this.microServiceModelUsed.add(jointEntry);
177 microServiceModel.getUsedByLoopTemplates().add(jointEntry);
181 * Add a microService model to the current template, the flow order must be
182 * specified manually.
184 * @param microServiceModel The microserviceModel to add
185 * @param listPosition The position in the flow
187 public void addMicroServiceModel(MicroServiceModel microServiceModel, Integer listPosition) {
188 TemplateMicroServiceModel jointEntry = new TemplateMicroServiceModel(this, microServiceModel, listPosition);
189 this.microServiceModelUsed.add(jointEntry);
190 microServiceModel.getUsedByLoopTemplates().add(jointEntry);
194 * modelService getter.
196 * @return the modelService
198 public Service getModelService() {
203 * modelService setter.
205 * @param modelService the modelService to set
207 public void setModelService(Service modelService) {
208 this.modelService = modelService;
212 * Default constructor for serialization.
214 public LoopTemplate() {
221 * @param name The loop template name id
222 * @param blueprint The blueprint containing all microservices (legacy
224 * @param svgRepresentation The svg representation of that loop template
225 * @param maxInstancesAllowed The maximum number of instances that can be
226 * created from that template
227 * @param service The service associated to that loop template
229 public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed,
232 this.blueprint = blueprint;
233 this.svgRepresentation = svgRepresentation;
235 this.maximumInstancesAllowed = maxInstancesAllowed;
236 this.modelService = service;
240 public int hashCode() {
241 final int prime = 31;
243 result = prime * result + ((name == null) ? 0 : name.hashCode());
248 public boolean equals(Object obj) {
255 if (getClass() != obj.getClass()) {
258 LoopTemplate other = (LoopTemplate) obj;
260 if (other.name != null) {
263 } else if (!name.equals(other.name)) {