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;
30 import org.onap.vid.asdc.beans.tosca.Input;
31 import org.onap.vid.asdc.beans.tosca.NodeTemplate;
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
38 /** The Constant LOG. */
39 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.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 description. */
51 private String description;
57 private String version;
59 /** The model customization uuid. */
60 private String customizationUuid;
63 private Map<String, Input> inputs;
65 /** The get_input or other constructs from node template properties. */
66 private Map<String, CommandProperty> commands;
68 /** The get_input or other constructs from node template properties. */
69 private Map<String, String> properties;
71 /** Type from Metadata */
74 * Instantiates a new node.
77 this.commands = new HashMap<String, CommandProperty>();
78 this.properties = new HashMap<String, String>();
86 public String getUuid() {
91 * Gets the invariant uuid.
93 * @return the invariant uuid
95 public String getInvariantUuid() {
100 * Gets the description.
102 * @return the description
104 public String getDescription() {
113 public String getName() {
120 * @return the version
122 public String getVersion() {
127 * Gets the customization uuid.
129 * @return the model customization uuid
131 public String getCustomizationUuid() {
132 return customizationUuid;
139 public Map<String, Input> getInputs() {
145 * @return the commands
147 public Map<String, CommandProperty> getCommands() {
151 * Gets the properties.
153 * @return the properties
155 public Map<String, String> getProperties() {
161 * @param uuid the new uuid
163 public void setUuid(String uuid) {
168 * Sets the invariant uuid.
170 * @param invariantUuid the new invariant uuid
172 public void setInvariantUuid(String invariantUuid) {
173 this.invariantUuid = invariantUuid;
177 * Sets the description.
179 * @param description the new description
181 public void setDescription(String description) {
182 this.description = description;
188 * @param name the new name
190 public void setName(String name) {
197 * @param version the new version
199 public void setVersion(String version) {
200 this.version = version;
203 * Sets the customization uuid.
205 * @param u the new customization uuid
207 public void setCustomizationUuid(String u) {
208 this.customizationUuid = u;
214 * @param inputs the inputs
216 public void setInputs(Map<String, Input> inputs) {
217 this.inputs = inputs;
222 * @param m the commands
224 public void setCommands( Map<String, CommandProperty>m ) {
228 * Sets the properties.
230 * @param p the properties
232 public void setProperties( Map<String, String>p) {
238 * @return metadata type
240 public String getType() {
247 * @param type e.g. VF/CP/SERVICE_PROXY
249 public void setType(String type) {
256 * @param modelCustomizationName the model customization name
257 * @param nodeTemplate the node template
260 public void extractNode (NodeTemplate nodeTemplate) {
262 String methodName = "extractNode";
264 setUuid(nodeTemplate.getMetadata().getUUID());
265 setInvariantUuid(nodeTemplate.getMetadata().getInvariantUUID());
266 setDescription(nodeTemplate.getMetadata().getDescription());
267 setName(nodeTemplate.getMetadata().getName());
268 setVersion(nodeTemplate.getMetadata().getVersion());
269 // add customizationUUID
270 setCustomizationUuid(nodeTemplate.getMetadata().getCustomizationUUID());
273 // nodeTemplate.getProperties() map of String->Object
274 for (Entry<String, Object> e : nodeTemplate.getProperties().entrySet()) {
276 String k = e.getKey();
278 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " node template property: " + k );
280 if ( e.getValue() != null ) {
281 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " +
282 k + "=" + e.getValue());
283 //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " V class name: " +
284 // e.getValue().getClass().getName());
285 Class<?> c = e.getValue().getClass();
286 if ( c.getName().equalsIgnoreCase(java.lang.String.class.getName())) {
287 getProperties().put (k, (String)e.getValue());
290 Class<?>[] interfaces = e.getValue().getClass().getInterfaces();
292 for(Class<?> ifc: interfaces ) {
293 //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +
295 if ( ifc.getName().equalsIgnoreCase(java.util.Map.class.getName()) ) {
296 // only extract get_input for now
297 @SuppressWarnings("unchecked")
298 HashMap<String,String> v = (HashMap<String,String>)e.getValue();
299 for (Entry<String, String> entry : v.entrySet()) {
300 // only include get_input for now
301 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {
302 CommandProperty cp = new CommandProperty();
303 cp.setCommand(entry.getKey());
304 cp.setInputName(entry.getValue());
305 cp.setDisplayName(k);
306 getCommands().put(k,cp);
316 catch ( Exception e ) {
317 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse node properties: e=" +