Strabon

changeset 1189:c99b065768d9

changes to support exporting statistical results in charts
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Fri Jul 05 17:39:45 2013 +0300 (2013-07-05)
parents 94f44f1044be
children a5340fe30e7f 756d8f688fff
files endpoint/WebContent/WEB-INF/connection.properties endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.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/utils/Format.java
line diff
     1.1 --- a/endpoint/WebContent/WEB-INF/connection.properties	Thu Jul 04 17:56:41 2013 +0300
     1.2 +++ b/endpoint/WebContent/WEB-INF/connection.properties	Fri Jul 05 17:39:45 2013 +0300
     1.3 @@ -1,6 +1,6 @@
     1.4  hostname=localhost
     1.5  port=5432
     1.6  dbengine=postgis
     1.7 -password=postgres
     1.8 -dbname=endpoint
     1.9 +password=p1r3as
    1.10 +dbname=DLRDemo-y3
    1.11  username=postgres
     2.1 --- a/endpoint/WebContent/query.jsp	Thu Jul 04 17:56:41 2013 +0300
     2.2 +++ b/endpoint/WebContent/query.jsp	Fri Jul 05 17:39:45 2013 +0300
     2.3 @@ -6,6 +6,7 @@
     2.4  <%@page import="eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapperConfiguration"%>
     2.5  <%@page import="java.util.List"%>
     2.6  <%@page import="java.util.Iterator"%>
     2.7 +<%@page import="org.openrdf.query.TupleQueryResult"%>
     2.8  <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/>
     2.9  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    2.10  <html>
    2.11 @@ -197,6 +198,53 @@
    2.12   	<!-- jQuery end -->
    2.13   
    2.14  	<title>TELEIOS: Strabon Endpoint</title>
    2.15 +	   <!--Load the AJAX API-->
    2.16 +    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    2.17 +    <script type="text/javascript">
    2.18 +
    2.19 +      // Load the Visualization API and the piechart package.
    2.20 +      google.load('visualization', '1.0', {'packages':['corechart']});
    2.21 +
    2.22 +      // Set a callback to run when the Google Visualization API is loaded.
    2.23 +
    2.24 +
    2.25 +      // Callback that creates and populates a data table,
    2.26 +      // instantiates the pie chart, passes in the data and
    2.27 +      // draws it.
    2.28 +      
    2.29 +        <% if (request.getAttribute("response") != null) {
    2.30 +        	if (request.getParameter("format").equals("CHART")) {
    2.31 +        		TupleQueryResult result= request.getAttribute("response");
    2.32 +        		String label1 = esult.getBindingNames().get(0).toString();
    2.33 +        		String label2 = esult.getBindingNames().get(1).toString();
    2.34 +        		
    2.35 +        	      google.setOnLoadCallback(drawChart);
    2.36 +        	}%>
    2.37 +        	
    2.38 +      function drawChart() {
    2.39 + 		
    2.40 +        // Create the data table.
    2.41 +        var data = new google.visualization.DataTable();
    2.42 +        
    2.43 +     
    2.44 +        data.addColumn('string', <%=label1%>.);
    2.45 +        data.addColumn('number', <%=label2%>);
    2.46 +     
    2.47 +        <%
    2.48 +        while(result.hasNext()){
    2.49 +        %>	data.addRow('string', <%=result.next().getValue(label1).toString()%>); 
    2.50 +        	data.addRow('number', <%=Integer.parseInt(result.next().getValue(label2).toString())%>);
    2.51 +        <% } %>
    2.52 +        // Set chart options
    2.53 +        var options = {'title':'Displaying results in chart',
    2.54 +                       'width':400,
    2.55 +                       'height':300};
    2.56 +
    2.57 +        // Instantiate and draw our chart, passing in some options.
    2.58 +        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    2.59 +        chart.draw(data, options);
    2.60 +      }
    2.61 +    </script>
    2.62  </head>
    2.63  <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" onload="initialize()">
    2.64  
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Jul 04 17:56:41 2013 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Fri Jul 05 17:39:45 2013 +0300
     3.3 @@ -31,6 +31,7 @@
     3.4  import org.apache.commons.io.FileUtils;
     3.5  import org.apache.commons.lang.StringEscapeUtils;
     3.6  import org.openrdf.query.MalformedQueryException;
     3.7 +import org.openrdf.query.TupleQueryResult;
     3.8  import org.openrdf.query.resultio.TupleQueryResultFormat;
     3.9  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    3.10  import org.slf4j.Logger;
    3.11 @@ -38,6 +39,8 @@
    3.12  import org.springframework.web.context.WebApplicationContext;
    3.13  import org.springframework.web.context.support.WebApplicationContextUtils;
    3.14  
    3.15 +import eu.earthobservatory.utils.Format;
    3.16 +
    3.17  /**
    3.18   * 
    3.19   * @author Kostis Kyzirakos <kkyzir@di.uoa.gr>
    3.20 @@ -87,6 +90,8 @@
    3.21  	 * The name of this web application
    3.22  	 */
    3.23  	private String appName;
    3.24 +	
    3.25 +	private TupleQueryResult result;
    3.26  
    3.27  	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    3.28  		doPost(request, response);
    3.29 @@ -327,7 +332,11 @@
    3.30  						strabonWrapper.query(query, format, bos);
    3.31  						if (format.equals(Common.getHTMLFormat())) {
    3.32  							request.setAttribute(RESPONSE, bos.toString());
    3.33 -						} else {
    3.34 +						} 
    3.35 +						else if(format.equals(Format.CHART)){
    3.36 +							request.setAttribute(RESPONSE, strabonWrapper.getResult());
    3.37 +						}
    3.38 +						else {
    3.39  							request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
    3.40  						}
    3.41  						
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Jul 04 17:56:41 2013 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 05 17:39:45 2013 +0300
     4.3 @@ -20,6 +20,7 @@
     4.4  
     4.5  import org.openrdf.query.MalformedQueryException;
     4.6  import org.openrdf.query.QueryEvaluationException;
     4.7 +import org.openrdf.query.TupleQueryResult;
     4.8  import org.openrdf.query.TupleQueryResultHandlerException;
     4.9  import org.openrdf.repository.RepositoryException;
    4.10  import org.openrdf.rio.RDFHandlerException;
    4.11 @@ -49,6 +50,8 @@
    4.12  	
    4.13  	private Strabon strabon = null;
    4.14  	
    4.15 +	private TupleQueryResult result=null;
    4.16 +	
    4.17  	private boolean checkForLockTable;
    4.18  	private List<StrabonBeanWrapperConfiguration> entries;
    4.19  
    4.20 @@ -185,7 +188,12 @@
    4.21  		if ((this.strabon == null) && (!init())) {
    4.22  			throw new RepositoryException("Could not connect to Strabon.");
    4.23  		} 
    4.24 -		strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    4.25 +		if(answerFormatStrabon.equalsIgnoreCase(Format.CHART.toString())){
    4.26 +			result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    4.27 +		}
    4.28 +		else{
    4.29 +			strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out);
    4.30 +		}
    4.31  		
    4.32  	}
    4.33  	
    4.34 @@ -377,5 +385,15 @@
    4.35  		return prefixes;
    4.36  	}
    4.37  
    4.38 +	public TupleQueryResult getResult() {
    4.39 +		return result;
    4.40 +	}
    4.41 +
    4.42 +	public void setResult(TupleQueryResult result) {
    4.43 +		this.result = result;
    4.44 +	}
    4.45 +	
    4.46 +	
    4.47 +
    4.48  }
    4.49  
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Thu Jul 04 17:56:41 2013 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 05 17:39:45 2013 +0300
     5.3 @@ -264,7 +264,9 @@
     5.4  			case TUQU:
     5.5  				
     5.6  				return tupleQuery;
     5.7 -//				break;			
     5.8 +//				break;	
     5.9 +			case CHART:
    5.10 +				return tupleQuery.evaluate();
    5.11  				
    5.12  			default:
    5.13  				// get the writer for the specified format
     6.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Thu Jul 04 17:56:41 2013 +0300
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Fri Jul 05 17:39:45 2013 +0300
     6.3 @@ -94,7 +94,9 @@
     6.4  	/**
     6.5  	 * Invalid format.
     6.6  	 */
     6.7 -	INVALID("INVALID");
     6.8 +	INVALID("INVALID"),
     6.9 +	
    6.10 +	CHART("CHART");
    6.11  	
    6.12  	/**
    6.13  	 * The string representation of this format
    6.14 @@ -112,6 +114,7 @@
    6.15  			// add both upper- and lower-case versions of the format 
    6.16  			stringToEnum.put(format.toString(), format);
    6.17  			stringToEnum.put(format.toString().toLowerCase(), format);
    6.18 +	
    6.19  		}
    6.20  	}
    6.21