Sonar fixes in whole module
Change-Id: I55856a6ce73a73098dadb2c5b9428437349ed8a8
Issue-ID: APPC-671
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
17 files changed:
public class ConfigGeneratorActivator implements BundleActivator {
public class ConfigGeneratorActivator implements BundleActivator {
- private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
-
+ private static final String STR_REGISTERING_SERVICE = "Registering service ";
+ private static final String STR_REGISTERING_SERVICE_SUCCESS = "Registering service successful for ";
+ private List<ServiceRegistration> registrations = new LinkedList<>();
private static final EELFLogger log =
EELFManager.getInstance().getLogger(ConfigGeneratorActivator.class);
private static final EELFLogger log =
EELFManager.getInstance().getLogger(ConfigGeneratorActivator.class);
public void start(BundleContext ctx) throws Exception {
ConvertNode convertNode = new ConvertNode();
public void start(BundleContext ctx) throws Exception {
ConvertNode convertNode = new ConvertNode();
- log.info("Registering service " + convertNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE + convertNode.getClass().getName());
registrations.add(ctx.registerService(convertNode.getClass().getName(), convertNode, null));
registrations.add(ctx.registerService(convertNode.getClass().getName(), convertNode, null));
- log.info("Registering service sccessful for " + convertNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + convertNode.getClass().getName());
MergeNode mergeNode = new MergeNode();
MergeNode mergeNode = new MergeNode();
- log.info("Registering service " + mergeNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE + mergeNode.getClass().getName());
registrations.add(ctx.registerService(mergeNode.getClass().getName(), mergeNode, null));
registrations.add(ctx.registerService(mergeNode.getClass().getName(), mergeNode, null));
- log.info("Registering service sccessful for " + mergeNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + mergeNode.getClass().getName());
PatternNode patternNode = new PatternNode();
PatternNode patternNode = new PatternNode();
- log.info("Registering service " + patternNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE + patternNode.getClass().getName());
registrations.add(ctx.registerService(patternNode.getClass().getName(), patternNode, null));
registrations.add(ctx.registerService(patternNode.getClass().getName(), patternNode, null));
- log.info("Registering service sccessful for " + patternNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + patternNode.getClass().getName());
ReaderNode readerNode = new ReaderNode();
ReaderNode readerNode = new ReaderNode();
- log.info("Registering service " + readerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE + readerNode.getClass().getName());
registrations.add(ctx.registerService(readerNode.getClass().getName(), readerNode, null));
registrations.add(ctx.registerService(readerNode.getClass().getName(), readerNode, null));
- log.info("Registering service sccessful for " + readerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + readerNode.getClass().getName());
FileWriterNode writerNode = new FileWriterNode();
FileWriterNode writerNode = new FileWriterNode();
- log.info("Registering service " + writerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE + writerNode.getClass().getName());
registrations.add(ctx.registerService(writerNode.getClass().getName(), writerNode, null));
registrations.add(ctx.registerService(writerNode.getClass().getName(), writerNode, null));
- log.info("Registering service sccessful for " + writerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + writerNode.getClass().getName());
public void stop(BundleContext arg0) throws Exception {
for (ServiceRegistration registration : registrations) {
registration.unregister();
public void stop(BundleContext arg0) throws Exception {
for (ServiceRegistration registration : registrations) {
registration.unregister();
public class ConfigGeneratorConstant {
public class ConfigGeneratorConstant {
public static final String STRING_ENCODING = "utf-8";
public static final String Y = "Y";
public static final String N = "N";
public static final String STRING_ENCODING = "utf-8";
public static final String Y = "Y";
public static final String N = "N";
public static final String INPUT_PARAM_REQUEST_DATA = "requestData";
public static final String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix";
public static final String INPUT_PARAM_REQUEST_DATA = "requestData";
public static final String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix";
public static final String OUTPUT_PARAM_MERGED_DATA = "mergedData";
public static final String OUTPUT_PARAM_TRANSFORMED_DATA = "transformedData";
public static final String OUTPUT_PARAM_FILE_DATA = "fileData";
public static final String OUTPUT_PARAM_MERGED_DATA = "mergedData";
public static final String OUTPUT_PARAM_TRANSFORMED_DATA = "transformedData";
public static final String OUTPUT_PARAM_FILE_DATA = "fileData";
public static final String INPUT_PARAM_CONTEXT_KEY = "contextKey";
public static final String INPUT_PARAM_JSON_CONTENT = "jsonContent";
public static final String INPUT_PARAM_CONTEXT_KEY = "contextKey";
public static final String INPUT_PARAM_JSON_CONTENT = "jsonContent";
+ private ConfigGeneratorConstant(){}
}
private String tryFetchEscapedData(String unEscapeData, String dataType) throws InvalidParameterException {
}
private String tryFetchEscapedData(String unEscapeData, String dataType) throws InvalidParameterException {
- if (StringUtils.isBlank(unEscapeData)) {
- throw new InvalidParameterException("Unescape (" + ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA
- + ") param is missing for escapeData conversion." + unEscapeData);
- }
- if (StringUtils.isBlank(dataType)) {
- throw new InvalidParameterException(DATA_TYPE_STR + ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE
- + ")param is missing for escapeData conversion.");
- }
+ validateInput(unEscapeData, dataType);
if (ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(dataType)) {
return StringEscapeUtils.escapeJavaScript(unEscapeData);
} else if (ConfigGeneratorConstant.DATA_TYPE_XML.equalsIgnoreCase(dataType)) {
if (ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(dataType)) {
return StringEscapeUtils.escapeJavaScript(unEscapeData);
} else if (ConfigGeneratorConstant.DATA_TYPE_XML.equalsIgnoreCase(dataType)) {
+ private void validateInput(String unEscapeData, String dataType) throws InvalidParameterException {
+ if (StringUtils.isBlank(unEscapeData)) {
+ throw new InvalidParameterException("Unescape (" + ConfigGeneratorConstant.INPUT_PARAM_UNESCAPE_DATA
+ + ") param is missing for escapeData conversion." + unEscapeData);
+ }
+ if (StringUtils.isBlank(dataType)) {
+ throw new InvalidParameterException(DATA_TYPE_STR + ConfigGeneratorConstant.INPUT_PARAM_DATA_TYPE
+ + ")param is missing for escapeData conversion.");
+ }
+ }
+
public void unEscapeData(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
log.trace("Received unEscapeData call with params : " + inParams);
public void unEscapeData(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
log.trace("Received unEscapeData call with params : " + inParams);
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeNode.class);
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeNode.class);
- public void mergeDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx)
- throws SvcLogicException { /* TODO implement this method */ }
+ public void mergeDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ /* TODO implement this method */
+ }
public void mergeJsonDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
public void mergeJsonDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
- public void mergeYamlDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx)
- throws SvcLogicException { /* TODO implement this method */}
+ public void mergeYamlDataOnTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ /* TODO implement this method */
+ }
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
+import org.onap.sdnc.config.generator.merge.ParameterMissingException;
import org.onap.sdnc.config.generator.tool.CheckDataTool;
import org.onap.sdnc.config.generator.tool.LogParserTool;
import org.onap.sdnc.config.generator.tool.CheckDataTool;
import org.onap.sdnc.config.generator.tool.LogParserTool;
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
String logData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA);
if (StringUtils.isBlank(logData)) {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
String logData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA);
if (StringUtils.isBlank(logData)) {
- throw new Exception("Log Data is missing");
+ throw new ParameterMissingException("Log Data is missing");
}
LogParserTool logParserTool = new LogParserTool();
String parsedError = logParserTool.parseErrorLog(logData);
}
LogParserTool logParserTool = new LogParserTool();
String parsedError = logParserTool.parseErrorLog(logData);
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
- log.error("Failed in parsing error log " + e.getMessage());
+ log.error("Failed in parsing error log", e);
throw new SvcLogicException(e.getMessage());
}
}
throw new SvcLogicException(e.getMessage());
}
}
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
String checkData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA);
if (StringUtils.isBlank(checkData)) {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
String checkData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA);
if (StringUtils.isBlank(checkData)) {
- throw new Exception("Check Data is missing");
+ throw new ParameterMissingException("Check Data is missing");
}
String dataType = CheckDataTool.checkData(checkData);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_DATA_TYPE,
}
String dataType = CheckDataTool.checkData(checkData);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_DATA_TYPE,
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
- log.error("Failed in checkDataType " + e.getMessage());
+ log.error("Failed in checkDataType", e);
throw new SvcLogicException(e.getMessage());
}
}
throw new SvcLogicException(e.getMessage());
}
}
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeNode.class);
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeNode.class);
public void getFileData(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
log.info("Received getFileData call with params : " + inParams);
public void getFileData(Map<String, String> inParams, SvcLogicContext ctx)
throws SvcLogicException {
log.info("Received getFileData call with params : " + inParams);
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
- log.error("Failed in merging data to template " + e.getMessage());
+ log.error("Failed in merging data to template", e);
throw new SvcLogicException(e.getMessage());
}
}
throw new SvcLogicException(e.getMessage());
}
}
package org.onap.sdnc.config.generator.tool;
package org.onap.sdnc.config.generator.tool;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
-import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class CheckDataTool {
import org.xml.sax.InputSource;
public class CheckDataTool {
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CheckDataTool.class);
+ private static final String STR_INPUT_DATA = "Input data: \n";
+
+ private CheckDataTool() {}
+
public static String checkData(String data) {
boolean isJSON = isJSON(data);
if (isJSON) {
public static String checkData(String data) {
boolean isJSON = isJSON(data);
if (isJSON) {
try {
new JSONObject(data);
} catch (JSONException ex) {
try {
new JSONObject(data);
} catch (JSONException ex) {
+ logger.error(STR_INPUT_DATA + data + "\n is not json object", ex);
try {
new JSONArray(data);
} catch (JSONException ex1) {
try {
new JSONArray(data);
} catch (JSONException ex1) {
+ logger.error(STR_INPUT_DATA + data + "\n is not json array", ex1);
return false;
}
}
return true;
return false;
}
}
return true;
-
- // try {
- // final ObjectMapper mapper = new ObjectMapper();
- // mapper.readTree(data);
- // return true;
- // } catch (IOException e) {
- // return false;
- // }
}
public static boolean isXML(String data) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
}
public static boolean isXML(String data) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(new InputSource(new StringReader(data)));
+ dBuilder.parse(new InputSource(new StringReader(data)));
return true;
} catch (Exception ex) {
return true;
} catch (Exception ex) {
+ logger.error(STR_INPUT_DATA + data + "\n is not xml document", ex);
- public static final String DBLIB_SERVICE =
- "org.onap.ccsdk.sli.core.dblib.DBResourceManager";
+ public static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DBResourceManager";
public static final String DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION";
public static final String SCHEMA_SDNCTL = "SDNCTL";
public static final String DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION";
public static final String SCHEMA_SDNCTL = "SDNCTL";
public static final String APPC_CONFIG_DIR = "/opt/onap/appc/data/properties";
public static final String APPC_CONFIG_DIR = "/opt/onap/appc/data/properties";
public class CustomJsonNodeFactory extends JsonNodeFactory {
public class CustomJsonNodeFactory extends JsonNodeFactory {
public TextNode textNode(String text) {
return new CustomTextNode(text);
}
public TextNode textNode(String text) {
return new CustomTextNode(text);
}
}
protected static void appendQuoted(StringBuilder sb, String content) {
}
protected static void appendQuoted(StringBuilder sb, String content) {
CharTypes.appendQuoted(sb, content);
CharTypes.appendQuoted(sb, content);
package org.onap.sdnc.config.generator.tool;
package org.onap.sdnc.config.generator.tool;
+import com.google.common.collect.Lists;
import java.io.File;
import java.net.URL;
import java.sql.SQLException;
import java.util.ArrayList;
import java.io.File;
import java.net.URL;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import javax.sql.rowset.CachedRowSet;
import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import java.util.Properties;
import javax.sql.rowset.CachedRowSet;
import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
- private static Properties props;
+ private static Properties properties;
private static DBResourceManager jdbcDataSource = null;
private static DBResourceManager jdbcDataSource = null;
- public static boolean updateDB(String tableName, ArrayList inputArgs, String scema,
- String whereClause, String setCluase) throws SQLException {
+ public static boolean updateDB(String tableName, List<String> inputArgs, String whereClause, String setClause)
+ throws SQLException {
String updatePasswordString =
String updatePasswordString =
- "update " + tableName + " set " + setCluase + " where " + whereClause;
- boolean result =
- jdbcDataSource.writeData(updatePasswordString, inputArgs, Constants.SCHEMA_SDNCTL);
- return result;
+ "update " + tableName + " set " + setClause + " where " + whereClause;
+
+ return jdbcDataSource.writeData(updatePasswordString, Lists.newArrayList(inputArgs), Constants.SCHEMA_SDNCTL);
- public static CachedRowSet getData(String tableName, ArrayList argList, String schema,
+ public static CachedRowSet getData(String tableName, List<String> argList, String schema,
String getselectData, String getDataClasue) throws SQLException {
String selectQuery =
"select " + getselectData + "from " + tableName + " where " + getDataClasue;
String getselectData, String getDataClasue) throws SQLException {
String selectQuery =
"select " + getselectData + "from " + tableName + " where " + getDataClasue;
- CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema);
- return data;
+ return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
}
public static DBResourceManager initDbLibService() throws Exception {
}
public static DBResourceManager initDbLibService() throws Exception {
- props = new Properties();
+ properties = new Properties();
File file = new File("/opt/onap/appc/data/properties/dblib.properties");
URL propURL = file.toURI().toURL();
File file = new File("/opt/onap/appc/data/properties/dblib.properties");
URL propURL = file.toURI().toURL();
- props.load(propURL.openStream());
+ properties.load(propURL.openStream());
// this is an expected difference in CCSDK
// this is an expected difference in CCSDK
- jdbcDataSource = new DBResourceManager(props);
+ jdbcDataSource = new DBResourceManager(properties);
public class EscapeUtils {
public class EscapeUtils {
- public EscapeUtils() {
- // TODO Auto-generated constructor stub
- }
+ private EscapeUtils() {}
public static String escapeSql(String str) {
if (str == null) {
public static String escapeSql(String str) {
if (str == null) {
private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
private String[] singleLines;
private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
private String[] singleLines;
- private List<String> recentErrors = new ArrayList<String>();
- ;
+ private List<String> recentErrors = new ArrayList<>();
private Date todaysDate = new Date();
private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private Date todaysDate = new Date();
private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- private final int minMilli = 60000;
- private final int IN_TIME = 0;
- private final int NOT_IN_TIME = 1;
- private final int NO_DATE = 2;
+
+ private static final int MIN_MILLI = 60000;
+ private static final int IN_TIME = 0;
+ private static final int NOT_IN_TIME = 1;
+ private static final int NO_DATE = 2;
public String parseErrorLog(String data) {
singleLines = data.split("\\r?\\n");
public String parseErrorLog(String data) {
singleLines = data.split("\\r?\\n");
getNearestDates();
} catch (Exception e) {
getNearestDates();
} catch (Exception e) {
+ log.error("Failed to get nearest dates", e);
- if (recentErrors.size() == 0) {
+ if (recentErrors.isEmpty()) {
recentErrors.clear();
return "Did not find the string 'Starting orchestration of file backed up to /var/opt/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes";
} else if (recentErrors.size() == 1) {
recentErrors.clear();
return "Did not find the string 'Starting orchestration of file backed up to /var/opt/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes";
} else if (recentErrors.size() == 1) {
- public void getNearestDates() throws ParseException {
+ private void getNearestDates() throws ParseException {
int result;
for (int i = singleLines.length - 1; i >= 0; i--) {
if (singleLines[i].contains("Starting orchestration of file backed up to")
int result;
for (int i = singleLines.length - 1; i >= 0; i--) {
if (singleLines[i].contains("Starting orchestration of file backed up to")
Date newDate;
try {
newDate = dFormat.parse(line.substring(0, 19));
Date newDate;
try {
newDate = dFormat.parse(line.substring(0, 19));
- if ((todaysDate.getTime() - newDate.getTime()) <= 5 * minMilli) {
+ if ((todaysDate.getTime() - newDate.getTime()) <= 5 * MIN_MILLI) {
return IN_TIME;
} else {
return NOT_IN_TIME;
}
} catch (ParseException e) {
return IN_TIME;
} else {
return NOT_IN_TIME;
}
} catch (ParseException e) {
+ log.error("Failed to parse date", e);
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
+ private MergeTool() {}
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeTool.class);
public static String mergeMap2TemplateData(String template, Map<String, String> dataMap) {
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeTool.class);
public static String mergeMap2TemplateData(String template, Map<String, String> dataMap) {
Template t = ve.getTemplate("TemplateResource");
VelocityContext context = new VelocityContext();
Template t = ve.getTemplate("TemplateResource");
VelocityContext context = new VelocityContext();
- Iterator<Map.Entry<String, String>> entries = dataMap.entrySet().iterator();
- while (entries.hasNext()) {
- Map.Entry<String, String> entry = entries.next();
+ for (Entry<String, String> entry : dataMap.entrySet()) {
context.put(entry.getKey(), entry.getValue());
}
t.merge(context, writer);
return writer.toString();
}
context.put(entry.getKey(), entry.getValue());
}
t.merge(context, writer);
return writer.toString();
}
public static String mergeJson2TemplateData(String template, String jsonData,
public static String mergeJson2TemplateData(String template, String jsonData,
- String templateType, String doPrettyOutput)
- throws JsonParseException, JsonMappingException, IOException {
+ String templateType, String doPrettyOutput) throws IOException {
+
String mergedData = template;
if (StringUtils.isNotBlank(template) && StringUtils.isNotBlank(jsonData)) {
Velocity.init();
String mergedData = template;
if (StringUtils.isNotBlank(template) && StringUtils.isNotBlank(jsonData)) {
Velocity.init();
writer.flush();
mergedData = writer.toString();
writer.flush();
mergedData = writer.toString();
- if (StringUtils.isNotBlank(templateType) && StringUtils.isNotBlank(doPrettyOutput)
- && ConfigGeneratorConstant.Y.equalsIgnoreCase(doPrettyOutput)
- && (ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(templateType)
- || ConfigGeneratorConstant.DATA_TYPE_XML
- .equalsIgnoreCase(templateType))) {
+ if (prettyPrint(templateType, doPrettyOutput)) {
+ private static boolean isJsonOrXml(String templateType) {
+ return ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(templateType)
+ || ConfigGeneratorConstant.DATA_TYPE_XML.equalsIgnoreCase(templateType);
+ private static boolean prettyPrint(String templateType, String doPrettyOutput) {
+ return StringUtils.isNotBlank(templateType) && StringUtils.isNotBlank(doPrettyOutput)
+ && ConfigGeneratorConstant.Y.equalsIgnoreCase(doPrettyOutput) && isJsonOrXml(templateType);
+ }
import java.nio.charset.Charset;
import java.util.Map;
import javax.xml.transform.Transformer;
import java.nio.charset.Charset;
import java.util.Map;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
+import org.onap.sdnc.config.generator.merge.ParameterMissingException;
public class XSLTTransformerNode implements SvcLogicJavaPlugin {
public class XSLTTransformerNode implements SvcLogicJavaPlugin {
}
}
if (StringUtils.isBlank(templateData)) {
}
}
if (StringUtils.isBlank(templateData)) {
- throw new Exception("In-param templateFile/templateData value is missing");
+ throw new ParameterMissingException("In-param templateFile/templateData value is missing");
}
String requestData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA);
if (StringUtils.isBlank(requestData)) {
}
String requestData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA);
if (StringUtils.isBlank(requestData)) {
- throw new Exception("In-param requestData value is missing");
+ throw new ParameterMissingException("In-param requestData value is missing");
}
String transformedData = transform(requestData, templateData);
}
String transformedData = transform(requestData, templateData);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
} catch (Exception e) {
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
} catch (Exception e) {
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
e.getMessage());
- log.error("Failed in XSLTTransformerNode : " + e.getMessage());
+ log.error("Failed in XSLTTransformerNode", e);
throw new SvcLogicException(e.getMessage());
}
}
throw new SvcLogicException(e.getMessage());
}
}
- public String transform(String requestData, String templateData)
- throws TransformerConfigurationException, TransformerException {
+ private String transform(String requestData, String templateData) throws TransformerException {
StringWriter xmlResultResource = new StringWriter();
StringWriter xmlResultResource = new StringWriter();
- Transformer xmlTransformer = TransformerFactory.newInstance()
+
+ Transformer xmlTransformer = TransformerFactory
+ .newInstance()
.newTransformer(new StreamSource(new StringReader(templateData)));
.newTransformer(new StreamSource(new StringReader(templateData)));
- xmlTransformer.transform(new StreamSource(new StringReader(requestData)),
- new StreamResult(xmlResultResource));
+
+ xmlTransformer
+ .transform(new StreamSource(new StringReader(requestData)), new StreamResult(xmlResultResource));
+
return xmlResultResource.getBuffer().toString();
}
return xmlResultResource.getBuffer().toString();
}
package org.onap.sdnc.config.generator.writer;
package org.onap.sdnc.config.generator.writer;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.File;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
public class FileWriterNode implements SvcLogicJavaPlugin {
private static final EELFLogger log = EELFManager.getInstance().getLogger(FileWriterNode.class);
public class FileWriterNode implements SvcLogicJavaPlugin {
private static final EELFLogger log = EELFManager.getInstance().getLogger(FileWriterNode.class);
public void writeFile(Map<String, String> inParams, SvcLogicContext ctx)
public void writeFile(Map<String, String> inParams, SvcLogicContext ctx)
- throws SvcLogicException {
+ throws SvcLogicException {
log.info("Received writeFile call with params : " + inParams);
String responsePrefix = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX);
try {
log.info("Received writeFile call with params : " + inParams);
String responsePrefix = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX);
try {
String fileName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME);
String fileContents = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA);
String fileName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME);
String fileContents = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA);
File file = new File(fileName);
File filePath = file.getParentFile();
FileUtils.forceMkdir(filePath);
FileUtils.writeStringToFile(file, fileContents,
File file = new File(fileName);
File filePath = file.getParentFile();
FileUtils.forceMkdir(filePath);
FileUtils.writeStringToFile(file, fileContents,
- ConfigGeneratorConstant.STRING_ENCODING);
-
+ ConfigGeneratorConstant.STRING_ENCODING);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
- ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
+ ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
} catch (Exception e) {
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
} catch (Exception e) {
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
- ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
+ ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE,
- e.getMessage());
- log.error("Failed in writeFile " + e.getMessage());
+ e.getMessage());
+ log.error("Failed in writeFile", e);
throw new SvcLogicException(e.getMessage());
}
}
throw new SvcLogicException(e.getMessage());
}
}
import org.powermock.reflect.Whitebox;
public class TestDataTool {
import org.powermock.reflect.Whitebox;
public class TestDataTool {
- LogParserTool lp = new LogParserTool();
+ private LogParserTool logParserTool = new LogParserTool();
@Test
public void testCheckData() throws IOException {
String data = IOUtils.toString(
@Test
public void testCheckData() throws IOException {
String data = IOUtils.toString(
- TestPatternNode.class.getClassLoader()
- .getResourceAsStream("convert/payload_cli_config.json"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ TestPatternNode.class.getClassLoader()
+ .getResourceAsStream("convert/payload_cli_config.json"),
+ ConfigGeneratorConstant.STRING_ENCODING);
CheckDataTool.checkData(data);
}
@Test
public void testIsJSON() throws IOException {
String data = IOUtils.toString(
CheckDataTool.checkData(data);
}
@Test
public void testIsJSON() throws IOException {
String data = IOUtils.toString(
- TestPatternNode.class.getClassLoader()
- .getResourceAsStream("convert/payload_cli_config.json"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ TestPatternNode.class.getClassLoader()
+ .getResourceAsStream("convert/payload_cli_config.json"),
+ ConfigGeneratorConstant.STRING_ENCODING);
CheckDataTool.isJSON(data);
}
@Test
public void testIsXML() throws IOException {
String data = IOUtils.toString(
CheckDataTool.isJSON(data);
}
@Test
public void testIsXML() throws IOException {
String data = IOUtils.toString(
- TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
+ ConfigGeneratorConstant.STRING_ENCODING);
CheckDataTool.isXML(data);
}
CheckDataTool.isXML(data);
}
EscapeUtils.escapeString(null);
}
EscapeUtils.escapeString(null);
}
- // @Test(expected = Exception.class)
+ @Test(expected = Exception.class)
public void testgetData() throws Exception {
public void testgetData() throws Exception {
- ArrayList argList = null;
+ List<String> argList = null;
String schema = "sdnctl";
String tableName = "dual";
String getselectData = "123";
String schema = "sdnctl";
String tableName = "dual";
String getselectData = "123";
DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
}
DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
}
- // @Test(expected = Exception.class)
+ @Test(expected = Exception.class)
public void testupdateDB() throws Exception {
public void testupdateDB() throws Exception {
- String setCluase = null;
- String schema = "sdnctl";
+ String setClause = null;
String tableName = "dual";
String tableName = "dual";
- ArrayList inputArgs = null;
+ List<String> inputArgs = null;
String whereClause = "123='123'";
String whereClause = "123='123'";
- DbServiceUtil.updateDB(tableName, inputArgs, schema, whereClause, setCluase);
+ DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
}
// @Test(expected = Exception.class)
}
// @Test(expected = Exception.class)
@Test
public void testJSONTool() throws Exception {
String data = IOUtils.toString(
@Test
public void testJSONTool() throws Exception {
String data = IOUtils.toString(
- TestPatternNode.class.getClassLoader()
- .getResourceAsStream("convert/payload_cli_config.json"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ TestPatternNode.class.getClassLoader()
+ .getResourceAsStream("convert/payload_cli_config.json"),
+ ConfigGeneratorConstant.STRING_ENCODING);
JSONTool.convertToProperties(data);
List<String> blockKeys = new ArrayList<String>();
blockKeys.add("vnf-type");
JSONTool.convertToProperties(data);
List<String> blockKeys = new ArrayList<String>();
blockKeys.add("vnf-type");
@Test
public void testLogParserTool() throws Exception {
String data = IOUtils.toString(
@Test
public void testLogParserTool() throws Exception {
String data = IOUtils.toString(
- TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
- ConfigGeneratorConstant.STRING_ENCODING);
+ TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
+ ConfigGeneratorConstant.STRING_ENCODING);
LogParserTool lpt = new LogParserTool();
lpt.parseErrorLog(data);
}
LogParserTool lpt = new LogParserTool();
lpt.parseErrorLog(data);
}
@Test
public void testcheckDateTime() throws Exception {
String line = "2017-08-20T17:40:23.100361+00:00";
@Test
public void testcheckDateTime() throws Exception {
String line = "2017-08-20T17:40:23.100361+00:00";
- Whitebox.invokeMethod(lp, "checkDateTime", line);
+ Whitebox.invokeMethod(logParserTool, "checkDateTime", line);