2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.model;
\r
23 import java.text.DateFormat;
\r
24 import java.text.SimpleDateFormat;
\r
25 import java.util.Date;
\r
26 import java.util.HashMap;
\r
27 import java.util.Map;
\r
28 import java.util.Map.Entry;
\r
30 import org.openecomp.vid.asdc.beans.tosca.Input;
\r
31 import org.openecomp.vid.asdc.beans.tosca.NodeTemplate;
\r
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
38 /** The Constant LOG. */
\r
39 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class);
\r
41 /** The Constant dateFormat. */
\r
42 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
45 private String uuid;
\r
47 /** The invariant uuid. */
\r
48 private String invariantUuid;
\r
50 /** The description. */
\r
51 private String description;
\r
54 private String name;
\r
57 private String version;
\r
59 /** The model customization uuid. */
\r
60 private String customizationUuid;
\r
63 private Map<String, Input> inputs;
\r
65 /** The get_input or other constructs from node template properties. */
\r
66 private Map<String, CommandProperty> commands;
\r
68 /** The get_input or other constructs from node template properties. */
\r
69 private Map<String, String> properties;
\r
71 * Instantiates a new node.
\r
74 this.commands = new HashMap<String, CommandProperty>();
\r
75 this.properties = new HashMap<String, String>();
\r
83 public String getUuid() {
\r
88 * Gets the invariant uuid.
\r
90 * @return the invariant uuid
\r
92 public String getInvariantUuid() {
\r
93 return invariantUuid;
\r
97 * Gets the description.
\r
99 * @return the description
\r
101 public String getDescription() {
\r
102 return description;
\r
110 public String getName() {
\r
115 * Gets the version.
\r
117 * @return the version
\r
119 public String getVersion() {
\r
124 * Gets the customization uuid.
\r
126 * @return the model customization uuid
\r
128 public String getCustomizationUuid() {
\r
129 return customizationUuid;
\r
134 * @return the inputs
\r
136 public Map<String, Input> getInputs() {
\r
140 * Gets the commands.
\r
142 * @return the commands
\r
144 public Map<String, CommandProperty> getCommands() {
\r
148 * Gets the properties.
\r
150 * @return the properties
\r
152 public Map<String, String> getProperties() {
\r
158 * @param uuid the new uuid
\r
160 public void setUuid(String uuid) {
\r
165 * Sets the invariant uuid.
\r
167 * @param invariantUuid the new invariant uuid
\r
169 public void setInvariantUuid(String invariantUuid) {
\r
170 this.invariantUuid = invariantUuid;
\r
174 * Sets the description.
\r
176 * @param description the new description
\r
178 public void setDescription(String description) {
\r
179 this.description = description;
\r
185 * @param name the new name
\r
187 public void setName(String name) {
\r
192 * Sets the version.
\r
194 * @param version the new version
\r
196 public void setVersion(String version) {
\r
197 this.version = version;
\r
200 * Sets the customization uuid.
\r
202 * @param u the new customization uuid
\r
204 public void setCustomizationUuid(String u) {
\r
205 this.customizationUuid = u;
\r
211 * @param inputs the inputs
\r
213 public void setInputs(Map<String, Input> inputs) {
\r
214 this.inputs = inputs;
\r
217 * Sets the commands.
\r
219 * @param m the commands
\r
221 public void setCommands( Map<String, CommandProperty>m ) {
\r
225 * Sets the properties.
\r
227 * @param p the properties
\r
229 public void setProperties( Map<String, String>p) {
\r
235 * @param modelCustomizationName the model customization name
\r
236 * @param nodeTemplate the node template
\r
239 public void extractNode (NodeTemplate nodeTemplate) {
\r
241 String methodName = "extractNode";
\r
243 setUuid(nodeTemplate.getMetadata().getUUID());
\r
244 setInvariantUuid(nodeTemplate.getMetadata().getInvariantUUID());
\r
245 setDescription(nodeTemplate.getMetadata().getDescription());
\r
246 setName(nodeTemplate.getMetadata().getName());
\r
247 setVersion(nodeTemplate.getMetadata().getVersion());
\r
248 // add customizationUUID
\r
249 setCustomizationUuid(nodeTemplate.getMetadata().getCustomizationUUID());
\r
252 // nodeTemplate.getProperties() map of String->Object
\r
253 for (Entry<String, Object> e : nodeTemplate.getProperties().entrySet()) {
\r
255 String k = e.getKey();
\r
257 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " node template property: " + k );
\r
259 if ( e.getValue() != null ) {
\r
260 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " +
\r
261 k + "=" + e.getValue());
\r
262 //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " V class name: " +
\r
263 // e.getValue().getClass().getName());
\r
264 Class<?> c = e.getValue().getClass();
\r
265 if ( c.getName().equalsIgnoreCase(java.lang.String.class.getName())) {
\r
266 getProperties().put (k, (String)e.getValue());
\r
269 Class<?>[] interfaces = e.getValue().getClass().getInterfaces();
\r
271 for(Class<?> ifc: interfaces ) {
\r
272 //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +
\r
274 if ( ifc.getName().equalsIgnoreCase(java.util.Map.class.getName()) ) {
\r
275 // only extract get_input for now
\r
276 @SuppressWarnings("unchecked")
\r
277 HashMap<String,String> v = (HashMap<String,String>)e.getValue();
\r
278 for (Entry<String, String> entry : v.entrySet()) {
\r
279 // only include get_input for now
\r
280 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {
\r
281 CommandProperty cp = new CommandProperty();
\r
282 cp.setCommand(entry.getKey());
\r
283 cp.setInputName(entry.getValue());
\r
284 cp.setDisplayName(k);
\r
285 getCommands().put(k,cp);
\r
295 catch ( Exception e ) {
\r
296 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse node properties: e=" +
\r