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