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