From: <ba...@us...> - 2010-05-30 22:40:02
|
Revision: 3345 http://obo.svn.sourceforge.net/obo/?rev=3345&view=rev Author: balhoff Date: 2010-05-30 22:39:55 +0000 (Sun, 30 May 2010) Log Message: ----------- Added streaming representations for large datasets, continued autocomplete work, added some docs. Modified Paths: -------------- OBD-WS/trunk/src/org/phenoscape/obd/model/AutocompleteResult.java OBD-WS/trunk/src/org/phenoscape/ws/resource/AbstractPhenoscapeResource.java Added Paths: ----------- OBD-WS/trunk/src/org/phenoscape/ws/representation/ OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableJSONRepresentation.java OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableTextRepresentation.java Removed Paths: ------------- OBD-WS/trunk/src/org/phenoscape/ws/exceptions/PhenoscapeTreeAssemblyException.java Modified: OBD-WS/trunk/src/org/phenoscape/obd/model/AutocompleteResult.java =================================================================== --- OBD-WS/trunk/src/org/phenoscape/obd/model/AutocompleteResult.java 2010-05-27 22:04:35 UTC (rev 3344) +++ OBD-WS/trunk/src/org/phenoscape/obd/model/AutocompleteResult.java 2010-05-30 22:39:55 UTC (rev 3345) @@ -1,34 +1,51 @@ package org.phenoscape.obd.model; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; public class AutocompleteResult { private final List<SearchHit> hits = new ArrayList<SearchHit>(); - private final String searchText; + private String searchText; + private int resultLimit; + private int completeResultCount; - public AutocompleteResult(String searchText) { - this.searchText = searchText; + public void addSearchHit(SearchHit hit) { + this.hits.add(hit); } + public void addAllSearchHits(Collection<SearchHit> hits) { + this.hits.addAll(hits); + } + public List<SearchHit> getResults() { return Collections.unmodifiableList(hits); } - + public int getResultLimit() { - //TODO - return 0; + return this.resultLimit; } + public void setResultLimit(int limit) { + this.resultLimit = limit; + } + public int getCompleteResultCount() { - //TODO - return 0; + return this.completeResultCount; } + public void setCompleteResultCount(int count) { + this.completeResultCount = count; + } + public String getSearchText() { return this.searchText; } + + public void setSearchText(String text) { + this.searchText = text; + } } Deleted: OBD-WS/trunk/src/org/phenoscape/ws/exceptions/PhenoscapeTreeAssemblyException.java =================================================================== --- OBD-WS/trunk/src/org/phenoscape/ws/exceptions/PhenoscapeTreeAssemblyException.java 2010-05-27 22:04:35 UTC (rev 3344) +++ OBD-WS/trunk/src/org/phenoscape/ws/exceptions/PhenoscapeTreeAssemblyException.java 2010-05-30 22:39:55 UTC (rev 3345) @@ -1,17 +0,0 @@ -package org.phenoscape.ws.exceptions; -/** - * An exception that is thrown when there is a problem - * in generatng the tree from the input taxon to - * phenotype assertions - * @author cartik - * - */ - -public class PhenoscapeTreeAssemblyException extends Exception{ - - private static final long serialVersionUID = 7649731646724043305L; - - public PhenoscapeTreeAssemblyException(String msg){ - super(msg); - } -} Added: OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableJSONRepresentation.java =================================================================== --- OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableJSONRepresentation.java (rev 0) +++ OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableJSONRepresentation.java 2010-05-30 22:39:55 UTC (rev 3345) @@ -0,0 +1,52 @@ +package org.phenoscape.ws.representation; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Iterator; + +import org.json.JSONObject; +import org.restlet.data.MediaType; + +public class StreamableJSONRepresentation extends StreamableTextRepresentation { + + private String key; + private JSONObject otherValues = new JSONObject(); + private static final String SEPARATOR = "," + System.getProperty("line.separator"); + + public StreamableJSONRepresentation(Iterator<? extends JSONObject> items) { + super(items, MediaType.APPLICATION_JSON); + } + + public StreamableJSONRepresentation(Iterator<? extends JSONObject> items, String key) { + super(items, MediaType.APPLICATION_JSON); + } + + public StreamableJSONRepresentation(Iterator<? extends JSONObject> items, String key, JSONObject otherValues) { + super(items, MediaType.APPLICATION_JSON); + } + + @Override + public void write(OutputStream stream) throws IOException { + final Writer writer = new BufferedWriter(new OutputStreamWriter(stream, this.getCharacterEncoding())); + if (this.key != null) { + final String json = this.otherValues.toString(); + final String openEndedJSON = json.substring(0, json.lastIndexOf("}")); + writer.append(openEndedJSON); + writer.append(JSONObject.quote(this.key)); + writer.append(":"); + } + writer.write("["); + super.write(stream); + writer.write("]"); + if (this.key != null) { writer.write("}"); } + } + + @Override + protected String getItemSeparator() { + return SEPARATOR; + } + +} Added: OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableTextRepresentation.java =================================================================== --- OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableTextRepresentation.java (rev 0) +++ OBD-WS/trunk/src/org/phenoscape/ws/representation/StreamableTextRepresentation.java 2010-05-30 22:39:55 UTC (rev 3345) @@ -0,0 +1,53 @@ +package org.phenoscape.ws.representation; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.nio.charset.Charset; +import java.util.Iterator; + +import org.restlet.data.MediaType; +import org.restlet.representation.OutputRepresentation; + +public class StreamableTextRepresentation extends OutputRepresentation { + + private final Iterator<? extends Object> items; + private String characterEncoding = "UTF-8"; + private static final String SEPARATOR = System.getProperty("line.separator"); + + public StreamableTextRepresentation(Iterator<? extends Object> items) { + this(items, MediaType.TEXT_PLAIN); + } + + public StreamableTextRepresentation(Iterator<? extends Object> items, MediaType mediaType) { + super(mediaType); + this.items = items; + } + + @Override + public void write(OutputStream stream) throws IOException { + final Writer writer = new BufferedWriter(new OutputStreamWriter(stream, Charset.forName("UTF-8"))); + while (this.items.hasNext()) { + writer.write(this.items.next().toString()); + if (this.items.hasNext()) { + writer.write(this.getItemSeparator()); + } + } + writer.close(); + } + + public String getCharacterEncoding() { + return this.characterEncoding; + } + + public void setCharacterEncoding(String encoding) { + this.characterEncoding = encoding; + } + + protected String getItemSeparator() { + return SEPARATOR; + } + +} Modified: OBD-WS/trunk/src/org/phenoscape/ws/resource/AbstractPhenoscapeResource.java =================================================================== --- OBD-WS/trunk/src/org/phenoscape/ws/resource/AbstractPhenoscapeResource.java 2010-05-27 22:04:35 UTC (rev 3344) +++ OBD-WS/trunk/src/org/phenoscape/ws/resource/AbstractPhenoscapeResource.java 2010-05-30 22:39:55 UTC (rev 3345) @@ -27,7 +27,7 @@ } /** - * Return first value of the given query parameter, decoded, or null if not present; + * Return first value of the given query parameter, decoded, or null if not present. */ protected String getFirstQueryValue(String parameter) { if (this.getQuery().getFirstValue(parameter) != null) { @@ -37,6 +37,9 @@ } } + /** + * Return first value of the given query parameter as a boolean, or the given default value if not present. + */ protected boolean getBooleanQueryValue(String parameter, boolean defaultValue) { if (this.getQuery().getFirstValue(parameter) != null) { final String queryValue = this.getFirstQueryValue(parameter); @@ -46,6 +49,9 @@ } } + /** + * Return first value of the given query parameter as an integer, or the given default value if not present. + */ protected int getIntegerQueryValue(String parameter, int defaultValue) { if (this.getQuery().getFirstValue(parameter) != null) { final String queryValue = this.getFirstQueryValue(parameter); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |