summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-09-07 01:14:57 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-07 01:14:57 +0000
commit26311ae5220efa4460c03284d0a47b2def420ecb (patch)
tree8c033fcf195944f23451b827ae02cfe2584bac16 /datarouter-prov/src/main/java
parent5cbbe749bfb23c1ab24aec01fdd3f3f4b2e36ce9 (diff)
parent1d9710279b4d9bffacc0f8e360922119bb12e347 (diff)
Merge "unit test for StastisticsServlet with db"
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();
+ }
}
+}