Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
adapt
ace
Commits
cb309ccf
Commit
cb309ccf
authored
Mar 30, 2017
by
Michael Ritter
Browse files
Differentiate on GET/POST methods for the stats servlet
parent
34f9c264
Changes
1
Hide whitespace changes
Inline
Side-by-side
ace-am/src/main/java/edu/umiacs/ace/stats/StatisticsServlet.java
View file @
cb309ccf
package
edu.umiacs.ace.stats
;
package
edu.umiacs.ace.stats
;
import
edu.umiacs.ace.util.EntityManagerServlet
;
import
edu.umiacs.ace.util.EntityManagerServlet
;
import
org.apache.log4j.Logger
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManager
;
import
javax.servlet.RequestDispatcher
;
import
javax.servlet.RequestDispatcher
;
...
@@ -17,22 +18,42 @@ import java.util.List;
...
@@ -17,22 +18,42 @@ import java.util.List;
* Created by shake on 8/30/16.
* Created by shake on 8/30/16.
*/
*/
public
class
StatisticsServlet
extends
EntityManagerServlet
{
public
class
StatisticsServlet
extends
EntityManagerServlet
{
private
static
final
Object
[]
HEADER
=
{
"date"
,
"collection"
,
"group"
,
"total_count"
,
"size"
}
;
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
StatisticsServlet
.
class
)
;
// General infos
private
static
final
String
GET
=
"GET"
;
private
static
final
String
SERVLET
=
"statistics.jsp"
;
// Query params
private
static
final
String
AFTER
=
"after"
;
private
static
final
String
AFTER
=
"after"
;
private
static
final
String
BEFORE
=
"before"
;
private
static
final
String
BEFORE
=
"before"
;
private
static
final
String
GROUP
=
"group"
;
private
static
final
String
GROUP
=
"group"
;
private
static
final
String
COLLECTION
=
"collection"
;
private
static
final
String
COLLECTION
=
"collection"
;
private
static
final
String
CSV
=
"csv"
;
private
static
final
String
CSV
=
"csv"
;
@Override
@Override
protected
void
processRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
,
EntityManager
em
)
throws
ServletException
,
IOException
{
protected
void
processRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
,
EntityManager
em
)
throws
ServletException
,
IOException
{
// Differentiate on the request method
// GET - no query, just forward
// POST - query/csv handling
if
(
GET
.
equals
(
request
.
getMethod
()))
{
processGet
(
request
,
response
);
}
else
{
processPost
(
request
,
response
,
em
);
}
}
private
void
processGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
RequestDispatcher
dispatcher
=
request
.
getRequestDispatcher
(
SERVLET
);
dispatcher
.
forward
(
request
,
response
);
}
private
void
processPost
(
HttpServletRequest
request
,
HttpServletResponse
response
,
EntityManager
em
)
throws
ServletException
,
IOException
{
String
csv
=
getParameter
(
request
,
CSV
,
null
);
String
group
=
getParameter
(
request
,
GROUP
,
null
);
String
after
=
getParameter
(
request
,
AFTER
,
null
);
String
after
=
getParameter
(
request
,
AFTER
,
null
);
String
before
=
getParameter
(
request
,
BEFORE
,
null
);
String
before
=
getParameter
(
request
,
BEFORE
,
null
);
String
group
=
getParameter
(
request
,
GROUP
,
null
);
String
collection
=
getParameter
(
request
,
COLLECTION
,
null
);
String
collection
=
getParameter
(
request
,
COLLECTION
,
null
);
String
csv
=
getParameter
(
request
,
CSV
,
null
);
SummaryQuery
q
=
new
SummaryQuery
(
group
,
after
,
before
,
collection
);
SummaryQuery
q
=
new
SummaryQuery
(
group
,
after
,
before
,
collection
);
...
@@ -42,7 +63,7 @@ public class StatisticsServlet extends EntityManagerServlet {
...
@@ -42,7 +63,7 @@ public class StatisticsServlet extends EntityManagerServlet {
List
<
IngestSummary
>
summary
=
q
.
getSummary
();
List
<
IngestSummary
>
summary
=
q
.
getSummary
();
request
.
setAttribute
(
"summary"
,
summary
);
request
.
setAttribute
(
"summary"
,
summary
);
RequestDispatcher
dispatcher
=
request
.
getRequestDispatcher
(
"statistics.jsp"
);
RequestDispatcher
dispatcher
=
request
.
getRequestDispatcher
(
SERVLET
);
dispatcher
.
forward
(
request
,
response
);
dispatcher
.
forward
(
request
,
response
);
}
else
{
}
else
{
try
{
try
{
...
@@ -51,8 +72,9 @@ public class StatisticsServlet extends EntityManagerServlet {
...
@@ -51,8 +72,9 @@ public class StatisticsServlet extends EntityManagerServlet {
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=ingest-summary.csv"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=ingest-summary.csv"
);
q
.
writeToCsv
(
response
.
getOutputStream
());
q
.
writeToCsv
(
response
.
getOutputStream
());
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
(
);
LOG
.
error
(
"Error with statistics query"
,
e
);
}
}
}
}
}
}
}
}
Michael Ritter
@shake
mentioned in issue
#36 (closed)
·
Mar 30, 2017
mentioned in issue
#36 (closed)
mentioned in issue #36
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment