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