1 |
3551
|
leinfelder
|
<%@page
|
2 |
|
|
import="java.sql.ResultSet"%><%@page
|
3 |
4039
|
leinfelder
|
import="edu.ucsb.nceas.first.metacat.client.AssessmentQuery"%><%@page
|
4 |
|
|
import="edu.ucsb.nceas.utilities.OrderedMap"%><%@page
|
5 |
3551
|
leinfelder
|
import="au.com.bytecode.opencsv.CSVWriter"%><%@page
|
6 |
|
|
import="java.util.*"%><%@page
|
7 |
|
|
import="java.io.*"%><%
|
8 |
3542
|
leinfelder
|
|
9 |
|
|
String[] docids = request.getParameterValues("docids");
|
10 |
3669
|
leinfelder
|
String questionId = request.getParameter("questionId");
|
11 |
3551
|
leinfelder
|
String qformat = request.getParameter("qformat");
|
12 |
3542
|
leinfelder
|
|
13 |
|
|
if (docids != null && docids.length > 0) {
|
14 |
|
|
|
15 |
|
|
List assessmentDocIds = Arrays.asList(docids);
|
16 |
|
|
|
17 |
4039
|
leinfelder
|
//the "columns" to extract from the metadata document (will be param soon)
|
18 |
|
|
Map attributeMap = new OrderedMap();
|
19 |
|
|
attributeMap.put("id", "//@packageId");
|
20 |
|
|
attributeMap.put("title", "//assessment/@title");
|
21 |
|
|
attributeMap.put("duration", "//assessment/duration");
|
22 |
|
|
attributeMap.put("badColumn", "//does/not/exist");
|
23 |
|
|
attributeMap.put("item", "//assessmentItems/assessmentItem/assessmentItemId");
|
24 |
|
|
|
25 |
3542
|
leinfelder
|
//make a title
|
26 |
|
|
String tableTitle = "Showing data for ";
|
27 |
3551
|
leinfelder
|
String fileName = "results-";
|
28 |
3542
|
leinfelder
|
for (int i=0; i<docids.length; i++) {
|
29 |
|
|
tableTitle += docids[i];
|
30 |
|
|
tableTitle +=", ";
|
31 |
3551
|
leinfelder
|
|
32 |
|
|
fileName += docids[i];
|
33 |
3542
|
leinfelder
|
}
|
34 |
|
|
tableTitle = tableTitle.substring(0, tableTitle.length()-2);
|
35 |
3551
|
leinfelder
|
fileName += ".csv";
|
36 |
3542
|
leinfelder
|
|
37 |
|
|
//AssessmentQuery.testEcogrid("edml.4.5");
|
38 |
4034
|
leinfelder
|
ResultSet rs = null;
|
39 |
|
|
if (questionId != null) {
|
40 |
|
|
rs = AssessmentQuery.selectResponseData(assessmentDocIds, questionId, "=", new Integer(1));
|
41 |
|
|
}
|
42 |
|
|
else {
|
43 |
4039
|
leinfelder
|
rs = AssessmentQuery.selectMergedResponseData(assessmentDocIds, attributeMap);
|
44 |
4034
|
leinfelder
|
}
|
45 |
3551
|
leinfelder
|
|
46 |
3563
|
leinfelder
|
if (rs == null) {
|
47 |
|
|
return;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
3551
|
leinfelder
|
//get the results as csv file
|
51 |
|
|
if (qformat != null && qformat.equalsIgnoreCase("csv")) {
|
52 |
|
|
response.setContentType("text/csv");
|
53 |
|
|
//response.setContentType("application/csv");
|
54 |
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
55 |
|
|
|
56 |
|
|
Writer writer = new OutputStreamWriter(response.getOutputStream());
|
57 |
|
|
CSVWriter csv = new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
|
58 |
|
|
csv.writeAll(rs, true);
|
59 |
3669
|
leinfelder
|
csv.flush();
|
60 |
3551
|
leinfelder
|
|
61 |
|
|
response.flushBuffer();
|
62 |
|
|
|
63 |
|
|
rs.close();
|
64 |
|
|
return;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
3542
|
leinfelder
|
int numColumns = rs.getMetaData().getColumnCount();
|
68 |
|
|
%>
|
69 |
|
|
|
70 |
|
|
<!-- <h3><%=tableTitle %></h3> -->
|
71 |
|
|
|
72 |
|
|
<table>
|
73 |
|
|
<!--
|
74 |
|
|
<tr>
|
75 |
|
|
<th colspan="<%=numColumns %>"><%=tableTitle %></th>
|
76 |
|
|
</tr>
|
77 |
|
|
-->
|
78 |
|
|
<tr>
|
79 |
|
|
<% for (int i=1; i<=numColumns; i++) { %>
|
80 |
|
|
<th><%=rs.getMetaData().getColumnName(i) %></th>
|
81 |
|
|
<% } %>
|
82 |
|
|
</tr>
|
83 |
|
|
<%
|
84 |
|
|
while (rs.next()) {
|
85 |
|
|
//System.out.println("rs:" + rs.getInt(1));
|
86 |
|
|
%>
|
87 |
|
|
<tr>
|
88 |
|
|
<% for (int i=1; i<=numColumns; i++) { %>
|
89 |
3563
|
leinfelder
|
<td><%=rs.getString(i) %></td>
|
90 |
3542
|
leinfelder
|
<% } %>
|
91 |
|
|
</tr>
|
92 |
|
|
<%
|
93 |
|
|
}
|
94 |
|
|
%>
|
95 |
|
|
</table>
|
96 |
3551
|
leinfelder
|
<%
|
97 |
|
|
//clean up
|
98 |
|
|
if (rs != null) {
|
99 |
|
|
rs.close();
|
100 |
|
|
}
|
101 |
|
|
}//end if docids
|
102 |
|
|
else {
|
103 |
|
|
%>
|
104 |
|
|
No items selected
|
105 |
|
|
<%}%>
|