f7b4d88f1a90800d5618a6d9e7bc37982a62f752
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / VfModule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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.vid.model;
22
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.Map.Entry;
29 import org.onap.vid.asdc.beans.tosca.Group;
30
31 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.sdc.toscaparser.api.Property;
33
34 /**
35  * The Class VfModule.
36  */
37 public class VfModule {
38
39         /** The Constant LOG. */
40         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.class);
41         
42         /** The Constant dateFormat. */
43         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
44         
45         /** The uuid. */
46         private String uuid;
47         
48         /** The invariant uuid. */
49         private String invariantUuid;
50         
51         /** The customization uuid. */
52         private String customizationUuid;
53         
54         /** The description. */
55         private String description;
56         
57         /** The name. */
58         private String name;
59         
60         /** The version. */
61         private String version;
62         
63         /** The volume group allowed. */
64         private boolean volumeGroupAllowed;
65         
66         /** The get_input or other constructs for VF Module. */
67         private Map<String, CommandProperty> commands;
68         
69         /** The model customization name. */
70         private String modelCustomizationName;
71         
72         /** The model properties. */
73         private Map<String, Property> properties;
74         
75         /**
76          * Instantiates a new vf module.
77          */
78         public VfModule() {
79                 commands = new HashMap<String, CommandProperty>();
80         }
81         /**
82          * Gets the model customization name.
83          *
84          * @return the model customization name
85          */
86         public String getModelCustomizationName() {
87                 return modelCustomizationName;
88         }
89         /**
90          * Gets the uuid.
91          *
92          * @return the uuid
93          */
94         public String getUuid() {
95                 return uuid;
96         }
97
98         /**
99          * Gets the invariant uuid.
100          *
101          * @return the invariant uuid
102          */
103         public String getInvariantUuid() {
104                 return invariantUuid;
105         }
106         /**
107          * Gets the customization uuid.
108          *
109          * @return the invariant uuid
110          */
111         public String getCustomizationUuid() {
112                 return customizationUuid;
113         }
114         /**
115          * Gets the description.
116          *
117          * @return the description
118          */
119         public String getDescription() {
120                 return description;
121         }
122         /**
123          * Gets the commands.
124          *
125          * @return the commands
126          */
127         public Map<String, CommandProperty> getCommands() {
128                 return commands;
129         }
130         /**
131          * Gets the name.
132          *
133          * @return the name
134          */
135         public String getName() {
136                 return name;
137         }
138
139         /**
140          * Gets the version.
141          *
142          * @return the version
143          */
144         public String getVersion() {
145                 return version;
146         }
147
148         /**
149          * Checks if is volume group allowed.
150          *
151          * @return true, if is volume group allowed
152          */
153         public boolean isVolumeGroupAllowed() {
154                 return volumeGroupAllowed;
155         }
156         
157         /**
158          * Sets the uuid.
159          *
160          * @param uuid the new uuid
161          */
162         public void setUuid(String uuid) {
163                 this.uuid = uuid;
164         }
165
166         /**
167          * Sets the invariant uuid.
168          *
169          * @param invariantUuid the new invariant uuid
170          */
171         public void setInvariantUuid(String invariantUuid) {
172                 this.invariantUuid = invariantUuid;
173         }
174         /**
175          * Sets the customization uuid.
176          *
177          * @param customizationUuid the new customization uuid
178          */
179         public void setCustomizationUuid(String customizationUuid) {
180                 this.customizationUuid = customizationUuid;
181         }
182         /**
183          * Sets the description.
184          *
185          * @param description the new description
186          */
187         public void setDescription(String description) {
188                 this.description = description;
189         }
190
191         /**
192          * Sets the name.
193          *
194          * @param name the new name
195          */
196         public void setName(String name) {
197                 this.name = name;
198         }
199
200         /**
201          * Sets the version.
202          *
203          * @param version the new version
204          */
205         public void setVersion(String version) {
206                 this.version = version;
207         }
208
209         /**
210          * Sets the volume group allowed.
211          *
212          * @param volumeGroupAllowed the new volume group allowed
213          */
214         public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
215                 this.volumeGroupAllowed = volumeGroupAllowed;
216         }
217         /**
218          * Sets the commands.
219          *
220          * @param m the commands
221          */
222         public void setCommands( Map<String, CommandProperty>m ) {
223                 commands = m;
224         }
225         /**
226          * Sets the model customization name.
227          *
228          * @param modelCustomizationName the new model customization name
229          */
230         public void setModelCustomizationName(String modelCustomizationName) {
231                 this.modelCustomizationName = modelCustomizationName;
232         }
233         /**
234          * Extract vf module.
235          *
236          * @param group the group
237          * @return the vf module
238          */
239         public static  VfModule extractVfModule(String modelCustomizationName, Group group) {
240                 
241                 String methodName = "extractVfModule";
242
243                 final VfModule vfModule = new VfModule();
244                 
245                 try {
246                         vfModule.setUuid(group.getMetadata().getVfModuleModelUUID());
247                         vfModule.setInvariantUuid(group.getMetadata().getVfModuleModelInvariantUUID());
248                         vfModule.setDescription(group.getMetadata().getDescription());
249                         vfModule.setName(group.getMetadata().getVfModuleModelName());
250                         vfModule.setVersion(group.getMetadata().getVfModuleModelVersion());
251                         vfModule.setCustomizationUuid(group.getMetadata().getVfModuleModelCustomizationUUID());
252                         vfModule.setModelCustomizationName (modelCustomizationName);
253                         //?vfModule.setProperties(group.getProperties());
254                         
255                         if (group.getProperties().containsKey("volume_group")) {
256                                 if (group.getProperties().get("volume_group") != null) {
257                                 
258                                         Class<?> c = group.getProperties().get("volume_group").getClass();
259                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" + 
260                                                         c.getName());
261                                         
262                                         if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) {
263                                                 Boolean b = (Boolean)group.getProperties().get("volume_group");
264                                                 vfModule.setVolumeGroupAllowed( b.booleanValue() );
265                                         }
266                                 }
267                         } else {
268                                 vfModule.setVolumeGroupAllowed(false);
269                         }
270                 }
271                 catch ( Exception e ) {
272                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" + 
273                                         e.toString());
274                 }
275                 /* Not extracting other types of properties for 1702
276                  try {
277                         
278                         for (Entry<String, Object> e : group.getProperties().entrySet()) {
279                                 
280                                 String k = e.getKey();
281                                 if ( e.getValue() != null ) {
282                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " + 
283                                                         k + "=" + e.getValue());
284                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " V class name: " +
285                                                          e.getValue().getClass().getName());
286                                          Class<?>[] interfaces = e.getValue().getClass().getInterfaces();
287                                          
288                                          for(Class<?> ifc: interfaces ){
289                                                  LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +
290                                                                  ifc.getName());
291                                      }
292                                          
293                                         // only extract get_input for now
294                                         for (Entry<String, String> entry : v.entrySet()) {
295                                                 // only include get_input for now
296                                                 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {
297                                                         CommandProperty cp = new CommandProperty();
298                                                         cp.setDisplayName(entry.getValue());
299                                                         cp.setCommand(entry.getKey());
300                                                         cp.setInputName(k);
301                                                         (vfModule.getCommands()).put(k,cp);
302                                                 }
303                                         } 
304                                 }
305                         }
306                 }
307                 catch ( Exception e ) {
308                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module properties: e=" + 
309                                         e.toString());
310                 }*/
311                 return vfModule;
312         }
313     public Map<String, Property> getProperties() {
314         return properties;
315     }
316     public void setProperties(Map<String, Property> properties) {
317         this.properties = properties;
318     }
319 }