ea30571a0166a05a492b184652020a5d2ba327f2
[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 org.onap.vid.asdc.beans.tosca.Group;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29
30 /**
31  * The Class VfModule.
32  */
33 public class VfModule extends org.onap.vid.model.Group {
34
35         /** The Constant LOG. */
36         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.class);
37         
38         /** The Constant dateFormat. */
39         static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
40         public static final String VOLUME_GROUP = "volume_group";
41
42         /** The volume group allowed. */
43         private boolean volumeGroupAllowed;
44
45         /**
46          * Checks if is volume group allowed.
47          *
48          * @return true, if is volume group allowed
49          */
50         public boolean isVolumeGroupAllowed() {
51                 return volumeGroupAllowed;
52         }
53
54
55         /**
56          * Sets the volume group allowed.
57          *
58          * @param volumeGroupAllowed the new volume group allowed
59          */
60         public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
61                 this.volumeGroupAllowed = volumeGroupAllowed;
62         }
63
64
65         /**
66          * Extract vf module.
67          *
68          * @param group the group
69          * @return the vf module
70          */
71         public static  VfModule extractVfModule(String modelCustomizationName, Group group) {
72                 
73                 String methodName = "extractVfModule";
74
75                 final VfModule vfModule = new VfModule();
76                 
77                 try {
78                         vfModule.setUuid(group.getMetadata().getVfModuleModelUUID());
79                         vfModule.setInvariantUuid(group.getMetadata().getVfModuleModelInvariantUUID());
80                         vfModule.setDescription(group.getMetadata().getDescription());
81                         vfModule.setName(group.getMetadata().getVfModuleModelName());
82                         vfModule.setVersion(group.getMetadata().getVfModuleModelVersion());
83                         vfModule.setCustomizationUuid(group.getMetadata().getVfModuleModelCustomizationUUID());
84                         vfModule.setModelCustomizationName (modelCustomizationName);
85                         vfModule.setProperties(VfModule.extractPropertiesForGroup(group));
86
87                         if (group.getProperties().containsKey(VOLUME_GROUP)) {
88                                 if (group.getProperties().get(VOLUME_GROUP) != null) {
89                                 
90                                         Class<?> c = group.getProperties().get(VOLUME_GROUP).getClass();
91                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" +
92                                                         c.getName());
93                                         
94                                         if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) {
95                                                 Boolean b = (Boolean)group.getProperties().get(VOLUME_GROUP);
96                                                 vfModule.setVolumeGroupAllowed( b.booleanValue() );
97                                         }
98                                 }
99                         } else {
100                                 vfModule.setVolumeGroupAllowed(false);
101                         }
102                 }
103                 catch ( Exception e ) {
104                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" + 
105                                         e.toString());
106                 }
107                         return vfModule;
108         }
109
110
111 }