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