173480172da5614c7613d035952ea9791d38e399
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / ConfigurationResource.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.Set;
26
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.Id;
31 import javax.persistence.OneToMany;
32 import javax.persistence.PrePersist;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36
37 import org.apache.commons.lang3.builder.EqualsBuilder;
38 import org.apache.commons.lang3.builder.HashCodeBuilder;
39 import org.apache.commons.lang3.builder.ToStringBuilder;
40
41 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
42 import com.openpojo.business.annotation.BusinessKey;
43
44 import uk.co.blackpepper.bowman.annotation.LinkedResource;
45
46 @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
47 @Entity
48 @Table(name = "configuration")
49 public class ConfigurationResource implements Serializable {
50
51         /**
52          * 
53          */
54         private static final long serialVersionUID = 6675926401792679171L;
55
56         @BusinessKey
57         @Id
58         @Column(name = "MODEL_UUID")
59         private String modelUUID;
60
61         @Column(name = "MODEL_INVARIANT_UUID")
62         private String modelInvariantUUID;
63
64         @Column(name = "MODEL_VERSION")
65         private String modelVersion;
66
67         @Column(name = "MODEL_NAME")
68         private String modelName;
69
70         @Column(name = "TOSCA_NODE_TYPE")
71         private String toscaNodeType;
72
73         @Column(name = "DESCRIPTION")
74         private String description;
75
76         @Column(name = "CREATION_TIMESTAMP", updatable = false)
77         @Temporal(TemporalType.TIMESTAMP)
78         private Date created;
79
80         @OneToMany(cascade = CascadeType.ALL, mappedBy = "configurationResource")
81         private Set<ConfigurationResourceCustomization> configurationResourceCustomization;
82
83         @PrePersist
84         protected void onCreate() {
85                 this.created = new Date();
86         }
87
88         public String getModelUUID() {
89                 return modelUUID;
90         }
91
92         public void setModelUUID(String modelUUID) {
93                 this.modelUUID = modelUUID;
94         }
95
96         public String getModelInvariantUUID() {
97                 return modelInvariantUUID;
98         }
99
100         public void setModelInvariantUUID(String modelInvariantUUID) {
101                 this.modelInvariantUUID = modelInvariantUUID;
102         }
103
104         public String getModelVersion() {
105                 return modelVersion;
106         }
107
108         public void setModelVersion(String modelVersion) {
109                 this.modelVersion = modelVersion;
110         }
111
112         public String getModelName() {
113                 return modelName;
114         }
115
116         public void setModelName(String modelName) {
117                 this.modelName = modelName;
118         }
119
120         public String getToscaNodeType() {
121                 return toscaNodeType;
122         }
123
124         public void setToscaNodeType(String toscaNodeType) {
125                 this.toscaNodeType = toscaNodeType;
126         }
127
128         public String getDescription() {
129                 return description;
130         }
131
132         public void setDescription(String description) {
133                 this.description = description;
134         }
135
136         public Date getCreated() {
137                 return created;
138         }
139
140         @LinkedResource
141         public Set<ConfigurationResourceCustomization> getConfigurationResourceCustomization() {
142                 return configurationResourceCustomization;
143         }
144
145         public void setConfigurationResourceCustomization(
146                         Set<ConfigurationResourceCustomization> configurationResourceCustomization) {
147                 this.configurationResourceCustomization = configurationResourceCustomization;
148         }
149
150         @Override
151         public String toString() {
152                 return new ToStringBuilder(this).append("modelUUID", modelUUID).append("modelInvariantUUID", modelInvariantUUID)
153                                 .append("modelVersion", modelVersion).append("modelName", modelName)
154                                 .append("toscaNodeType", toscaNodeType).append("description", description).append("created", created)
155                                 .append("configurationResourceCustomization", configurationResourceCustomization).toString();
156         }
157
158         @Override
159         public boolean equals(final Object other) {
160                 if (!(other instanceof ConfigurationResource)) {
161                         return false;
162                 }
163                 ConfigurationResource castOther = (ConfigurationResource) other;
164                 return new EqualsBuilder().append(modelUUID, castOther.modelUUID).isEquals();
165         }
166
167         @Override
168         public int hashCode() {
169                 return new HashCodeBuilder().append(modelUUID).toHashCode();
170         }
171 }