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.onap.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 = new HashMap<>();
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> entrySet : nodeTemplate.getProperties().entrySet()) {
275 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " node template property: " + entrySet.getKey());
276 if ( entrySet.getValue() != null ) {
277 readStringAndCommandsProperties(entrySet);
281 catch ( Exception e ) {
282 LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse node properties: e=" +
287 private void readStringAndCommandsProperties(Entry<String, Object> entrySet) {
288 String key = entrySet.getKey();
289 String methodName = "readStringAndCommandsProperties";
290 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " +
291 key + "=" + entrySet.getValue());
292 Class<?> c = entrySet.getValue().getClass();
293 if ( c.getName().equalsIgnoreCase(String.class.getName())) {
294 getProperties().put (key, (String) entrySet.getValue());
297 Class<?>[] interfaces = entrySet.getValue().getClass().getInterfaces();
299 for(Class<?> ifc: interfaces ) {
300 if ( ifc.getName().equalsIgnoreCase(Map.class.getName()) ) {
301 readGetInputAsCommands(entrySet, key);
309 private void readGetInputAsCommands(Entry<String, Object> entrySet, String key) {
310 // only extract get_input for now
311 @SuppressWarnings("unchecked")
312 HashMap<String,String> v = (HashMap<String,String>) entrySet.getValue();
313 for (Entry<String, String> entry : v.entrySet()) {
314 // only include get_input for now
315 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {
316 CommandProperty cp = new CommandProperty();
317 cp.setCommand(entry.getKey());
318 cp.setInputName(entry.getValue());
319 cp.setDisplayName(key);
320 getCommands().put(key,cp);