# HG changeset patch # User Babis Nikolaou # Date 1342783179 -10800 # Node ID 39688ed7f6d529b6e634f29aba18ba82e42ffc9d # Parent b817cc860552578b906dfc6b81c5da29598beeda made DescribeOp require the format and changed Strabon.describe to require the output stream to write the result of the query diff -r b817cc860552 -r 39688ed7f6d5 endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java Fri Jul 20 01:39:46 2012 +0300 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java Fri Jul 20 14:19:39 2012 +0300 @@ -1,23 +1,14 @@ package eu.earthobservatory.org.StrabonEndpoint; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; -import java.math.BigInteger; import java.net.URLDecoder; import java.net.URLEncoder; -import java.security.SecureRandom; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -26,26 +17,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.FileUtils; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.TupleQueryResultHandlerException; -import org.openrdf.repository.RepositoryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.Entry; -import eu.earthobservatory.org.StrabonEndpoint.ResponseMessages; -import eu.earthobservatory.runtime.generaldb.Strabon; - public class DescribeBean extends HttpServlet{ private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.DescribeBean.class); - private static final long serialVersionUID = -7541662133934957148L; + private static final long serialVersionUID = -7541662133934957148L; /** * @param args diff -r b817cc860552 -r 39688ed7f6d5 endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Fri Jul 20 01:39:46 2012 +0300 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Fri Jul 20 14:19:39 2012 +0300 @@ -222,9 +222,9 @@ throw new RepositoryException("Could not connect to Strabon."); } - String answer = null; + ByteArrayOutputStream answer = new ByteArrayOutputStream(); - strabon.describe(queryString, strabon.getSailRepoConnection(), answer); + strabon.describe(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), answer); return answer.toString(); } diff -r b817cc860552 -r 39688ed7f6d5 runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Fri Jul 20 01:39:46 2012 +0300 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Fri Jul 20 14:19:39 2012 +0300 @@ -426,7 +426,7 @@ logger.info("[Strabon.storeString] Storing was successful."); } - public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException + public void describe(String describeString, String format, SailRepositoryConnection con, OutputStream out) throws MalformedQueryException { GraphQuery graphQuery = null; @@ -437,30 +437,16 @@ logger.error("[Strabon.describe]", e); } - logger.info("[Strabon.describe] Executing describe query:" + describeString); + logger.info("[Strabon.describe] Executing DESCRIBE query:" + describeString); try { - OutputStream out = new FileOutputStream(outFile); RDFHandler rdfHandler = new NTriplesWriter(out); graphQuery.evaluate(rdfHandler); - out.close(); - } catch (FileNotFoundException e) { - logger.error("[Strabon.describe]", e); - } catch (QueryEvaluationException e) { - logger.error("[Strabon.describe]", e); - } catch (RDFHandlerException e) { - logger.error("[Strabon.describe]", e); - } catch (IOException e) { + } catch (Exception e) { logger.error("[Strabon.describe]", e); } - logger.info("[Strabon.describe] Output: {}", outFile); - } - - private static void writeString(OutputStream out, String str) throws IOException { - if (str != null && str.length() > 0) { - out.write(str.getBytes(Charset.defaultCharset())); - } + logger.info("[Strabon.describe] DESCRIBE query executed successfully."); } } diff -r b817cc860552 -r 39688ed7f6d5 runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java Fri Jul 20 01:39:46 2012 +0300 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java Fri Jul 20 14:19:39 2012 +0300 @@ -15,14 +15,14 @@ public static void main(String[] args) { if (args.length < 7) { - System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); + System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); System.err.println(" where is the postgis database host to connect to"); System.err.println(" is the port to connect to on the database host"); System.err.println(" is the spatially enabled postgis database that Strabon will use as a backend, "); System.err.println(" is the username to use when connecting to the database "); System.err.println(" is the password to use when connecting to the database"); System.err.println(" is the stSPARQL query to evaluate."); - System.err.println(" is the stSPARQL query to evaluate."); + System.err.println(" is the RDF format of the output."); System.exit(0); } @@ -32,12 +32,12 @@ String user = args[3]; String passwd = args[4]; String queryString = args[5]; - String outFile = args[6]; + String format = args[6]; Strabon strabon = null; try { strabon = new Strabon(db, user, passwd, port, host, true); - strabon.describe(queryString, strabon.getSailRepoConnection(), outFile); + strabon.describe(queryString, format, strabon.getSailRepoConnection(), System.out); } catch (Exception e) { logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e); diff -r b817cc860552 -r 39688ed7f6d5 runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java Fri Jul 20 01:39:46 2012 +0300 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java Fri Jul 20 14:19:39 2012 +0300 @@ -15,14 +15,14 @@ public static void main(String[] args) { if (args.length < 7) { - System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); + System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); System.err.println(" where is the postgis database host to connect to"); System.err.println(" is the port to connect to on the database host"); System.err.println(" is the spatially enabled postgis database that Strabon will use as a backend, "); System.err.println(" is the username to use when connecting to the database "); System.err.println(" is the password to use when connecting to the database"); System.err.println(" is the stSPARQL query to evaluate."); - System.err.println(" is the output file."); + System.err.println(" is the RDF format of the output."); System.exit(0); } @@ -32,12 +32,12 @@ String user = args[3]; String passwd = args[4]; String queryString = args[5]; - String outFile = args[6]; + String format = args[6]; Strabon strabon = null; try { strabon = new Strabon(db, user, passwd, port, host, true); - strabon.describe(queryString, strabon.getSailRepoConnection(), outFile); + strabon.describe(queryString, format, strabon.getSailRepoConnection(), System.out); } catch (Exception e) { logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e);