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