aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorActivator.java28
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorConstant.java3
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/convert/ConvertNode.java20
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/merge/MergeNode.java10
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/pattern/PatternNode.java10
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/reader/ReaderNode.java5
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java23
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java5
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java2
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java3
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java29
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java4
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java24
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java30
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/transform/XSLTTransformerNode.java24
-rw-r--r--appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java23
-rw-r--r--appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java44
17 files changed, 134 insertions, 153 deletions
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorActivator.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorActivator.java
index 957f324d3..1dfd4c1d3 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorActivator.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorActivator.java
@@ -39,8 +39,9 @@ import org.osgi.framework.ServiceRegistration;
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);
@@ -49,29 +50,29 @@ public class ConfigGeneratorActivator implements BundleActivator {
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));
- log.info("Registering service sccessful for " + convertNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + convertNode.getClass().getName());
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));
- log.info("Registering service sccessful for " + mergeNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + mergeNode.getClass().getName());
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));
- log.info("Registering service sccessful for " + patternNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + patternNode.getClass().getName());
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));
- log.info("Registering service sccessful for " + readerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + readerNode.getClass().getName());
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));
- log.info("Registering service sccessful for " + writerNode.getClass().getName());
+ log.info(STR_REGISTERING_SERVICE_SUCCESS + writerNode.getClass().getName());
}
@@ -79,9 +80,6 @@ public class ConfigGeneratorActivator implements BundleActivator {
public void stop(BundleContext arg0) throws Exception {
for (ServiceRegistration registration : registrations) {
registration.unregister();
- registration = null;
}
-
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorConstant.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorConstant.java
index bfeef35f4..9c003f59b 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorConstant.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/ConfigGeneratorConstant.java
@@ -26,7 +26,6 @@ package org.onap.sdnc.config.generator;
public class ConfigGeneratorConstant {
-
public static final String STRING_ENCODING = "utf-8";
public static final String Y = "Y";
public static final String N = "N";
@@ -52,7 +51,6 @@ public class ConfigGeneratorConstant {
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";
@@ -69,4 +67,5 @@ public class ConfigGeneratorConstant {
public static final String INPUT_PARAM_CONTEXT_KEY = "contextKey";
public static final String INPUT_PARAM_JSON_CONTENT = "jsonContent";
+ private ConfigGeneratorConstant(){}
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/convert/ConvertNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/convert/ConvertNode.java
index d3ea34f9a..1f1ecf6bb 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/convert/ConvertNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/convert/ConvertNode.java
@@ -121,14 +121,7 @@ public class ConvertNode implements SvcLogicJavaPlugin {
}
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)) {
@@ -142,6 +135,17 @@ public class ConvertNode implements SvcLogicJavaPlugin {
}
}
+ 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);
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/merge/MergeNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/merge/MergeNode.java
index 2c4c0614d..a9046e6bc 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/merge/MergeNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/merge/MergeNode.java
@@ -42,8 +42,9 @@ public class MergeNode implements SvcLogicJavaPlugin {
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 {
@@ -139,6 +140,7 @@ public class MergeNode implements SvcLogicJavaPlugin {
}
}
- 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 */
+ }
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/pattern/PatternNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/pattern/PatternNode.java
index 4d4ba6bd6..6a7c8bfbc 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/pattern/PatternNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/pattern/PatternNode.java
@@ -32,6 +32,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
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;
@@ -47,7 +48,7 @@ public class PatternNode implements SvcLogicJavaPlugin {
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);
@@ -60,7 +61,7 @@ public class PatternNode implements SvcLogicJavaPlugin {
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());
}
}
@@ -73,7 +74,7 @@ public class PatternNode implements SvcLogicJavaPlugin {
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,
@@ -85,9 +86,8 @@ public class PatternNode implements SvcLogicJavaPlugin {
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());
}
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/reader/ReaderNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/reader/ReaderNode.java
index c657ee531..6f729f4f0 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/reader/ReaderNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/reader/ReaderNode.java
@@ -40,7 +40,6 @@ public class ReaderNode implements SvcLogicJavaPlugin {
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);
@@ -61,10 +60,8 @@ public class ReaderNode implements SvcLogicJavaPlugin {
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());
}
}
-
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java
index 4488e0be8..3895aa47f 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java
@@ -24,6 +24,8 @@
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;
@@ -31,11 +33,15 @@ import org.codehaus.jettison.json.JSONArray;
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 {
+ 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) {
@@ -54,33 +60,26 @@ public class CheckDataTool {
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) {
+ logger.error(STR_INPUT_DATA + data + "\n is not json array", ex1);
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();
- Document doc = dBuilder.parse(new InputSource(new StringReader(data)));
+ dBuilder.parse(new InputSource(new StringReader(data)));
return true;
} catch (Exception ex) {
+ logger.error(STR_INPUT_DATA + data + "\n is not xml document", ex);
return false;
}
-
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java
index 00fda9fb7..7193dc91e 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java
@@ -26,11 +26,10 @@ package org.onap.sdnc.config.generator.tool;
public class Constants {
- 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 APPC_CONFIG_DIR = "/opt/onap/appc/data/properties";
+ private Constants() {}
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java
index 7a44b8b47..b0d96583b 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java
@@ -29,8 +29,8 @@ import com.fasterxml.jackson.databind.node.TextNode;
public class CustomJsonNodeFactory extends JsonNodeFactory {
+ @Override
public TextNode textNode(String text) {
return new CustomTextNode(text);
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java
index 2cfc643aa..101ad2a5c 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java
@@ -44,9 +44,6 @@ public class CustomTextNode extends TextNode {
}
protected static void appendQuoted(StringBuilder sb, String content) {
- // sb.append('"');
CharTypes.appendQuoted(sb, content);
- // sb.append('"');
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java
index c98429c02..a37b258f5 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java
@@ -24,10 +24,12 @@
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.util.List;
import java.util.Properties;
import javax.sql.rowset.CachedRowSet;
import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
@@ -38,41 +40,36 @@ public class DbServiceUtil {
private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
- private static Properties props;
+ private static Properties properties;
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 =
- "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;
- CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema);
- return data;
+ return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
}
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();
- props.load(propURL.openStream());
+ properties.load(propURL.openStream());
// this is an expected difference in CCSDK
- jdbcDataSource = new DBResourceManager(props);
+ jdbcDataSource = new DBResourceManager(properties);
return jdbcDataSource;
-
}
-
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
index 177716187..8d3493fe4 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java
@@ -28,9 +28,7 @@ import org.apache.commons.lang3.StringUtils;
public class EscapeUtils {
- public EscapeUtils() {
- // TODO Auto-generated constructor stub
- }
+ private EscapeUtils() {}
public static String escapeSql(String str) {
if (str == null) {
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java
index ebd58b01c..a9a7ecaf1 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java
@@ -37,14 +37,14 @@ public class LogParserTool {
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 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");
@@ -52,9 +52,9 @@ public class LogParserTool {
getNearestDates();
} catch (Exception e) {
- e.printStackTrace();
+ 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) {
@@ -68,7 +68,7 @@ public class LogParserTool {
}
}
- 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")
@@ -87,16 +87,14 @@ public class LogParserTool {
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) {
- e.printStackTrace();
+ log.error("Failed to parse date", e);
return NO_DATE;
}
}
-
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java
index 1126c2adb..e31cc5e93 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java
@@ -26,14 +26,13 @@ package org.onap.sdnc.config.generator.tool;
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 java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
@@ -44,9 +43,10 @@ import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
-
public class MergeTool {
+ private MergeTool() {}
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeTool.class);
public static String mergeMap2TemplateData(String template, Map<String, String> dataMap) {
@@ -64,19 +64,16 @@ public class MergeTool {
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();
}
-
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();
@@ -99,17 +96,20 @@ public class MergeTool {
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)) {
// Perform Prettying
-
}
}
return mergedData;
+ }
+ 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);
+ }
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/transform/XSLTTransformerNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/transform/XSLTTransformerNode.java
index 5ce7a69b0..300e30428 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/transform/XSLTTransformerNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/transform/XSLTTransformerNode.java
@@ -32,7 +32,6 @@ import java.io.StringWriter;
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;
@@ -43,7 +42,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
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 {
@@ -68,12 +67,12 @@ public class XSLTTransformerNode implements SvcLogicJavaPlugin {
}
}
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)) {
- throw new Exception("In-param requestData value is missing");
+ throw new ParameterMissingException("In-param requestData value is missing");
}
String transformedData = transform(requestData, templateData);
@@ -83,24 +82,25 @@ public class XSLTTransformerNode implements SvcLogicJavaPlugin {
ctx.setAttribute(responsePrefix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS,
ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
} catch (Exception e) {
- e.printStackTrace();
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());
}
}
- public String transform(String requestData, String templateData)
- throws TransformerConfigurationException, TransformerException {
+ private String transform(String requestData, String templateData) throws TransformerException {
StringWriter xmlResultResource = new StringWriter();
- Transformer xmlTransformer = TransformerFactory.newInstance()
+
+ Transformer xmlTransformer = TransformerFactory
+ .newInstance()
.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();
}
-
}
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java
index f7900b70a..a9047da5e 100644
--- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java
+++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/writer/FileWriterNode.java
@@ -24,6 +24,8 @@
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;
@@ -32,17 +34,13 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
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 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 {
@@ -50,27 +48,22 @@ public class FileWriterNode implements SvcLogicJavaPlugin {
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,
- ConfigGeneratorConstant.STRING_ENCODING);
-
+ ConfigGeneratorConstant.STRING_ENCODING);
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,
- ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
+ ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE);
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());
}
}
-
-
-
}
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
index 2a416f7b2..3eed17848 100644
--- a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
+++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestDataTool.java
@@ -37,32 +37,33 @@ import org.onap.sdnc.config.generator.pattern.TestPatternNode;
import org.powermock.reflect.Whitebox;
public class TestDataTool {
+
@Mock
- LogParserTool lp = new LogParserTool();
+ private LogParserTool logParserTool = new LogParserTool();
@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(
- 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(
- 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);
}
@@ -93,9 +94,9 @@ public class TestDataTool {
EscapeUtils.escapeString(null);
}
- // @Test(expected = Exception.class)
+ @Test(expected = Exception.class)
public void testgetData() throws Exception {
- ArrayList argList = null;
+ List<String> argList = null;
String schema = "sdnctl";
String tableName = "dual";
String getselectData = "123";
@@ -103,14 +104,13 @@ public class TestDataTool {
DbServiceUtil.getData(tableName, argList, schema, getselectData, getDataClasue);
}
- // @Test(expected = Exception.class)
+ @Test(expected = Exception.class)
public void testupdateDB() throws Exception {
- String setCluase = null;
- String schema = "sdnctl";
+ String setClause = null;
String tableName = "dual";
- ArrayList inputArgs = null;
+ List<String> inputArgs = null;
String whereClause = "123='123'";
- DbServiceUtil.updateDB(tableName, inputArgs, schema, whereClause, setCluase);
+ DbServiceUtil.updateDB(tableName, inputArgs, whereClause, setClause);
}
// @Test(expected = Exception.class)
@@ -121,9 +121,9 @@ public class TestDataTool {
@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");
@@ -134,8 +134,8 @@ public class TestDataTool {
@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);
}
@@ -150,6 +150,6 @@ public class TestDataTool {
@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);
}
}