1d3ee7c36ef1fe6a4946d9ee1586ee48a2c54ff9
[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 com.fasterxml.jackson.annotation.JsonFormat;
39 import org.apache.commons.lang3.builder.EqualsBuilder;
40 import org.apache.commons.lang3.builder.HashCodeBuilder;
41 import org.apache.commons.lang3.builder.ToStringBuilder;
42
43 import com.openpojo.business.annotation.BusinessKey;
44
45 import uk.co.blackpepper.bowman.annotation.LinkedResource;
46
47 @Entity
48 @Table(name = "allotted_resource")
49 public class AllottedResource implements Serializable {
50
51         private static final long serialVersionUID = 768026109321305392L;
52         @BusinessKey
53         @Id
54         @Column(name = "MODEL_UUID")
55         private String modelUUID;
56
57         @Column(name = "MODEL_INVARIANT_UUID")
58         private String modelInvariantUUID;
59
60         @Column(name = "MODEL_VERSION")
61         private String modelVersion;
62
63         @Column(name = "MODEL_NAME")
64         private String modelName;
65
66         @Column(name = "TOSCA_NODE_TYPE")
67         private String toscaNodeType;
68
69         @Column(name = "SUBCATEGORY")
70         private String subcategory;
71
72         @Column(name = "DESCRIPTION")
73         private String description;
74         
75         @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
76         @Column(name = "CREATION_TIMESTAMP", updatable = false)
77         @Temporal(TemporalType.TIMESTAMP)
78         private Date created;
79
80         @OneToMany(cascade = CascadeType.ALL, mappedBy = "allottedResource")
81         private Set<AllottedResourceCustomization> allotedResourceCustomization;
82
83         @Override
84         public String toString() {
85                 return new ToStringBuilder(this).append("modelUUID", modelUUID).append("modelInvariantUUID", modelInvariantUUID)
86                                 .append("modelVersion", modelVersion).append("modelName", modelName)
87                                 .append("toscaNodeType", toscaNodeType).append("subcategory", subcategory)
88                                 .append("description", description).append("created", created)
89                                 .append("allotedResourceCustomization", allotedResourceCustomization).toString();
90         }
91
92         @Override
93         public boolean equals(final Object other) {
94                 if (!(other instanceof AllottedResource)) {
95                         return false;
96                 }
97                 AllottedResource castOther = (AllottedResource) other;
98                 return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
99         }
100
101         @Override
102         public int hashCode() {
103                 return new HashCodeBuilder().append(modelUUID).toHashCode();
104         }
105
106         @PrePersist
107         protected void onCreate() {
108                 this.created = new Date();
109         }
110
111         @LinkedResource
112         public Set<AllottedResourceCustomization> getAllotedResourceCustomization() {
113                 if (allotedResourceCustomization == null)
114                         allotedResourceCustomization = new HashSet<>();
115                 return allotedResourceCustomization;
116         }
117
118         public void setAllotedResourceCustomization(Set<AllottedResourceCustomization> allotedResourceCustomization) {
119                 this.allotedResourceCustomization = allotedResourceCustomization;
120         }
121
122         public String getModelUUID() {
123                 return this.modelUUID;
124         }
125
126         public void setModelUUID(String modelUUID) {
127                 this.modelUUID = modelUUID;
128         }
129
130         public String getModelInvariantUUID() {
131                 return this.modelInvariantUUID;
132         }
133
134         public void setModelInvariantUUID(String modelInvariantUUID) {
135                 this.modelInvariantUUID = modelInvariantUUID;
136         }
137
138         public String getModelVersion() {
139                 return this.modelVersion;
140         }
141
142         public void setModelVersion(String modelVersion) {
143                 this.modelVersion = modelVersion;
144         }
145
146         public String getModelName() {
147                 return this.modelName;
148         }
149
150         public void setModelName(String modelName) {
151                 this.modelName = modelName;
152         }
153
154         public String getToscaNodeType() {
155                 return this.toscaNodeType;
156         }
157
158         public void setToscaNodeType(String toscaNodeType) {
159                 this.toscaNodeType = toscaNodeType;
160         }
161
162         public String getSubcategory() {
163                 return this.subcategory;
164         }
165
166         public void setSubcategory(String subcategory) {
167                 this.subcategory = subcategory;
168         }
169
170         public String getDescription() {
171                 return this.description;
172         }
173
174         public void setDescription(String description) {
175                 this.description = description;
176         }
177
178         public Date getCreated() {
179                 return created;
180         }
181 }