[SO] Release so 1.13.0 image
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / CloudSite.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
24 import java.net.URI;
25 import java.util.Date;
26 import javax.persistence.CascadeType;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.OneToOne;
33 import javax.persistence.PrePersist;
34 import javax.persistence.PreUpdate;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import javax.persistence.Transient;
39 import org.apache.commons.lang3.builder.EqualsBuilder;
40 import org.apache.commons.lang3.builder.HashCodeBuilder;
41 import org.apache.commons.lang3.builder.ToStringBuilder;
42 import org.apache.commons.lang3.builder.ToStringStyle;
43 import com.fasterxml.jackson.annotation.JsonAutoDetect;
44 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
45 import com.fasterxml.jackson.annotation.JsonProperty;
46 import com.openpojo.business.annotation.BusinessKey;
47 import uk.co.blackpepper.bowman.annotation.RemoteResource;
48 import uk.co.blackpepper.bowman.annotation.ResourceId;
49
50 /**
51  * EntityBean class for a CloudSite. This bean represents a cloud location (i.e. and LCP node) in the NVP/AIC cloud. It
52  * will be loaded via CloudConfig object, of which it is a component
53  *
54  */
55 @Entity
56 @RemoteResource("/cloudSite")
57 @Table(name = "cloud_sites")
58 @JsonAutoDetect(fieldVisibility = Visibility.ANY)
59 public class CloudSite {
60
61     @JsonProperty
62     @BusinessKey
63     @Id
64     @Column(name = "ID")
65     private String id;
66
67     @JsonProperty("region_id")
68     @BusinessKey
69     @Column(name = "REGION_ID")
70     private String regionId;
71
72     @JsonProperty("aic_version")
73     @BusinessKey
74     @Column(name = "CLOUD_VERSION")
75     private String cloudVersion;
76
77     @JsonProperty("clli")
78     @BusinessKey
79     @Column(name = "CLLI")
80     private String clli;
81
82     @JsonProperty("platform")
83     @BusinessKey
84     @Column(name = "PLATFORM")
85     private String platform;
86
87     @JsonProperty("orchestrator")
88     @BusinessKey
89     @Column(name = "ORCHESTRATOR")
90     private String orchestrator;
91
92     @JsonProperty("cloudify_id")
93     @BusinessKey
94     @Column(name = "CLOUDIFY_ID")
95     private String cloudifyId;
96
97     @JsonProperty("cloud_owner")
98     @BusinessKey
99     @Column(name = "CLOUD_OWNER")
100     private String cloudOwner;
101
102     // Derived property (set by CloudConfig loader based on identityServiceId)
103     @BusinessKey
104     @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
105     @JoinColumn(name = "IDENTITY_SERVICE_ID")
106     private CloudIdentity identityService;
107
108     @BusinessKey
109     @JsonProperty("identity_service_id")
110     private transient String identityServiceId;
111
112     @JsonProperty("last_updated_by")
113     @BusinessKey
114     @Column(name = "LAST_UPDATED_BY")
115     private String lastUpdatedBy;
116
117     @JsonProperty("creation_timestamp")
118     @BusinessKey
119     @Column(name = "CREATION_TIMESTAMP", updatable = false)
120     @Temporal(TemporalType.TIMESTAMP)
121     private Date created;
122
123     @JsonProperty("update_timestamp")
124     @BusinessKey
125     @Column(name = "UPDATE_TIMESTAMP")
126     @Temporal(TemporalType.TIMESTAMP)
127     private Date updated;
128
129     @JsonProperty("support_fabric")
130     @BusinessKey
131     @Column(name = "SUPPORT_FABRIC", nullable = false)
132     private Boolean supportFabric = true;
133
134     @Transient
135     private URI uri;
136
137     public CloudSite() {
138
139     }
140
141     @PrePersist
142     protected void onCreate() {
143         this.created = new Date();
144         this.updated = new Date();
145     }
146
147     @PreUpdate
148     protected void onUpdate() {
149         this.updated = new Date();
150     }
151
152     public CloudSite(CloudSite site) {
153         this.cloudVersion = site.getCloudVersion();
154         this.clli = site.getClli();
155         this.id = site.getId();
156         this.identityService = site.getIdentityService();
157         this.orchestrator = site.getOrchestrator();
158         this.platform = site.getPlatform();
159         this.regionId = site.getRegionId();
160         this.identityServiceId = site.getIdentityServiceId();
161         this.supportFabric = site.getSupportFabric();
162     }
163
164
165     public String getId() {
166         return this.id;
167     }
168
169     public void setId(String id) {
170         this.id = id;
171     }
172
173     @ResourceId
174     public URI getUri() {
175         return this.uri;
176     }
177
178     public void setUri(URI uri) {
179         this.uri = uri;
180     }
181
182     public String getRegionId() {
183         return regionId;
184     }
185
186     public void setRegionId(String regionId) {
187         this.regionId = regionId;
188     }
189
190     public String getIdentityServiceId() {
191         return identityServiceId == null ? (identityService == null ? null : identityService.getId())
192                 : identityServiceId;
193     }
194
195     public String getCloudVersion() {
196         return cloudVersion;
197     }
198
199     public void setCloudVersion(String cloudVersion) {
200         this.cloudVersion = cloudVersion;
201     }
202
203     public String getClli() {
204         return clli;
205     }
206
207     public void setClli(String clli) {
208         this.clli = clli;
209     }
210
211     public String getCloudifyId() {
212         return cloudifyId;
213     }
214
215     public void setCloudifyId(String cloudifyId) {
216         this.cloudifyId = cloudifyId;
217     }
218
219     public String getLastUpdatedBy() {
220         return lastUpdatedBy;
221     }
222
223     public Date getCreated() {
224         return created;
225     }
226
227     public Date getUpdated() {
228         return updated;
229     }
230
231     public void setLastUpdatedBy(String lastUpdatedBy) {
232         this.lastUpdatedBy = lastUpdatedBy;
233     }
234
235     public void setCreated(Date created) {
236         this.created = created;
237     }
238
239     public void setUpdated(Date updated) {
240         this.updated = updated;
241     }
242
243     public String getPlatform() {
244         return platform;
245     }
246
247     public void setPlatform(String platform) {
248         this.platform = platform;
249     }
250
251     public String getOrchestrator() {
252         return orchestrator;
253     }
254
255     public void setOrchestrator(String orchestrator) {
256         this.orchestrator = orchestrator;
257     }
258
259     public CloudIdentity getIdentityService() {
260         return identityService;
261     }
262
263     public void setIdentityService(CloudIdentity identity) {
264         this.identityService = identity;
265     }
266
267     public Boolean getSupportFabric() {
268         return supportFabric;
269     }
270
271     public void setSupportFabric(Boolean supportFabric) {
272         this.supportFabric = supportFabric;
273     }
274
275     @Deprecated
276     public void setIdentityServiceId(String identityServiceId) {
277         this.identityServiceId = identityServiceId;
278     }
279
280     public String getCloudOwner() {
281         return cloudOwner;
282     }
283
284     public void setCloudOwner(String cloudOwner) {
285         this.cloudOwner = cloudOwner;
286     }
287
288     @Override
289     public String toString() {
290         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("regionId", getRegionId())
291                 .append("identityServiceId", getIdentityServiceId()).append("cloudVersion", getCloudVersion())
292                 .append("clli", getClli()).append("cloudifyId", getCloudifyId()).append("platform", getPlatform())
293                 .append("orchestrator", getOrchestrator()).append("cloud-owner", getCloudOwner()).toString();
294     }
295
296     @Override
297     public boolean equals(final Object other) {
298         if (other == null) {
299             return false;
300         }
301         if (!getClass().equals(other.getClass())) {
302             return false;
303         }
304         CloudSite castOther = (CloudSite) other;
305         return new EqualsBuilder().append(getRegionId(), castOther.getRegionId())
306                 .append(getIdentityServiceId(), castOther.getIdentityServiceId())
307                 .append(getCloudVersion(), castOther.getCloudVersion()).append(getClli(), castOther.getClli())
308                 .isEquals();
309     }
310
311     @Override
312     public int hashCode() {
313         return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion())
314                 .append(getClli()).toHashCode();
315     }
316 }