Revision 4855
Added by ben leinfelder almost 16 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
47 | 47 |
import java.util.HashMap; |
48 | 48 |
import java.util.Hashtable; |
49 | 49 |
import java.util.Iterator; |
50 |
import java.util.List; |
|
50 | 51 |
import java.util.Map; |
51 | 52 |
import java.util.Timer; |
52 | 53 |
import java.util.Vector; |
... | ... | |
64 | 65 |
|
65 | 66 |
import org.apache.log4j.Logger; |
66 | 67 |
import org.apache.log4j.PropertyConfigurator; |
68 |
import org.ecoinformatics.datamanager.transpose.DataTranspose; |
|
67 | 69 |
import org.ecoinformatics.eml.EMLParser; |
68 | 70 |
|
69 | 71 |
import au.com.bytecode.opencsv.CSVWriter; |
... | ... | |
922 | 924 |
} |
923 | 925 |
String fileName = "query-results." + qformat; |
924 | 926 |
|
927 |
boolean transpose = false; |
|
928 |
temp = params.get("transpose"); |
|
929 |
if (temp != null && temp.length > 0) { |
|
930 |
transpose = Boolean.parseBoolean(temp[0]); |
|
931 |
} |
|
932 |
int observation = 0; |
|
933 |
temp = params.get("observation"); |
|
934 |
if (temp != null && temp.length > 0) { |
|
935 |
observation = Integer.parseInt(temp[0]); |
|
936 |
} |
|
937 |
int pivot = 0; |
|
938 |
temp = params.get("pivot"); |
|
939 |
if (temp != null && temp.length > 0) { |
|
940 |
pivot = Integer.parseInt(temp[0]); |
|
941 |
} |
|
942 |
|
|
925 | 943 |
//get the results as csv file |
926 | 944 |
if (qformat != null && qformat.equalsIgnoreCase("csv")) { |
927 | 945 |
response.setContentType("text/csv"); |
... | ... | |
931 | 949 |
Writer writer = new OutputStreamWriter(response.getOutputStream()); |
932 | 950 |
CSVWriter csv = new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER); |
933 | 951 |
try { |
934 |
csv.writeAll(rs, true); |
|
952 |
if (transpose) { |
|
953 |
List transposedTable = DataTranspose.transpose(rs, observation, pivot); |
|
954 |
csv.writeAll(transposedTable); |
|
955 |
} else { |
|
956 |
csv.writeAll(rs, true); |
|
957 |
} |
|
935 | 958 |
|
936 | 959 |
csv.flush(); |
937 | 960 |
response.flushBuffer(); |
Also available in: Unified diff
new datamanager feature!
Pivot a result set (rows to columns).
Handles simplest case:
-single id column (observation)
-single pivot column (pivot)