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