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