* ================================================================================
* 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.
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;
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";
try (FileInputStream in = new FileInputStream(configDir + "/" + TEMPLATE_PROPERTIES_FILE_NAME)) {
props.load(in);
} catch (Exception e) {
- logger.error("Caught exception loading properties!", e);
+ logger.warn("Properties not loaded for template node, using sensible defaults. " + e.getMessage());
}
// give sensible defaults for required properties
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());
}
}
-}
\ No newline at end of file
+}