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