34389de22f297c2f94ecf37097d829208f2e13f3
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / CollectionResourceCustomization.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.FetchType;
32 import javax.persistence.Id;
33 import javax.persistence.Inheritance;
34 import javax.persistence.InheritanceType;
35 import javax.persistence.JoinColumn;
36 import javax.persistence.ManyToOne;
37 import javax.persistence.OneToMany;
38 import javax.persistence.PrePersist;
39 import javax.persistence.Table;
40 import javax.persistence.Temporal;
41 import javax.persistence.TemporalType;
42
43 import org.apache.commons.lang3.builder.EqualsBuilder;
44 import org.apache.commons.lang3.builder.HashCodeBuilder;
45 import org.apache.commons.lang3.builder.ToStringBuilder;
46
47 import com.openpojo.business.annotation.BusinessKey;
48
49 import uk.co.blackpepper.bowman.annotation.LinkedResource;
50
51 @Entity
52 @DiscriminatorColumn(name = "OBJECT_TYPE")
53 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
54 @Table(name = "collection_resource_customization")
55 public class CollectionResourceCustomization implements Serializable {
56
57         /**
58          * 
59          */
60         private static final long serialVersionUID = -8328823396870652841L;
61
62         @BusinessKey
63         @Id
64         @Column(name = "MODEL_CUSTOMIZATION_UUID")
65         private String modelCustomizationUUID;
66
67         @Column(name = "MODEL_INSTANCE_NAME")
68         private String modelInstanceName;
69
70         @Column(name = "COLLECTION_RESOURCE_TYPE")
71         private String type;
72
73         @Column(name = "ROLE")
74         private String role;
75
76         @Column(name = "FUNCTION")
77         private String function;
78
79         @Column(name = "CREATION_TIMESTAMP", updatable = false)
80         @Temporal(TemporalType.TIMESTAMP)
81         private Date created;
82
83         @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
84         @JoinColumn(name = "CR_MODEL_UUID")
85         private CollectionResource collectionResource;
86
87         @OneToMany(cascade = CascadeType.ALL, mappedBy = "collectionResourceCust")
88         private List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations;
89
90         @Override
91         public String toString() {
92                 return new ToStringBuilder(this).append("modelCustomizationUUID", modelCustomizationUUID)
93                                 .append("modelInstanceName", modelInstanceName).append("type", type).append("role", role)
94                                 .append("function", function).append("created", created)
95                                 .append("collectionResource", collectionResource)
96                                 .append("collectionInstanceGroupCustomizations", collectionInstanceGroupCustomizations).toString();
97         }
98
99         @Override
100         public boolean equals(final Object other) {
101                 if (!(other instanceof CollectionResourceCustomization)) {
102                         return false;
103                 }
104                 CollectionResourceCustomization castOther = (CollectionResourceCustomization) other;
105                 return new EqualsBuilder().append(modelCustomizationUUID, castOther.modelCustomizationUUID).isEquals();
106         }
107
108         @Override
109         public int hashCode() {
110                 return new HashCodeBuilder().append(modelCustomizationUUID).toHashCode();
111         }
112
113         public Date getCreated() {
114                 return this.created;
115         }
116
117         @PrePersist
118         protected void onCreate() {
119                 this.created = new Date();
120         }
121
122         public String getModelCustomizationUUID() {
123                 return modelCustomizationUUID;
124         }
125
126         public void setModelCustomizationUUID(String modelCustomizationUUID) {
127                 this.modelCustomizationUUID = modelCustomizationUUID;
128         }
129
130         public String getModelInstanceName() {
131                 return modelInstanceName;
132         }
133
134         public void setModelInstanceName(String modelInstanceName) {
135                 this.modelInstanceName = modelInstanceName;
136         }
137
138         public String getType() {
139                 return type;
140         }
141
142         public void setType(String type) {
143                 this.type = type;
144         }
145
146         public String getRole() {
147                 return role;
148         }
149
150         public void setRole(String role) {
151                 this.role = role;
152         }
153
154         public String getFunction() {
155                 return function;
156         }
157
158         public void setFunction(String function) {
159                 this.function = function;
160         }
161
162         @LinkedResource
163         public CollectionResource getCollectionResource() {
164                 return collectionResource;
165         }
166
167         public void setCollectionResource(CollectionResource collectionResource) {
168                 this.collectionResource = collectionResource;
169         }
170
171         @LinkedResource
172         public List<CollectionResourceInstanceGroupCustomization> getCollectionInstanceGroupCustomizations() {
173                 return collectionInstanceGroupCustomizations;
174         }
175
176         public void setCollectionInstanceGroupCustomizations(
177                         List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations) {
178                 this.collectionInstanceGroupCustomizations = collectionInstanceGroupCustomizations;
179         }
180 }