aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java
diff options
context:
space:
mode:
authorEmmett Cox <emmett.cox@ericsson.com>2018-09-06 13:58:27 +0100
committerEmmett Cox <emmett.cox@ericsson.com>2018-09-06 16:40:13 +0100
commit1d9710279b4d9bffacc0f8e360922119bb12e347 (patch)
tree1c72d75019a04ba9b7856bf8e088a63455b4db5d /datarouter-prov/src/main/java
parent079a007f29994785912ca891c58e09f755189e58 (diff)
unit test for StastisticsServlet with db
Change-Id: I32ed948f2485d13605d58fadef72903b05ca57f5 Signed-off-by: Emmett Cox <emmett.cox@ericsson.com> Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov/src/main/java')
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java79
1 files changed, 37 insertions, 42 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
index 33bf3a35..4917402c 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
@@ -180,39 +180,8 @@ public class StatisticsServlet extends BaseServlet {
outputType = req.getParameter("output_type");
}
- try {
-
- String filterQuery = this.queryGeneretor(map);
- eventlogger.debug("SQL Query for Statistics resultset. " + filterQuery);
-
- ResultSet rs = this.getRecordsForSQL(filterQuery);
+ this.getRecordsForSQL(map, outputType, out, resp);
- if (outputType.equals("csv")) {
- resp.setContentType("application/octet-stream");
- Date date = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");
- resp.setHeader("Content-Disposition",
- "attachment; filename=\"result:" + dateFormat.format(date) + ".csv\"");
- eventlogger.info("Generating CSV file from Statistics resultset");
-
- rsToCSV(rs, out);
- } else {
- eventlogger.info("Generating JSON for Statistics resultset");
- this.rsToJson(rs, out);
- }
- } catch (IOException e) {
- eventlogger.error("IOException - Generating JSON/CSV:" + e);
- e.printStackTrace();
- } catch (JSONException e) {
- eventlogger.error("JSONException - executing SQL query:" + e);
- e.printStackTrace();
- } catch (SQLException e) {
- eventlogger.error("SQLException - executing SQL query:" + e);
- e.printStackTrace();
- } catch (ParseException e) {
- eventlogger.error("ParseException - executing SQL query:" + e);
- e.printStackTrace();
- }
}
@@ -565,21 +534,47 @@ public class StatisticsServlet extends BaseServlet {
intlogger.info("Error parsing time=" + s);
return -1;
}
- private ResultSet getRecordsForSQL(String sql) {
- intlogger.debug(sql);
+
+ private void getRecordsForSQL(Map<String, String> map, String outputType, ServletOutputStream out, HttpServletResponse resp) {
+ try {
+
+ String filterQuery = this.queryGeneretor(map);
+ eventlogger.debug("SQL Query for Statistics resultset. " + filterQuery);
+ intlogger.debug(filterQuery);
long start = System.currentTimeMillis();
DB db = new DB();
ResultSet rs = null;
- try (
- Connection conn = db.getConnection()){
- try(PreparedStatement pst = conn.prepareStatement(sql)){
- rs = pst.executeQuery();
+ try (Connection conn = db.getConnection()) {
+ try (PreparedStatement pst = conn.prepareStatement(filterQuery)) {
+ rs = pst.executeQuery();
+ if (outputType.equals("csv")) {
+ resp.setContentType("application/octet-stream");
+ Date date = new Date();
+ SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");
+ resp.setHeader("Content-Disposition",
+ "attachment; filename=\"result:" + dateFormat.format(date) + ".csv\"");
+ eventlogger.info("Generating CSV file from Statistics resultset");
+
+ rsToCSV(rs, out);
+ } else {
+ eventlogger.info("Generating JSON for Statistics resultset");
+ this.rsToJson(rs, out);
}
+ }
} catch (SQLException e) {
- e.printStackTrace();
- }
- intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
- return rs;
+ e.printStackTrace();
}
+ intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
+ } catch (IOException e) {
+ eventlogger.error("IOException - Generating JSON/CSV:" + e);
+ e.printStackTrace();
+ } catch (JSONException e) {
+ eventlogger.error("JSONException - executing SQL query:" + e);
+ e.printStackTrace();
+ } catch (ParseException e) {
+ eventlogger.error("ParseException - executing SQL query:" + e);
+ e.printStackTrace();
+ }
}
+}