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