c31cd61ce075846eeeef6c3929f5402fb11fd744
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / NetworkResource.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.text.DateFormat;
25 import java.util.ArrayList;
26 import java.util.Date;
27 import java.util.List;
28
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.ManyToOne;
36 import javax.persistence.OneToMany;
37 import javax.persistence.PrePersist;
38 import javax.persistence.Table;
39 import javax.persistence.Temporal;
40 import javax.persistence.TemporalType;
41
42 import org.apache.commons.lang3.builder.EqualsBuilder;
43 import org.apache.commons.lang3.builder.HashCodeBuilder;
44
45 import com.openpojo.business.annotation.BusinessKey;
46
47 import uk.co.blackpepper.bowman.annotation.LinkedResource;
48
49 @Entity
50 @Table(name = "network_resource")
51 public class NetworkResource implements Serializable {
52
53         private static final long serialVersionUID = 768026109321305392L;
54
55         @BusinessKey
56         @Id
57         @Column(name = "MODEL_UUID")
58         private String modelUUID;
59
60         @Column(name = "ORCHESTRATION_MODE")
61         private String orchestrationMode = null;
62
63         @Column(name = "DESCRIPTION")
64         private String description = null;
65
66         @Column(name = "NEUTRON_NETWORK_TYPE")
67         private String neutronNetworkType = null;
68
69         @Column(name = "AIC_VERSION_MIN")
70         private String aicVersionMin = null;
71
72         @Column(name = "AIC_VERSION_MAX")
73         private String aicVersionMax = null;
74
75         @Column(name = "MODEL_NAME")
76         private String modelName;
77
78         @Column(name = "MODEL_INVARIANT_UUID")
79         private String modelInvariantUUID;
80
81         @Column(name = "MODEL_VERSION")
82         private String modelVersion;
83
84         @Column(name = "TOSCA_NODE_TYPE")
85         private String toscaNodeType;
86
87         @Column(name = "RESOURCE_CATEGORY")
88         private String category;
89
90         @Column(name = "RESOURCE_SUB_CATEGORY")
91         private String subCategory;
92
93         @Column(name = "CREATION_TIMESTAMP", updatable = false)
94         @Temporal(TemporalType.TIMESTAMP)
95         private Date created;
96
97         @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "networkResource")
98         private List<NetworkResourceCustomization> networkResourceCustomization;
99
100         @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "networkResource")
101         private List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomization;
102
103         @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
104         @JoinColumn(name = "HEAT_TEMPLATE_ARTIFACT_UUID")
105         private HeatTemplate heatTemplate;
106
107         @PrePersist
108         protected void onCreate() {
109                 this.created = new Date();
110         }
111
112         @Override
113         public boolean equals(final Object other) {
114                 if (!(other instanceof NetworkResource)) {
115                         return false;
116                 }
117                 NetworkResource castOther = (NetworkResource) other;
118                 return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
119         }
120
121         @Override
122         public int hashCode() {
123                 return new HashCodeBuilder().append(modelUUID).toHashCode();
124         }
125
126         @LinkedResource
127         public List<NetworkResourceCustomization> getNetworkResourceCustomization() {
128                 return networkResourceCustomization;
129         }
130
131         public void addNetworkResourceCustomization(NetworkResourceCustomization networkResourceCustomization) {
132                 if (this.networkResourceCustomization == null)
133                         this.networkResourceCustomization = new ArrayList<>();
134
135                 this.networkResourceCustomization.add(networkResourceCustomization);
136         }
137
138         public void setNetworkResourceCustomization(List<NetworkResourceCustomization> networkResourceCustomization) {
139                 this.networkResourceCustomization = networkResourceCustomization;
140         }
141
142         @LinkedResource
143         public List<CollectionNetworkResourceCustomization> getCollectionNetworkResourceCustomization() {
144                 return collectionNetworkResourceCustomization;
145         }
146
147         public void setCollectionNetworkResourceCustomization(
148                         List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomization) {
149                 this.collectionNetworkResourceCustomization = collectionNetworkResourceCustomization;
150         }
151
152         public String getOrchestrationMode() {
153                 return orchestrationMode;
154         }
155
156         public void setOrchestrationMode(String orchestrationMode) {
157                 this.orchestrationMode = orchestrationMode;
158         }
159
160         public String getDescription() {
161                 return description;
162         }
163
164         public void setDescription(String description) {
165                 this.description = description;
166         }
167
168         public String getNeutronNetworkType() {
169                 return neutronNetworkType;
170         }
171
172         public void setNeutronNetworkType(String neutronNetworkType) {
173                 this.neutronNetworkType = neutronNetworkType;
174         }
175
176         public Date getCreated() {
177                 return created;
178         }
179
180         public String getAicVersionMin() {
181                 return aicVersionMin;
182         }
183
184         public void setAicVersionMin(String aicVersionMin) {
185                 this.aicVersionMin = aicVersionMin;
186         }
187
188         public String getAicVersionMax() {
189                 return aicVersionMax;
190         }
191
192         public void setAicVersionMax(String aicVersionMax) {
193                 this.aicVersionMax = aicVersionMax;
194         }
195
196         public String getModelName() {
197                 return modelName;
198         }
199
200         public void setModelName(String modelName) {
201                 this.modelName = modelName;
202         }
203
204         public String getModelInvariantUUID() {
205                 return modelInvariantUUID;
206         }
207
208         public void setModelInvariantUUID(String modelInvariantUUID) {
209                 this.modelInvariantUUID = modelInvariantUUID;
210         }
211
212         public String getToscaNodeType() {
213                 return toscaNodeType;
214         }
215
216         public void setToscaNodeType(String toscaNodeType) {
217                 this.toscaNodeType = toscaNodeType;
218         }
219
220         public String getModelUUID() {
221                 return modelUUID;
222         }
223
224         public void setModelUUID(String modelUUID) {
225                 this.modelUUID = modelUUID;
226         }
227
228         /**
229          * @return Returns the category.
230          */
231         public String getCategory() {
232                 return category;
233         }
234
235         /**
236          * @param category
237          *            The category to set.
238          */
239         public void setCategory(String category) {
240                 this.category = category;
241         }
242
243         /**
244          * @return Returns the subCategory.
245          */
246         public String getSubCategory() {
247                 return subCategory;
248         }
249
250         /**
251          * @param subCategory
252          *            The subCategory to set.
253          */
254         public void setSubCategory(String subCategory) {
255                 this.subCategory = subCategory;
256         }
257
258         @LinkedResource
259         public HeatTemplate getHeatTemplate() {
260                 return heatTemplate;
261         }
262
263         public void setHeatTemplate(HeatTemplate heatTemplate) {
264                 this.heatTemplate = heatTemplate;
265         }
266
267         public String getModelVersion() {
268                 return modelVersion;
269         }
270
271         public void setModelVersion(String modelVersion) {
272                 this.modelVersion = modelVersion;
273         }
274
275         @Override
276         public String toString() {
277                 StringBuilder sb = new StringBuilder();
278                 sb.append("NETWORK Resource:");
279                 sb.append("modelVersion=");
280                 sb.append(modelVersion);
281                 sb.append(",mode=");
282                 sb.append(orchestrationMode);
283                 sb.append(",neutronType=");
284                 sb.append(neutronNetworkType);
285                 sb.append(",aicVersionMin=");
286                 sb.append(aicVersionMin);
287                 sb.append(",aicVersionMax=");
288                 sb.append(aicVersionMax);
289                 sb.append(",modelName=");
290                 sb.append(modelName);
291                 sb.append(",modelInvariantUUID=");
292                 sb.append(modelInvariantUUID);
293                 sb.append(",toscaNodeType=");
294                 sb.append(toscaNodeType);
295                 sb.append(",modelUUID=");
296                 sb.append(modelUUID);
297
298                 if (created != null) {
299                         sb.append(",created=");
300                         sb.append(DateFormat.getInstance().format(created));
301                 }
302
303                 return sb.toString();
304         }
305 }