Merge "Remove MsoLogger from MSOCommonBPMN scripts"
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / Service.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.db.catalog.beans;
22
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.persistence.CascadeType;
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.Id;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.JoinTable;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.MapKey;
37 import javax.persistence.OneToMany;
38 import javax.persistence.PrePersist;
39 import javax.persistence.Table;
40 import javax.persistence.Temporal;
41 import javax.persistence.TemporalType;
42
43 import org.apache.commons.lang3.builder.EqualsBuilder;
44 import org.apache.commons.lang3.builder.HashCodeBuilder;
45 import org.apache.commons.lang3.builder.ToStringBuilder;
46
47 import com.fasterxml.jackson.annotation.JsonFormat;
48 import com.openpojo.business.annotation.BusinessKey;
49
50 import uk.co.blackpepper.bowman.annotation.LinkedResource;
51
52 @Entity
53 @Table(name = "service")
54 public class Service implements Serializable {
55
56     private static final long serialVersionUID = 768026109321305392L;
57
58     @Column(name = "MODEL_NAME")
59     private String modelName;
60
61     @Column(name = "DESCRIPTION", length = 1200)
62     private String description;
63
64     @BusinessKey
65     @Id
66     @Column(name = "MODEL_UUID")
67     private String modelUUID;
68
69     @Column(name = "MODEL_INVARIANT_UUID")
70     private String modelInvariantUUID;
71
72     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
73     @Column(name = "CREATION_TIMESTAMP", updatable = false)
74     @Temporal(TemporalType.TIMESTAMP)
75     private Date created;
76
77     @Column(name = "MODEL_VERSION")
78     private String modelVersion;
79
80     @Column(name = "SERVICE_TYPE")
81     private String serviceType;
82
83     @Column(name = "SERVICE_ROLE")
84     private String serviceRole;
85
86     @Column(name = "ENVIRONMENT_CONTEXT")
87     private String environmentContext;
88
89     @Column(name = "WORKLOAD_CONTEXT")
90     private String workloadContext;
91
92     @Column(name = "SERVICE_CATEGORY")
93     private String category;
94
95     @Column(name = "RESOURCE_ORDER")
96     private String resourceOrder;
97
98     @OneToMany(cascade = CascadeType.ALL)
99     @JoinTable(name = "network_resource_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
100     private List<NetworkResourceCustomization> networkCustomizations;
101
102     @OneToMany(cascade = CascadeType.ALL)
103     @JoinTable(name = "vnf_resource_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
104     private List<VnfResourceCustomization> vnfCustomizations;
105
106     @OneToMany(cascade = CascadeType.ALL)
107     @JoinTable(name = "allotted_resource_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
108     private List<AllottedResourceCustomization> allottedCustomizations;
109
110     @OneToMany(cascade = CascadeType.ALL)
111     @JoinTable(name = "collection_resource_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
112     private List<CollectionResourceCustomization> collectionResourceCustomizations;
113
114     @OneToMany(cascade = CascadeType.ALL)
115     @JoinTable(name = "service_proxy_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
116     private List<ServiceProxyResourceCustomization> serviceProxyCustomizations;
117
118     @OneToMany(cascade = CascadeType.ALL)
119     @JoinTable(name = "configuration_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
120     private List<ConfigurationResourceCustomization> configurationCustomizations;
121
122     @OneToMany(cascade = CascadeType.ALL)
123     @JoinTable(name = "pnf_resource_customization_to_service", joinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"), inverseJoinColumns = @JoinColumn(name = "RESOURCE_MODEL_CUSTOMIZATION_UUID"))
124     private List<PnfResourceCustomization> pnfCustomizations;
125
126     @OneToMany(cascade = CascadeType.ALL, mappedBy = "service")
127     @MapKey(name = "action")
128     private Map<String, ServiceRecipe> recipes;
129
130     @ManyToOne(cascade = CascadeType.ALL)
131     @JoinColumn(name = "TOSCA_CSAR_ARTIFACT_UUID")
132     private ToscaCsar csar;
133
134     @Override
135     public String toString() {
136         return new ToStringBuilder(this).append("modelName", modelName).append("description", description)
137             .append("modelUUID", modelUUID).append("modelInvariantUUID", modelInvariantUUID)
138             .append("created", created).append("modelVersion", modelVersion).append("serviceType", serviceType)
139             .append("serviceRole", serviceRole).append("environmentContext", environmentContext)
140             .append("workloadContext", workloadContext).append("category", category)
141             .append("networkCustomizations", networkCustomizations).append("vnfCustomizations", vnfCustomizations)
142             .append("allottedCustomizations", allottedCustomizations)
143             .append("collectionResourceCustomizations", collectionResourceCustomizations)
144             .append("serviceProxyCustomizations", serviceProxyCustomizations)
145             .append("configurationCustomizations", configurationCustomizations)
146             .append("pnfCustomizations", pnfCustomizations)
147             .append("recipes", recipes)
148             .append("csar", csar).toString();
149     }
150
151     @PrePersist
152     protected void onCreate() {
153         this.created = new Date();
154     }
155
156     @Override
157     public boolean equals(final Object other) {
158         if (!(other instanceof Service)) {
159             return false;
160         }
161         Service castOther = (Service) other;
162         return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
163     }
164
165     @Override
166     public int hashCode() {
167         return new HashCodeBuilder().append(modelUUID).toHashCode();
168     }
169
170     @LinkedResource
171     public List<ServiceProxyResourceCustomization> getServiceProxyCustomizations() {
172         return serviceProxyCustomizations;
173     }
174
175     public void setServiceProxyCustomizations(List<ServiceProxyResourceCustomization> serviceProxyCustomizations) {
176         this.serviceProxyCustomizations = serviceProxyCustomizations;
177     }
178
179     @LinkedResource
180     public List<NetworkResourceCustomization> getNetworkCustomizations() {
181         if (networkCustomizations == null) {
182             networkCustomizations = new ArrayList<>();
183         }
184         return networkCustomizations;
185     }
186
187     public void setNetworkCustomizations(List<NetworkResourceCustomization> networkCustomizations) {
188         this.networkCustomizations = networkCustomizations;
189     }
190
191     @LinkedResource
192     public List<VnfResourceCustomization> getVnfCustomizations() {
193         if (vnfCustomizations == null) {
194             vnfCustomizations = new ArrayList<>();
195         }
196         return vnfCustomizations;
197     }
198
199     public void setVnfCustomizations(List<VnfResourceCustomization> vnfCustomizations) {
200         this.vnfCustomizations = vnfCustomizations;
201     }
202
203     @LinkedResource
204     public List<AllottedResourceCustomization> getAllottedCustomizations() {
205         if (allottedCustomizations == null) {
206             allottedCustomizations = new ArrayList<>();
207         }
208         return allottedCustomizations;
209     }
210
211     public void setAllottedCustomizations(List<AllottedResourceCustomization> allotedCustomizations) {
212         this.allottedCustomizations = allotedCustomizations;
213     }
214
215     @LinkedResource
216     public List<CollectionResourceCustomization> getCollectionResourceCustomizations() {
217         if (collectionResourceCustomizations == null) {
218             collectionResourceCustomizations = new ArrayList<>();
219         }
220         return collectionResourceCustomizations;
221     }
222
223     public void setCollectionResourceCustomizations(
224         List<CollectionResourceCustomization> collectionResourceCustomizations) {
225         this.collectionResourceCustomizations = collectionResourceCustomizations;
226     }
227
228     @LinkedResource
229     public List<ConfigurationResourceCustomization> getConfigurationCustomizations() {
230         if (configurationCustomizations == null) {
231             configurationCustomizations = new ArrayList<>();
232         }
233         return configurationCustomizations;
234     }
235
236     public void setConfigurationCustomizations(List<ConfigurationResourceCustomization> configurationCustomizations) {
237         this.configurationCustomizations = configurationCustomizations;
238     }
239
240     @LinkedResource
241     public List<PnfResourceCustomization> getPnfCustomizations() {
242         if (pnfCustomizations == null) {
243             pnfCustomizations = new ArrayList<>();
244         }
245         return pnfCustomizations;
246     }
247
248     public void setPnfCustomizations(List<PnfResourceCustomization> pnfCustomizations) {
249         this.pnfCustomizations = pnfCustomizations;
250     }
251
252     public String getModelName() {
253         return modelName;
254     }
255
256     public void setModelName(String modelName) {
257         this.modelName = modelName;
258     }
259
260     public String getDescription() {
261         return description;
262     }
263
264     public void setDescription(String description) {
265         this.description = description;
266     }
267
268     @LinkedResource
269     public Map<String, ServiceRecipe> getRecipes() {
270         return recipes;
271     }
272
273     public void setRecipes(Map<String, ServiceRecipe> recipes) {
274         this.recipes = recipes;
275     }
276
277     public Date getCreated() {
278         return created;
279     }
280
281     public String getModelUUID() {
282         return modelUUID;
283     }
284
285     public void setModelUUID(String modelUUID) {
286         this.modelUUID = modelUUID;
287     }
288
289     public String getModelInvariantUUID() {
290         return modelInvariantUUID;
291     }
292
293     public void setModelInvariantUUID(String modelInvariantUUID) {
294         this.modelInvariantUUID = modelInvariantUUID;
295     }
296
297     public String getModelVersion() {
298         return modelVersion;
299     }
300
301     public void setModelVersion(String modelVersion) {
302         this.modelVersion = modelVersion;
303     }
304
305     /**
306      * @return Returns the category.
307      */
308     public String getCategory() {
309         return category;
310     }
311
312     /**
313      * @param category The category to set.
314      */
315     public void setCategory(String category) {
316         this.category = category;
317     }
318
319     public String getServiceType() {
320         return serviceType;
321     }
322
323     public void setServiceType(String serviceType) {
324         this.serviceType = serviceType;
325     }
326
327     public String getServiceRole() {
328         return serviceRole;
329     }
330
331     public void setServiceRole(String serviceRole) {
332         this.serviceRole = serviceRole;
333     }
334
335     public String getEnvironmentContext() {
336         return this.environmentContext;
337     }
338
339     public void setEnvironmentContext(String environmentContext) {
340         this.environmentContext = environmentContext;
341     }
342
343     @LinkedResource
344     public ToscaCsar getCsar() {
345         return csar;
346     }
347
348     public void setCsar(ToscaCsar csar) {
349         this.csar = csar;
350     }
351
352     public String getWorkloadContext() {
353         return this.workloadContext;
354     }
355
356     public void setWorkloadContext(String workloadContext) {
357         this.workloadContext = workloadContext;
358     }
359
360     public String getResourceOrder() {
361         return resourceOrder;
362     }
363
364     public void setResourceOrder(String resourceOrder) {
365         this.resourceOrder = resourceOrder;
366     }
367 }