[MSO-8] Update the maven dependency
[so.git] / mso-catalog-db / src / main / java / org / openecomp / mso / db / catalog / beans / HeatTemplate.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.openecomp.mso.db.catalog.beans;
22
23
24 import java.io.BufferedReader;
25 import java.io.FileReader;
26 import java.sql.Timestamp;
27 import java.text.DateFormat;
28 import java.util.Date;
29 import java.util.Set;
30
31 import org.openecomp.mso.db.catalog.utils.MavenLikeVersioning;
32 import org.openecomp.mso.logger.MsoLogger;
33
34 public class HeatTemplate extends MavenLikeVersioning {
35
36     private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
37
38     private int id;
39     private String templateName;
40     private String templatePath = null;
41     private String templateBody = null;
42     private int timeoutMinutes;
43     private Set <HeatTemplateParam> parameters;
44     private Set <HeatNestedTemplate> files;
45     private String description;
46     private String asdcUuid;
47     private String asdcResourceName;
48     private String asdcLabel;
49     private String artifactChecksum;
50
51     private Timestamp created;
52
53     public enum TemplateStatus {
54                                 PARENT, CHILD, PARENT_COMPLETE
55     }
56
57     public HeatTemplate () {
58     }
59
60     public int getId () {
61         return id;
62     }
63
64     public void setId (int id) {
65         this.id = id;
66     }
67
68     public String getTemplateName () {
69         return templateName;
70     }
71
72     public void setTemplateName (String templateName) {
73         this.templateName = templateName;
74     }
75
76     public String getTemplatePath () {
77         return templatePath;
78     }
79
80     public void setTemplatePath (String templatePath) {
81         this.templatePath = templatePath;
82     }
83
84     public String getTemplateBody () {
85         return templateBody;
86     }
87
88     public void setTemplateBody (String templateBody) {
89         this.templateBody = templateBody;
90     }
91
92     public int getTimeoutMinutes () {
93         return timeoutMinutes;
94     }
95
96     public void setTimeoutMinutes (int timeout) {
97         this.timeoutMinutes = timeout;
98     }
99
100     public Set <HeatTemplateParam> getParameters () {
101         return parameters;
102     }
103
104     public void setParameters (Set <HeatTemplateParam> parameters) {
105         this.parameters = parameters;
106     }
107
108     public String getDescription() {
109                 return description;
110         }
111
112         public void setDescription(String description) {
113                 this.description = description;
114         }
115
116         public String getHeatTemplate () {
117         if (templateBody != null && !templateBody.isEmpty ()) {
118             // The template body is in the DB table. Just return it.
119             return templateBody;
120         }
121
122         String body = null;
123
124         try (BufferedReader reader = new BufferedReader (new FileReader (templatePath)))
125         {
126             String line = null;
127             StringBuilder stringBuilder = new StringBuilder ();
128             while ((line = reader.readLine ()) != null) {
129                 stringBuilder.append (line);
130             }
131             body = stringBuilder.toString ();
132         } catch (Exception e) {
133             LOGGER.debug ("Error reading template file " + templatePath, e);
134         }
135
136         return body;
137     }
138
139     public void setFiles (Set <HeatNestedTemplate> files) {
140         this.files = files;
141     }
142
143     public Set <HeatNestedTemplate> getFiles () {
144         return this.files;
145     }
146
147         public String getAsdcUuid() {
148                 return asdcUuid;
149         }
150
151         public void setAsdcUuid(String asdcUuidp) {
152                 this.asdcUuid = asdcUuidp;
153         }
154
155     public String getAsdcResourceName() {
156                 return asdcResourceName;
157         }
158
159         public void setAsdcResourceName(String asdcResourceName) {
160                 this.asdcResourceName = asdcResourceName;
161         }
162         public String getAsdcLabel() {
163                 return this.asdcLabel;
164         }
165         public void setAsdcLabel(String asdcLabel) {
166                 this.asdcLabel = asdcLabel;
167         }
168
169     public String getArtifactChecksum() {
170         return artifactChecksum;
171     }
172
173     public void setArtifactChecksum(String artifactChecksum) {
174         this.artifactChecksum = artifactChecksum;
175     }
176     public Timestamp getCreated() {
177                 return created;
178         }
179
180         public void setCreated(Timestamp created) {
181                 this.created = created;
182         }
183
184         @Override
185     public String toString () {
186         String body = (templateBody != null) ? "(" + templateBody.length () + " chars)" : "(Not defined)";
187         StringBuilder sb = new StringBuilder ();
188         sb.append ("Template=")
189           .append (templateName)
190           .append (",version=")
191           .append (version)
192           .append (",path=")
193           .append (templatePath)
194           .append (",body=")
195           .append (body)
196           .append (",timeout=")
197           .append (timeoutMinutes)
198           .append (",asdcUuid=")
199           .append (asdcUuid)
200           .append (",asdcResourceName=")
201           .append (asdcResourceName)
202           .append (",description=")
203           .append (description);
204         if (created != null) {
205                 sb.append (",created=");
206                 sb.append (DateFormat.getInstance().format(created));
207         }
208
209
210         if (parameters != null && !parameters.isEmpty ()) {
211             sb.append (",params=[");
212             for (HeatTemplateParam param : parameters) {
213                 sb.append (param.getParamName ());
214                 if (param.isRequired ()) {
215                     sb.append ("(reqd)");
216                 }
217                 sb.append (",");
218             }
219             sb.replace (sb.length () - 1, sb.length (), "]");
220         }
221         return sb.toString ();
222     }
223
224
225 }