2389793f33f4e939d63a553f403122db14638ac2
[so.git] / mso-catalog-db / src / main / java / org / onap / so / db / catalog / beans / HeatTemplate.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.HashSet;
27 import java.util.List;
28 import java.util.Set;
29
30 import javax.persistence.CascadeType;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.Id;
34 import javax.persistence.JoinColumn;
35 import javax.persistence.JoinTable;
36 import javax.persistence.Lob;
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 @Table(name = "heat_template")
53 public class HeatTemplate implements Serializable {
54
55         private static final long serialVersionUID = 768026109321305392L;
56
57         @BusinessKey
58         @Id
59         @Column(name = "ARTIFACT_UUID", length = 200)
60         private String artifactUuid;
61
62         @Column(name = "NAME", length = 200)
63         private String templateName;
64
65         @Lob
66         @Column(name = "BODY", columnDefinition = "LONGTEXT")
67         private String templateBody = null;
68
69         @Column(name = "TIMEOUT_MINUTES", length = 20)
70         private Integer timeoutMinutes;
71
72         @BusinessKey
73         @Column(name = "VERSION")
74         private String version;
75
76         @Column(name = "DESCRIPTION", length = 1200)
77         private String description;
78
79         @Column(name = "ARTIFACT_CHECKSUM", length = 200)
80         private String artifactChecksum;
81
82         @Column(name = "CREATION_TIMESTAMP", updatable = false)
83         @Temporal(TemporalType.TIMESTAMP)
84         private Date created;
85
86         @OneToMany(cascade = CascadeType.ALL, mappedBy = "heatTemplateArtifactUuid")
87         private Set<HeatTemplateParam> parameters;
88
89         @OneToMany(cascade = CascadeType.ALL)
90         @JoinTable(name = "heat_nested_template", joinColumns = @JoinColumn(name = "PARENT_HEAT_TEMPLATE_UUID"), inverseJoinColumns = @JoinColumn(name = "CHILD_HEAT_TEMPLATE_UUID"))
91         private List<HeatTemplate> childTemplates;
92
93         public enum TemplateStatus {
94                 PARENT, CHILD, PARENT_COMPLETE
95         }
96
97         @PrePersist
98         protected void onCreate() {
99                 this.created = new Date();
100         }
101
102         @Override
103         public String toString() {
104                 return new ToStringBuilder(this).append("artifactUuid", artifactUuid).append("templateName", templateName)
105                                 .append("templateBody", templateBody).append("timeoutMinutes", timeoutMinutes)
106                                 .append("version", version).append("description", description)
107                                 .append("artifactChecksum", artifactChecksum).append("created", created)
108                                 .append("parameters", parameters).append("childTemplates", childTemplates).toString();
109         }
110
111         @Override
112         public boolean equals(final Object other) {
113                 if (!(other instanceof HeatTemplate)) {
114                         return false;
115                 }
116                 HeatTemplate castOther = (HeatTemplate) other;
117                 return new EqualsBuilder().append(artifactUuid, castOther.artifactUuid).append(version, castOther.version)
118                                 .isEquals();
119         }
120
121         @Override
122         public int hashCode() {
123                 return new HashCodeBuilder().append(artifactUuid).append(version).toHashCode();
124         }
125
126         @LinkedResource
127         public List<HeatTemplate> getChildTemplates() {
128                 if (childTemplates == null)
129                         childTemplates = new ArrayList<>();
130                 return childTemplates;
131         }
132
133         public void setChildTemplates(List<HeatTemplate> childTemplates) {
134                 this.childTemplates = childTemplates;
135         }
136
137         public String getVersion() {
138                 return version;
139         }
140
141         public void setVersion(String version) {
142                 this.version = version;
143         }
144
145         public String getArtifactUuid() {
146                 return this.artifactUuid;
147         }
148
149         public void setArtifactUuid(String artifactUuid) {
150                 this.artifactUuid = artifactUuid;
151         }
152
153         public String getTemplateName() {
154                 return templateName;
155         }
156
157         public void setTemplateName(String templateName) {
158                 this.templateName = templateName;
159         }
160
161         public String getTemplateBody() {
162                 return templateBody;
163         }
164
165         public void setTemplateBody(String templateBody) {
166                 this.templateBody = templateBody;
167         }
168
169         public Integer getTimeoutMinutes() {
170                 return timeoutMinutes;
171         }
172
173         public void setTimeoutMinutes(Integer timeout) {
174                 this.timeoutMinutes = timeout;
175         }
176
177         @LinkedResource
178         public Set<HeatTemplateParam> getParameters() {
179                 if (parameters == null)
180                         parameters = new HashSet<>();
181                 return parameters;
182         }
183
184         public void setParameters(Set<HeatTemplateParam> parameters) {
185                 this.parameters = parameters;
186         }
187
188         public String getDescription() {
189                 return description;
190         }
191
192         public void setDescription(String description) {
193                 this.description = description;
194         }
195
196         public String getHeatTemplate() {
197                 return this.templateBody;
198         }
199
200         public String getArtifactChecksum() {
201                 return artifactChecksum;
202         }
203
204         public void setArtifactChecksum(String artifactChecksum) {
205                 this.artifactChecksum = artifactChecksum;
206         }
207
208         public Date getCreated() {
209                 return created;
210         }
211 }