f8148aa781e92b3c4552f4a7518a18dc49d959ce
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / CollectionResource.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 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.Set;
26
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.Id;
31 import javax.persistence.OneToMany;
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
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
42 import com.openpojo.business.annotation.BusinessKey;
43
44 import uk.co.blackpepper.bowman.annotation.LinkedResource;
45
46 @Entity
47 @Table(name = "collection_resource")
48 public class CollectionResource implements Serializable {
49
50         /**
51          * 
52          */
53         private static final long serialVersionUID = -8612818857960992110L;
54
55         @BusinessKey
56         @Id
57         @Column(name = "MODEL_UUID")
58         private String modelUUID;
59
60         @Column(name = "MODEL_NAME")
61         private String modelName;
62
63         @Column(name = "MODEL_INVARIANT_UUID")
64         private String modelInvariantUUID;
65
66         @Column(name = "MODEL_VERSION")
67         private String modelVersion;
68
69         @Column(name = "TOSCA_NODE_TYPE")
70         private String toscaNodeType;
71
72         @Column(name = "DESCRIPTION")
73         private String description;
74
75         @Column(name = "CREATION_TIMESTAMP", updatable = false)
76         @Temporal(TemporalType.TIMESTAMP)
77         private Date created;
78
79         @OneToMany(cascade = CascadeType.ALL, mappedBy = "collectionResource")
80         private Set<CollectionResourceCustomization> collectionResourceCustomization;
81
82         @OneToOne(cascade = CascadeType.ALL, mappedBy = "collectionResource")
83         private InstanceGroup instanceGroup;
84
85         @Override
86         public boolean equals(final Object other) {
87                 if (!(other instanceof CollectionResource)) {
88                         return false;
89                 }
90                 CollectionResource castOther = (CollectionResource) other;
91                 return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
92         }
93
94         @Override
95         public int hashCode() {
96                 return new HashCodeBuilder().append(modelUUID).toHashCode();
97         }
98
99         public Set<CollectionResourceCustomization> getCollectionResourceCustomization() {
100                 return collectionResourceCustomization;
101         }
102
103         public void setCollectionResourceCustomization(
104                         Set<CollectionResourceCustomization> collectionResourceCustomization) {
105                 this.collectionResourceCustomization = collectionResourceCustomization;
106         }
107
108         public String getModelUUID() {
109                 return modelUUID;
110         }
111
112         public Date getCreated() {
113                 return this.created;
114         }
115
116         @PrePersist
117         protected void onCreate() {
118                 this.created = new Date();
119         }
120
121         public void setModelUUID(String modelUUID) {
122                 this.modelUUID = modelUUID;
123         }
124
125         public String getModelName() {
126                 return modelName;
127         }
128
129         public void setModelName(String modelName) {
130                 this.modelName = modelName;
131         }
132
133         public String getModelInvariantUUID() {
134                 return modelInvariantUUID;
135         }
136
137         public void setModelInvariantUUID(String modelInvariantUUID) {
138                 this.modelInvariantUUID = modelInvariantUUID;
139         }
140
141         public String getModelVersion() {
142                 return modelVersion;
143         }
144
145         public void setModelVersion(String modelVersion) {
146                 this.modelVersion = modelVersion;
147         }
148
149         public String getToscaNodeType() {
150                 return toscaNodeType;
151         }
152
153         public void setToscaNodeType(String toscaNodeType) {
154                 this.toscaNodeType = toscaNodeType;
155         }
156
157         public String getDescription() {
158                 return description;
159         }
160
161         public void setDescription(String description) {
162                 this.description = description;
163         }
164
165         @LinkedResource
166         public InstanceGroup getInstanceGroup() {
167                 return instanceGroup;
168         }
169
170         public void setInstanceGroup(InstanceGroup instanceGroup) {
171                 this.instanceGroup = instanceGroup;
172         }
173
174         @Override
175         public String toString() {
176                 return new ToStringBuilder(this).append("modelUUID", modelUUID).append("modelName", modelName)
177                                 .append("modelInvariantUUID", modelInvariantUUID).append("modelVersion", modelVersion)
178                                 .append("toscaNodeType", toscaNodeType).append("description", description).append("created", created)
179                                 .toString();
180         }
181 }