Strabon

changeset 1192:756d8f688fff

some more changes, charts not supported yet
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Mon Jul 08 16:44:18 2013 +0300 (2013-07-08)
parents c99b065768d9
children 363ef97fb003
files endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java
line diff
     1.1 --- a/endpoint/WebContent/query.jsp	Fri Jul 05 17:39:45 2013 +0300
     1.2 +++ b/endpoint/WebContent/query.jsp	Mon Jul 08 16:44:18 2013 +0300
     1.3 @@ -5,6 +5,7 @@
     1.4  <%@page import="eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper"%>
     1.5  <%@page import="eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapperConfiguration"%>
     1.6  <%@page import="java.util.List"%>
     1.7 +<%@page import="java.util.ArrayList"%>
     1.8  <%@page import="java.util.Iterator"%>
     1.9  <%@page import="org.openrdf.query.TupleQueryResult"%>
    1.10  <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/>
    1.11 @@ -67,6 +68,9 @@
    1.12  	<%
    1.13  	// get the reference to StrabonBeanWrapper
    1.14  	StrabonBeanWrapper strabonWrapper;
    1.15 +	//String arr = new String[2];
    1.16 +	List<String[]> results = new ArrayList<String[]>();
    1.17 +	String[] arr = new String[2];
    1.18  	ServletContext context;
    1.19  	context = getServletContext();
    1.20  	WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
    1.21 @@ -205,6 +209,8 @@
    1.22        // Load the Visualization API and the piechart package.
    1.23        google.load('visualization', '1.0', {'packages':['corechart']});
    1.24  
    1.25 +      google.setOnLoadCallback(drawChart);
    1.26 +
    1.27        // Set a callback to run when the Google Visualization API is loaded.
    1.28  
    1.29  
    1.30 @@ -212,29 +218,25 @@
    1.31        // instantiates the pie chart, passes in the data and
    1.32        // draws it.
    1.33        
    1.34 -        <% if (request.getAttribute("response") != null) {
    1.35 -        	if (request.getParameter("format").equals("CHART")) {
    1.36 -        		TupleQueryResult result= request.getAttribute("response");
    1.37 -        		String label1 = esult.getBindingNames().get(0).toString();
    1.38 -        		String label2 = esult.getBindingNames().get(1).toString();
    1.39 -        		
    1.40 -        	      google.setOnLoadCallback(drawChart);
    1.41 -        	}%>
    1.42 +     
    1.43          	
    1.44        function drawChart() {
    1.45   		
    1.46          // Create the data table.
    1.47          var data = new google.visualization.DataTable();
    1.48 -        
    1.49 -     
    1.50 -        data.addColumn('string', <%=label1%>.);
    1.51 -        data.addColumn('number', <%=label2%>);
    1.52 -     
    1.53 +        <% if (request.getAttribute("response") != null) {
    1.54 +        	if (request.getParameter("format").equals("CHART")) {
    1.55 +        		 results= (List<String[]>)request.getAttribute("response");
    1.56 +        		arr[0] = results.get(0)[0];
    1.57 +        		arr[0] = results.get(0)[1];	
    1.58 +        	%>
    1.59          <%
    1.60 -        while(result.hasNext()){
    1.61 -        %>	data.addRow('string', <%=result.next().getValue(label1).toString()%>); 
    1.62 -        	data.addRow('number', <%=Integer.parseInt(result.next().getValue(label2).toString())%>);
    1.63 -        <% } %>
    1.64 +        int i=1;
    1.65 +        while(i <= results.size()){
    1.66 +        	arr =  results.get(i);
    1.67 +        %>	
    1.68 +  
    1.69 +        <% i++;} %>
    1.70          // Set chart options
    1.71          var options = {'title':'Displaying results in chart',
    1.72                         'width':400,
    1.73 @@ -243,6 +245,8 @@
    1.74          // Instantiate and draw our chart, passing in some options.
    1.75          var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    1.76          chart.draw(data, options);
    1.77 +        
    1.78 +        <%}}%>
    1.79        }
    1.80      </script>
    1.81  </head>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Fri Jul 05 17:39:45 2013 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Mon Jul 08 16:44:18 2013 +0300
     2.3 @@ -18,6 +18,8 @@
     2.4  import java.security.SecureRandom;
     2.5  import java.util.Date;
     2.6  import java.util.Iterator;
     2.7 +import java.util.ArrayList;
     2.8 +import java.util.List;
     2.9  
    2.10  import javax.servlet.RequestDispatcher;
    2.11  import javax.servlet.ServletConfig;
    2.12 @@ -91,7 +93,7 @@
    2.13  	 */
    2.14  	private String appName;
    2.15  	
    2.16 -	private TupleQueryResult result;
    2.17 +	private List<String[]> results = new ArrayList();
    2.18  
    2.19  	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    2.20  		doPost(request, response);
    2.21 @@ -334,7 +336,7 @@
    2.22  							request.setAttribute(RESPONSE, bos.toString());
    2.23  						} 
    2.24  						else if(format.equals(Format.CHART)){
    2.25 -							request.setAttribute(RESPONSE, strabonWrapper.getResult());
    2.26 +							request.setAttribute(RESPONSE, strabonWrapper.getResults());
    2.27  						}
    2.28  						else {
    2.29  							request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 05 17:39:45 2013 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Mon Jul 08 16:44:18 2013 +0300
     3.3 @@ -14,12 +14,15 @@
     3.4  import java.net.URL;
     3.5  import java.util.ArrayList;
     3.6  import java.util.Iterator;
     3.7 +import java.util.ArrayList;
     3.8  import java.util.List;
     3.9  import java.util.regex.Matcher;
    3.10  import java.util.regex.Pattern;
    3.11  
    3.12 +import org.openrdf.query.BindingSet;
    3.13  import org.openrdf.query.MalformedQueryException;
    3.14  import org.openrdf.query.QueryEvaluationException;
    3.15 +import org.openrdf.query.TupleQuery;
    3.16  import org.openrdf.query.TupleQueryResult;
    3.17  import org.openrdf.query.TupleQueryResultHandlerException;
    3.18  import org.openrdf.repository.RepositoryException;
    3.19 @@ -50,7 +53,7 @@
    3.20  	
    3.21  	private Strabon strabon = null;
    3.22  	
    3.23 -	private TupleQueryResult result=null;
    3.24 +	private List<String> results = new ArrayList<String>();
    3.25  	
    3.26  	private boolean checkForLockTable;
    3.27  	private List<StrabonBeanWrapperConfiguration> entries;
    3.28 @@ -189,7 +192,24 @@
    3.29  			throw new RepositoryException("Could not connect to Strabon.");
    3.30  		} 
    3.31  		if(answerFormatStrabon.equalsIgnoreCase(Format.CHART.toString())){
    3.32 -			result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    3.33 +			TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    3.34 +			List<String> bindingNames = result.getBindingNames();
    3.35 +			if(bindingNames.size() !=2 ){
    3.36 +				logger.error("Strabon endpoint: to display results in chart, exactly TWO variables must be projected");
    3.37 +			}
    3.38 +			
    3.39 +			//String arr = new String[2];
    3.40 +			//arr[0] = bindingNames.get(0);
    3.41 +			//arr[1] = bindingNames.get(1);
    3.42 +		    //results.add(0, arr);
    3.43 +			//while(result.hasNext()){
    3.44 +				//BindingSet bindings = result.next();
    3.45 +				//arr[0] = bindings.getValue(bindingNames.get(0)).toString();
    3.46 +				//arr[1] =bindings.getValue(bindingNames.get(1)).toString();
    3.47 +				//System.out.println("ARR1: "+arr[0]+" ARR2: "+arr[1]);
    3.48 +				//results.add(arr);
    3.49 +
    3.50 +			//}
    3.51  		}
    3.52  		else{
    3.53  			strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    3.54 @@ -385,12 +405,12 @@
    3.55  		return prefixes;
    3.56  	}
    3.57  
    3.58 -	public TupleQueryResult getResult() {
    3.59 -		return result;
    3.60 +	public List<String> getResults() {
    3.61 +		return results;
    3.62  	}
    3.63  
    3.64 -	public void setResult(TupleQueryResult result) {
    3.65 -		this.result = result;
    3.66 +	public void setResults(List<String> result) {
    3.67 +		this.results = result;
    3.68  	}
    3.69  	
    3.70  	
     4.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Fri Jul 05 17:39:45 2013 +0300
     4.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Mon Jul 08 16:44:18 2013 +0300
     4.3 @@ -73,6 +73,12 @@
     4.4  			Arrays.asList("text/html"), Charset.forName("UTF-8"), Arrays.asList("html", "htm"));
     4.5  	
     4.6  	/**
     4.7 +	 * CHART format (so that results can be displayed using google charts)  
     4.8 +	 */
     4.9 +	public static final stSPARQLQueryResultFormat CHART = new stSPARQLQueryResultFormat("CHART", 
    4.10 +			Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("chart", "chart"));
    4.11 +	
    4.12 +	/**
    4.13  	 * The available stSPARQLQuery Result Formats
    4.14  	 */
    4.15  	private static final List<stSPARQLQueryResultFormat> VALUES = new ArrayList<stSPARQLQueryResultFormat>(6);
    4.16 @@ -85,6 +91,7 @@
    4.17  		register(GEOJSON);
    4.18  		register(TSV);
    4.19  		register(HTML);
    4.20 +		register(CHART);
    4.21  	}
    4.22  	
    4.23  	/**