2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.model;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26 import java.util.HashMap;
28 import java.util.Map.Entry;
29 import org.onap.vid.asdc.beans.tosca.Group;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
36 public class VfModule {
38 /** The Constant LOG. */
39 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.class);
41 /** The Constant dateFormat. */
42 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
47 /** The invariant uuid. */
48 private String invariantUuid;
50 /** The customization uuid. */
51 private String customizationUuid;
53 /** The description. */
54 private String description;
60 private String version;
62 /** The volume group allowed. */
63 private boolean volumeGroupAllowed;
65 /** The get_input or other constructs for VF Module. */
66 private Map<String, CommandProperty> commands;
68 /** The model customization name. */
69 private String modelCustomizationName;
72 * Instantiates a new vf module.
75 commands = new HashMap<String, CommandProperty>();
78 * Gets the model customization name.
80 * @return the model customization name
82 public String getModelCustomizationName() {
83 return modelCustomizationName;
90 public String getUuid() {
95 * Gets the invariant uuid.
97 * @return the invariant uuid
99 public String getInvariantUuid() {
100 return invariantUuid;
103 * Gets the customization uuid.
105 * @return the invariant uuid
107 public String getCustomizationUuid() {
108 return customizationUuid;
111 * Gets the description.
113 * @return the description
115 public String getDescription() {
121 * @return the commands
123 public Map<String, CommandProperty> getCommands() {
131 public String getName() {
138 * @return the version
140 public String getVersion() {
145 * Checks if is volume group allowed.
147 * @return true, if is volume group allowed
149 public boolean isVolumeGroupAllowed() {
150 return volumeGroupAllowed;
156 * @param uuid the new uuid
158 public void setUuid(String uuid) {
163 * Sets the invariant uuid.
165 * @param invariantUuid the new invariant uuid
167 public void setInvariantUuid(String invariantUuid) {
168 this.invariantUuid = invariantUuid;
171 * Sets the customization uuid.
173 * @param customizationUuid the new customization uuid
175 public void setCustomizationUuid(String customizationUuid) {
176 this.customizationUuid = customizationUuid;
179 * Sets the description.
181 * @param description the new description
183 public void setDescription(String description) {
184 this.description = description;
190 * @param name the new name
192 public void setName(String name) {
199 * @param version the new version
201 public void setVersion(String version) {
202 this.version = version;
206 * Sets the volume group allowed.
208 * @param volumeGroupAllowed the new volume group allowed
210 public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
211 this.volumeGroupAllowed = volumeGroupAllowed;
216 * @param m the commands
218 public void setCommands( Map<String, CommandProperty>m ) {
222 * Sets the model customization name.
224 * @param modelCustomizationName the new model customization name
226 public void setModelCustomizationName(String modelCustomizationName) {
227 this.modelCustomizationName = modelCustomizationName;
232 * @param group the group
233 * @return the vf module
235 public static VfModule extractVfModule(String modelCustomizationName, Group group) {
237 String methodName = "extractVfModule";
239 final VfModule vfModule = new VfModule();
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);
250 if (group.getProperties().containsKey("volume_group")) {
251 if (group.getProperties().get("volume_group") != null) {
253 Class<?> c = group.getProperties().get("volume_group").getClass();
254 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" +
257 if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) {
258 Boolean b = (Boolean)group.getProperties().get("volume_group");
259 vfModule.setVolumeGroupAllowed( b.booleanValue() );
263 vfModule.setVolumeGroupAllowed(false);
266 catch ( Exception e ) {
267 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" +
270 /* Not extracting other types of properties for 1702
273 for (Entry<String, Object> e : group.getProperties().entrySet()) {
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();
283 for(Class<?> ifc: interfaces ){
284 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +
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());
296 (vfModule.getCommands()).put(k,cp);
302 catch ( Exception e ) {
303 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module properties: e=" +