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