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