Merge "Sonar fix: TemplateNode.java"
[ccsdk/sli/plugins.git] / template-node / provider / src / main / java / org / onap / ccsdk / sli / plugins / template / TemplateNode.java
old mode 100644 (file)
new mode 100755 (executable)
index 8a96768..a78b81e
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *                     reserved.
+ * Modifications Copyright © 2018 IBM.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +25,7 @@ package org.onap.ccsdk.sli.plugins.template;
 import java.io.FileInputStream;
 import java.io.StringWriter;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
@@ -37,10 +39,10 @@ import org.slf4j.LoggerFactory;
 
 public class TemplateNode implements SvcLogicJavaPlugin {
     private static final Logger logger = LoggerFactory.getLogger(TemplateNode.class);
-    public final static String TEMPLATE_PATH = "templatePath";
-    public final static String OUTPUT_PATH_KEY = "output";
-    public final static String PREFIX_KEY = "prefix";
-    public final static String REQUIRED_PARAMETERS_ERROR_MESSAGE = "templateName & outputPath are required fields";
+    public static final String TEMPLATE_PATH = "templatePath";
+    public static final String OUTPUT_PATH_KEY = "output";
+    public static final String PREFIX_KEY = "prefix";
+    public static final String REQUIRED_PARAMETERS_ERROR_MESSAGE = "templateName & outputPath are required fields";
     protected static final String TEMPLATE_PROPERTIES_FILE_NAME = "template-node.properties";
     protected static final String DEFAULT_PROPERTIES_DIR = "/opt/onap/ccsdk/data/properties";
     protected static final String PROPERTIES_DIR_KEY = "SDNC_CONFIG_DIR";
@@ -51,6 +53,7 @@ public class TemplateNode implements SvcLogicJavaPlugin {
         ve = new VelocityEngine();
         setProperties();
         ve.init();
+        ve.loadDirective("org.onap.ccsdk.sli.plugins.template.HideNullJson");
     }
 
     protected void setProperties() {
@@ -96,6 +99,10 @@ public class TemplateNode implements SvcLogicJavaPlugin {
                 VelocityContext context = new VelocityContext();
                 context.put("ctx", ctx);
                 context.put("params", params);
+                //Adding these values directly to context makes working with the values cleaner
+                for (Entry<String, String> entry : params.entrySet()) {
+                    context.put(entry.getKey(), entry.getValue());
+                }
                 StringWriter sw = new StringWriter();
                 template.merge(context, sw);
                 ctx.setAttribute(outputPath, sw.toString());
@@ -105,4 +112,4 @@ public class TemplateNode implements SvcLogicJavaPlugin {
         }
     }
 
-}
\ No newline at end of file
+}