fdd250089a3ddf1350f108b548b3a81c4cfc1fd1
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / InstanceGroup.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.List;
26
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.DiscriminatorColumn;
30 import javax.persistence.Entity;
31 import javax.persistence.EnumType;
32 import javax.persistence.Enumerated;
33 import javax.persistence.FetchType;
34 import javax.persistence.Id;
35 import javax.persistence.Inheritance;
36 import javax.persistence.InheritanceType;
37 import javax.persistence.JoinColumn;
38 import javax.persistence.ManyToOne;
39 import javax.persistence.OneToMany;
40 import javax.persistence.PrePersist;
41 import javax.persistence.Table;
42 import javax.persistence.Temporal;
43 import javax.persistence.TemporalType;
44
45 import org.apache.commons.lang3.builder.EqualsBuilder;
46 import org.apache.commons.lang3.builder.HashCodeBuilder;
47 import org.apache.commons.lang3.builder.ToStringBuilder;
48
49 import com.openpojo.business.annotation.BusinessKey;
50
51 import uk.co.blackpepper.bowman.annotation.LinkedResource;
52
53 @Entity
54 @DiscriminatorColumn(name = "OBJECT_TYPE")
55 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
56 @Table(name = "instance_group")
57 public class InstanceGroup implements Serializable {
58
59         /**
60          * 
61          */
62         private static final long serialVersionUID = -263859017727376578L;
63
64         @BusinessKey
65         @Id
66         @Column(name = "MODEL_UUID")
67         private String modelUUID;
68
69         @Column(name = "MODEL_NAME")
70         private String modelName;
71
72         @Column(name = "MODEL_INVARIANT_UUID")
73         private String modelInvariantUUID;
74
75         @Column(name = "MODEL_VERSION")
76         private String modelVersion;
77
78         @Column(name = "ROLE")
79         private String role;
80
81         @Column(name = "TOSCA_NODE_TYPE")
82         private String toscaNodeType;
83
84         @Enumerated(EnumType.STRING)
85         @Column(name = "INSTANCE_GROUP_TYPE")
86         private InstanceGroupType type;
87
88         @Column(name = "CREATION_TIMESTAMP", updatable = false)
89         @Temporal(TemporalType.TIMESTAMP)
90         private Date created;
91
92         @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
93         @JoinColumn(name = "CR_MODEL_UUID")
94         private CollectionResource collectionResource;
95
96         @OneToMany(cascade = CascadeType.ALL, mappedBy = "instanceGroup")
97         private List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations;
98
99         @OneToMany(cascade = CascadeType.ALL, mappedBy = "instanceGroup")
100         private List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations;
101
102         @OneToMany(cascade = CascadeType.ALL, mappedBy = "instanceGroup")
103         private List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizations;
104
105         @Override
106         public String toString() {
107                 return new ToStringBuilder(this).append("modelUUID", modelUUID).append("modelName", modelName)
108                                 .append("modelInvariantUUID", modelInvariantUUID).append("modelVersion", modelVersion)
109                                 .append("role", role).append("toscaNodeType", toscaNodeType).append("type", type)
110                                 .append("created", created).append("collectionResource", collectionResource)
111                                 .append("collectionInstanceGroupCustomizations", collectionInstanceGroupCustomizations)
112                                 .append("vnfcInstanceGroupCustomizations", vnfcInstanceGroupCustomizations).toString();
113         }
114
115         @Override
116         public boolean equals(final Object other) {
117                 if (!(other instanceof InstanceGroup)) {
118                         return false;
119                 }
120                 InstanceGroup castOther = (InstanceGroup) other;
121                 return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
122         }
123
124         @Override
125         public int hashCode() {
126                 return new HashCodeBuilder().append(modelUUID).toHashCode();
127         }
128
129         @PrePersist
130         protected void onCreate() {
131                 this.created = new Date();
132         }
133
134         public String getModelUUID() {
135                 return modelUUID;
136         }
137
138         public Date getCreated() {
139                 return created;
140         }
141
142         public void setModelUUID(String modelUUID) {
143                 this.modelUUID = modelUUID;
144         }
145
146         public String getModelName() {
147                 return modelName;
148         }
149
150         public String getToscaNodeType() {
151                 return toscaNodeType;
152         }
153
154         public void setToscaNodeType(String toscaNodeType) {
155                 this.toscaNodeType = toscaNodeType;
156         }
157
158         public void setModelName(String modelName) {
159                 this.modelName = modelName;
160         }
161
162         public String getModelInvariantUUID() {
163                 return modelInvariantUUID;
164         }
165
166         public void setModelInvariantUUID(String modelInvariantUUID) {
167                 this.modelInvariantUUID = modelInvariantUUID;
168         }
169
170         public String getModelVersion() {
171                 return modelVersion;
172         }
173
174         public void setModelVersion(String modelVersion) {
175                 this.modelVersion = modelVersion;
176         }
177
178         public String getRole() {
179                 return role;
180         }
181
182         public void setRole(String role) {
183                 this.role = role;
184         }
185
186         public InstanceGroupType getType() {
187                 return type;
188         }
189
190         public void setType(InstanceGroupType type) {
191                 this.type = type;
192         }
193
194         @LinkedResource
195         public CollectionResource getCollectionResource() {
196                 return collectionResource;
197         }
198
199         public void setCollectionResource(CollectionResource collectionResource) {
200                 this.collectionResource = collectionResource;
201         }
202
203         @LinkedResource
204         public List<CollectionResourceInstanceGroupCustomization> getCollectionInstanceGroupCustomizations() {
205                 return collectionInstanceGroupCustomizations;
206         }
207
208         public void setCollectionInstanceGroupCustomizations(
209                         List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations) {
210                 this.collectionInstanceGroupCustomizations = collectionInstanceGroupCustomizations;
211         }
212
213         @LinkedResource
214         public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupCustomizations() {
215                 return vnfcInstanceGroupCustomizations;
216         }
217
218         public void setVnfcInstanceGroupCustomizations(
219                         List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations) {
220                 this.vnfcInstanceGroupCustomizations = vnfcInstanceGroupCustomizations;
221         }
222
223         @LinkedResource
224         public List<CollectionNetworkResourceCustomization> getCollectionNetworkResourceCustomizations() {
225                 return collectionNetworkResourceCustomizations;
226         }
227
228         public void setCollectionNetworkResourceCustomizations(
229                         List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizations) {
230                 this.collectionNetworkResourceCustomizations = collectionNetworkResourceCustomizations;
231         }
232 }