2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.db.catalog.beans;
25 import java.util.Date;
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;
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;
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;
50 import uk.co.blackpepper.bowman.annotation.RemoteResource;
51 import uk.co.blackpepper.bowman.annotation.ResourceId;
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
59 @RemoteResource("/cloudSite")
61 @Table(name = "cloud_sites")
62 @JsonAutoDetect(fieldVisibility = Visibility.ANY)
63 public class CloudSite {
71 @JsonProperty("region_id")
73 @Column(name = "REGION_ID")
74 private String regionId;
76 @JsonProperty("aic_version")
78 @Column(name = "CLOUD_VERSION")
79 private String cloudVersion;
83 @Column(name = "CLLI")
86 @JsonProperty("platform")
88 @Column(name = "PLATFORM")
89 private String platform;
91 @JsonProperty("orchestrator")
93 @Column(name = "ORCHESTRATOR")
94 private String orchestrator;
96 @JsonProperty("cloudify_id")
98 @Column(name = "CLOUDIFY_ID")
99 private String cloudifyId;
101 // Derived property (set by CloudConfig loader based on identityServiceId)
103 @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
104 @JoinColumn(name = "IDENTITY_SERVICE_ID")
105 private CloudIdentity identityService;
108 @JsonProperty("identity_service_id")
109 private transient String identityServiceId;
111 @JsonProperty("last_updated_by")
113 @Column(name = "LAST_UPDATED_BY")
114 private String lastUpdatedBy ;
116 @JsonProperty("creation_timestamp")
118 @Column(name = "CREATION_TIMESTAMP", updatable = false)
119 @Temporal(TemporalType.TIMESTAMP)
120 private Date created;
122 @JsonProperty("update_timestamp")
124 @Column(name = "UPDATE_TIMESTAMP")
125 @Temporal(TemporalType.TIMESTAMP)
126 private Date updated;
136 protected void onCreate() {
137 this.created = new Date();
138 this.updated = new Date();
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();
153 public String getId() {
157 public void setId(String id) {
162 public URI getUri() {return this.uri;}
164 public void setUri(URI uri) {
168 public String getRegionId() {
172 public void setRegionId(String regionId) {
173 this.regionId = regionId;
176 public String getIdentityServiceId() {
177 return identityServiceId == null ? (identityService== null? null:identityService.getId()):identityServiceId;
180 public String getCloudVersion() {
184 public void setCloudVersion(String cloudVersion) {
185 this.cloudVersion = cloudVersion;
188 public String getClli() {
192 public void setClli(String clli) {
196 public String getCloudifyId() {
200 public void setCloudifyId(String cloudifyId) {
201 this.cloudifyId = cloudifyId;
204 public String getLastUpdatedBy() {
205 return lastUpdatedBy;
208 public Date getCreated() {
212 public Date getUpdated() {
216 public void setLastUpdatedBy(String lastUpdatedBy) {
217 this.lastUpdatedBy = lastUpdatedBy;
220 public void setCreated(Date created) {
221 this.created = created;
224 public void setUpdated(Date updated) {
225 this.updated = updated;
228 public String getPlatform() {
232 public void setPlatform(String platform) {
233 this.platform = platform;
236 public String getOrchestrator() {
240 public void setOrchestrator(String orchestrator) {
241 this.orchestrator = orchestrator;
244 public CloudIdentity getIdentityService () {
245 return identityService;
248 public void setIdentityService (CloudIdentity identity) {
249 this.identityService = identity;
252 public void setIdentityServiceId(String identityServiceId) {
253 this.identityServiceId = identityServiceId;
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();
265 public boolean equals(final Object other) {
269 if (!getClass().equals(other.getClass())) {
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();
279 public int hashCode() {
280 return new HashCodeBuilder(1, 31).append(getRegionId()).append(getIdentityServiceId()).append(getCloudVersion())
281 .append(getClli()).toHashCode();