Strabon

changeset 477:39688ed7f6d5

made DescribeOp require the format and changed Strabon.describe to require the output stream to write the result of the query
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Jul 20 14:19:39 2012 +0300 (2012-07-20)
parents b817cc860552
children 27a92cb6315c
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Fri Jul 20 01:39:46 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Fri Jul 20 14:19:39 2012 +0300
     1.3 @@ -1,23 +1,14 @@
     1.4  package eu.earthobservatory.org.StrabonEndpoint;
     1.5  
     1.6 -import java.io.BufferedWriter;
     1.7 -import java.io.File;
     1.8 -import java.io.FileOutputStream;
     1.9 -import java.io.FileWriter;
    1.10  import java.io.IOException;
    1.11  import java.io.PrintWriter;
    1.12  import java.io.UnsupportedEncodingException;
    1.13 -import java.math.BigInteger;
    1.14  import java.net.URLDecoder;
    1.15  import java.net.URLEncoder;
    1.16 -import java.security.SecureRandom;
    1.17 -import java.util.Date;
    1.18  import java.util.HashMap;
    1.19  import java.util.Iterator;
    1.20  import java.util.List;
    1.21  import java.util.Map;
    1.22 -import java.util.zip.ZipEntry;
    1.23 -import java.util.zip.ZipOutputStream;
    1.24  
    1.25  import javax.servlet.ServletConfig;
    1.26  import javax.servlet.ServletContext;
    1.27 @@ -26,26 +17,18 @@
    1.28  import javax.servlet.http.HttpServletRequest;
    1.29  import javax.servlet.http.HttpServletResponse;
    1.30  
    1.31 -import org.apache.commons.io.FileUtils;
    1.32 -import org.openrdf.query.MalformedQueryException;
    1.33 -import org.openrdf.query.QueryEvaluationException;
    1.34 -import org.openrdf.query.TupleQueryResultHandlerException;
    1.35 -import org.openrdf.repository.RepositoryException;
    1.36  import org.slf4j.Logger;
    1.37  import org.slf4j.LoggerFactory;
    1.38  import org.springframework.web.context.WebApplicationContext;
    1.39  import org.springframework.web.context.support.WebApplicationContextUtils;
    1.40  
    1.41  import eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.Entry;
    1.42 -import eu.earthobservatory.org.StrabonEndpoint.ResponseMessages;
    1.43 -import eu.earthobservatory.runtime.generaldb.Strabon;
    1.44 -
    1.45  
    1.46  public class DescribeBean extends HttpServlet{
    1.47  
    1.48  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.DescribeBean.class);
    1.49  
    1.50 -        private static final long serialVersionUID = -7541662133934957148L;
    1.51 +    private static final long serialVersionUID = -7541662133934957148L;
    1.52  
    1.53  	/**
    1.54  	* @param args
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 20 01:39:46 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 20 14:19:39 2012 +0300
     2.3 @@ -222,9 +222,9 @@
     2.4  			throw new RepositoryException("Could not connect to Strabon.");
     2.5  		} 
     2.6  
     2.7 -		String answer = null;
     2.8 +		ByteArrayOutputStream answer = new ByteArrayOutputStream();
     2.9  		
    2.10 -		strabon.describe(queryString, strabon.getSailRepoConnection(),  answer);
    2.11 +		strabon.describe(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), answer);
    2.12  		
    2.13  		return answer.toString();
    2.14  	}
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 01:39:46 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 14:19:39 2012 +0300
     3.3 @@ -426,7 +426,7 @@
     3.4  		logger.info("[Strabon.storeString] Storing was successful.");
     3.5  	}
     3.6  
     3.7 -	public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException
     3.8 +	public void describe(String describeString, String format, SailRepositoryConnection con, OutputStream out) throws MalformedQueryException
     3.9  	{
    3.10  		GraphQuery  graphQuery = null;
    3.11  
    3.12 @@ -437,30 +437,16 @@
    3.13  			logger.error("[Strabon.describe]", e);
    3.14  		}
    3.15  
    3.16 -		logger.info("[Strabon.describe] Executing describe query:" + describeString);
    3.17 +		logger.info("[Strabon.describe] Executing DESCRIBE query:" + describeString);
    3.18  
    3.19  		try {
    3.20 -			OutputStream out = new FileOutputStream(outFile);
    3.21  			RDFHandler rdfHandler = new NTriplesWriter(out);
    3.22  			graphQuery.evaluate(rdfHandler);
    3.23 -			out.close();
    3.24  
    3.25 -		} catch (FileNotFoundException e) {
    3.26 -			logger.error("[Strabon.describe]", e);
    3.27 -		} catch (QueryEvaluationException e) {
    3.28 -			logger.error("[Strabon.describe]", e);
    3.29 -		} catch (RDFHandlerException e) {
    3.30 -			logger.error("[Strabon.describe]", e);
    3.31 -		} catch (IOException e) {
    3.32 +		} catch (Exception e) {
    3.33  			logger.error("[Strabon.describe]", e);
    3.34  		}
    3.35  
    3.36 -		logger.info("[Strabon.describe] Output: {}", outFile);
    3.37 -	}
    3.38 -	
    3.39 -	private static void writeString(OutputStream out, String str) throws IOException {
    3.40 -		if (str != null && str.length() > 0) {
    3.41 -			out.write(str.getBytes(Charset.defaultCharset()));
    3.42 -		}
    3.43 +		logger.info("[Strabon.describe] DESCRIBE query executed successfully.");
    3.44  	}
    3.45  }
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java	Fri Jul 20 01:39:46 2012 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/DescribeOp.java	Fri Jul 20 14:19:39 2012 +0300
     4.3 @@ -15,14 +15,14 @@
     4.4  	public static void main(String[] args) {
     4.5  
     4.6  		if (args.length < 7) {
     4.7 -			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <OUTPUT>");
     4.8 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <FORMAT>");
     4.9  			System.err.println("       where <HOST>       is the postgis database host to connect to");
    4.10  			System.err.println("             <PORT>       is the port to connect to on the database host");		
    4.11  			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    4.12  			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    4.13  			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    4.14  			System.err.println("             <QUERY>      is the stSPARQL query to evaluate.");
    4.15 -			System.err.println("             <OUTPUT>      is the stSPARQL query to evaluate.");
    4.16 +			System.err.println("             <FORMAT>     is the RDF format of the output.");
    4.17  			System.exit(0);
    4.18  		}
    4.19  
    4.20 @@ -32,12 +32,12 @@
    4.21  		String user = args[3];
    4.22  		String passwd = args[4];		
    4.23  		String queryString = args[5];
    4.24 -		String outFile = args[6];
    4.25 +		String format = args[6];
    4.26  
    4.27  		Strabon strabon = null;
    4.28  		try { 
    4.29  			strabon = new Strabon(db, user, passwd, port, host, true);
    4.30 -			strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    4.31 +			strabon.describe(queryString, format, strabon.getSailRepoConnection(), System.out);
    4.32  			
    4.33  		} catch (Exception e) {
    4.34  			logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e);
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Fri Jul 20 01:39:46 2012 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Fri Jul 20 14:19:39 2012 +0300
     5.3 @@ -15,14 +15,14 @@
     5.4  	public static void main(String[] args) {
     5.5  
     5.6  		if (args.length < 7) {
     5.7 -			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <OUTPUT>");
     5.8 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <FORMAT>");
     5.9  			System.err.println("       where <HOST>       is the postgis database host to connect to");
    5.10  			System.err.println("             <PORT>       is the port to connect to on the database host");		
    5.11  			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    5.12  			System.err.println("             <USERNAME>   is the username to use when connecting to the database ");
    5.13  			System.err.println("             <PASSWORD>   is the password to use when connecting to the database");
    5.14  			System.err.println("             <QUERY>      is the stSPARQL query to evaluate.");
    5.15 -			System.err.println("             <OUTPUT>     is the output file.");
    5.16 +			System.err.println("             <FORMAT>     is the RDF format of the output.");
    5.17  			System.exit(0);
    5.18  		}
    5.19  
    5.20 @@ -32,12 +32,12 @@
    5.21  		String user = args[3];
    5.22  		String passwd = args[4];		
    5.23  		String queryString = args[5];
    5.24 -		String outFile = args[6];
    5.25 +		String format = args[6];
    5.26  		
    5.27  		Strabon strabon = null;
    5.28  		try {
    5.29  			strabon = new Strabon(db, user, passwd, port, host, true);
    5.30 -			strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
    5.31 +			strabon.describe(queryString, format, strabon.getSailRepoConnection(), System.out);
    5.32  			
    5.33  		} catch (Exception e) {
    5.34  			logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e);