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