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.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.sdc.toscaparser.api.Property;
37 public class VfModule {
39 /** The Constant LOG. */
40 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.class);
42 /** The Constant dateFormat. */
43 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
48 /** The invariant uuid. */
49 private String invariantUuid;
51 /** The customization uuid. */
52 private String customizationUuid;
54 /** The description. */
55 private String description;
61 private String version;
63 /** The volume group allowed. */
64 private boolean volumeGroupAllowed;
66 /** The get_input or other constructs for VF Module. */
67 private Map<String, CommandProperty> commands;
69 /** The model customization name. */
70 private String modelCustomizationName;
72 /** The model properties. */
73 private Map<String, Property> properties;
76 * Instantiates a new vf module.
79 commands = new HashMap<String, CommandProperty>();
82 * Gets the model customization name.
84 * @return the model customization name
86 public String getModelCustomizationName() {
87 return modelCustomizationName;
94 public String getUuid() {
99 * Gets the invariant uuid.
101 * @return the invariant uuid
103 public String getInvariantUuid() {
104 return invariantUuid;
107 * Gets the customization uuid.
109 * @return the invariant uuid
111 public String getCustomizationUuid() {
112 return customizationUuid;
115 * Gets the description.
117 * @return the description
119 public String getDescription() {
125 * @return the commands
127 public Map<String, CommandProperty> getCommands() {
135 public String getName() {
142 * @return the version
144 public String getVersion() {
149 * Checks if is volume group allowed.
151 * @return true, if is volume group allowed
153 public boolean isVolumeGroupAllowed() {
154 return volumeGroupAllowed;
160 * @param uuid the new uuid
162 public void setUuid(String uuid) {
167 * Sets the invariant uuid.
169 * @param invariantUuid the new invariant uuid
171 public void setInvariantUuid(String invariantUuid) {
172 this.invariantUuid = invariantUuid;
175 * Sets the customization uuid.
177 * @param customizationUuid the new customization uuid
179 public void setCustomizationUuid(String customizationUuid) {
180 this.customizationUuid = customizationUuid;
183 * Sets the description.
185 * @param description the new description
187 public void setDescription(String description) {
188 this.description = description;
194 * @param name the new name
196 public void setName(String name) {
203 * @param version the new version
205 public void setVersion(String version) {
206 this.version = version;
210 * Sets the volume group allowed.
212 * @param volumeGroupAllowed the new volume group allowed
214 public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {
215 this.volumeGroupAllowed = volumeGroupAllowed;
220 * @param m the commands
222 public void setCommands( Map<String, CommandProperty>m ) {
226 * Sets the model customization name.
228 * @param modelCustomizationName the new model customization name
230 public void setModelCustomizationName(String modelCustomizationName) {
231 this.modelCustomizationName = modelCustomizationName;
236 * @param group the group
237 * @return the vf module
239 public static VfModule extractVfModule(String modelCustomizationName, Group group) {
241 String methodName = "extractVfModule";
243 final VfModule vfModule = new VfModule();
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());
255 if (group.getProperties().containsKey("volume_group")) {
256 if (group.getProperties().get("volume_group") != null) {
258 Class<?> c = group.getProperties().get("volume_group").getClass();
259 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" +
262 if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) {
263 Boolean b = (Boolean)group.getProperties().get("volume_group");
264 vfModule.setVolumeGroupAllowed( b.booleanValue() );
268 vfModule.setVolumeGroupAllowed(false);
271 catch ( Exception e ) {
272 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" +
275 /* Not extracting other types of properties for 1702
278 for (Entry<String, Object> e : group.getProperties().entrySet()) {
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();
288 for(Class<?> ifc: interfaces ){
289 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +
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());
301 (vfModule.getCommands()).put(k,cp);
307 catch ( Exception e ) {
308 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module properties: e=" +
313 public Map<String, Property> getProperties() {
316 public void setProperties(Map<String, Property> properties) {
317 this.properties = properties;