Strabon

changeset 560:319dcc2c9a03

remember format and handle parameters when returning to the query page after correcting the connection details
author Babis Nikolaou <charnik@di.uoa.gr>
date Tue Sep 18 21:30:07 2012 +0300 (2012-09-18)
parents 8a56ed030c78
children 1559214d32c6
files endpoint/WebContent/connection.jsp endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java
line diff
     1.1 --- a/endpoint/WebContent/connection.jsp	Tue Sep 18 21:17:58 2012 +0300
     1.2 +++ b/endpoint/WebContent/connection.jsp	Tue Sep 18 21:30:07 2012 +0300
     1.3 @@ -30,6 +30,8 @@
     1.4  
     1.5  <FORM method=POST enctype="UTF-8" accept-charset="UTF-8" action="DBConnect">
     1.6  <input type="hidden" name="query" value="<%=request.getAttribute("query")%>"/>
     1.7 +<input type="hidden" name="handle" value="<%=request.getAttribute("handle")%>"/>
     1.8 +<input type="hidden" name="format" value="<%=request.getAttribute("format")%>"/>
     1.9  <TABLE class="style4">
    1.10  	<TR> 
    1.11  		<TD valign="top" class="style4">Database Name:</TD>
     2.1 --- a/endpoint/WebContent/query.jsp	Tue Sep 18 21:17:58 2012 +0300
     2.2 +++ b/endpoint/WebContent/query.jsp	Tue Sep 18 21:30:07 2012 +0300
     2.3 @@ -50,7 +50,6 @@
     2.4  			
     2.5  			// get KML filename
     2.6  			var kml = '<%=request.getAttribute("pathToKML")%>';
     2.7 -			// <%=request.getAttribute("handle")%>
     2.8  			// create map
     2.9  			var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    2.10  		
    2.11 @@ -124,6 +123,7 @@
    2.12  <tr>
    2.13  <td id="output">stSPARQL Query:</td>
    2.14  <%
    2.15 +	// get query parameter or attribute (the attribute comes from ConnectionBean)
    2.16  	String query = "";
    2.17  	if (request.getParameter("query") != null) {
    2.18  		query = request.getParameter("query");
    2.19 @@ -132,14 +132,33 @@
    2.20  		query = (String) request.getAttribute("query");
    2.21  		
    2.22  	}
    2.23 +	
    2.24 +	// get format parameter or attribute (the attribute comes from ConnectionBean)
    2.25 +	String selFormat = "";
    2.26 +	if (request.getParameter("format") != null) {
    2.27 +		selFormat = request.getParameter("format");
    2.28 +		
    2.29 +	} else if (request.getAttribute("format") != null) {
    2.30 +		selFormat = (String) request.getAttribute("format");
    2.31 +		
    2.32 +	}
    2.33 +		
    2.34 +	// get handle parameter or attribute (the attribute comes from ConnectionBean)
    2.35 +	String handle = "";
    2.36 +	if (request.getParameter("handle") != null) {
    2.37 +		handle = request.getParameter("handle");
    2.38 +		
    2.39 +	} else if (request.getAttribute("handle") != null) {
    2.40 +		handle = (String) request.getAttribute("handle");
    2.41 +		
    2.42 +	}
    2.43  %>
    2.44  <td id="output"><textarea name="query" title="pose your query/update here" rows="15" cols="100"><%=query%></textarea></td>
    2.45  </tr>
    2.46  <tr>
    2.47  	<td id="output"><center>Output Format:<br/>
    2.48  		<select name="format" title="select one of the following output format types">
    2.49 -		<%
    2.50 -		String selFormat = request.getParameter("format") != null ? request.getParameter("format"):""; 
    2.51 +		<% 
    2.52  		for (String format : Common.registeredQueryResultsFormatNames) {%>
    2.53  				<OPTION value="<%=format%>"<%=format.equals(selFormat) ? "selected":""%>><%=format%></OPTION>
    2.54  		<%}%>
    2.55 @@ -152,10 +171,10 @@
    2.56  <tr>
    2.57  	<td id="output"><center>View Result:<br/>
    2.58  	<SELECT name="handle" title="select how you would like to view the result">
    2.59 -		<OPTION value="plain"<%= ("plain".equals(request.getAttribute("handle"))) ? "selected":""%>>Plain</OPTION>
    2.60 -		<OPTION value="download"<%= ("download".equals(request.getAttribute("handle"))) ? "selected":""%>>Download</OPTION>
    2.61 -		<OPTION value="map"<%= ("map".equals(request.getAttribute("handle"))) ? "selected":""%>>On a map</OPTION>
    2.62 -		<OPTION value="map_local"<%= ("map_local".equals(request.getAttribute("handle"))) ? "selected":""%>>On a map (localhost)</OPTION>
    2.63 +		<OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION>
    2.64 +		<OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION>
    2.65 +		<OPTION value="map"<%= ("map".equals(handle)) ? "selected":""%>>On a map</OPTION>
    2.66 +		<OPTION value="map_local"<%= ("map_local".equals(handle)) ? "selected":""%>>On a map (localhost)</OPTION>
    2.67  	</SELECT></center>
    2.68  	</td>
    2.69  	<td colspan=2>&nbsp;</td>
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java	Tue Sep 18 21:17:58 2012 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java	Tue Sep 18 21:30:07 2012 +0300
     3.3 @@ -86,16 +86,17 @@
     3.4  		RequestDispatcher dispatcher;
     3.5  		
     3.6  		// set new connection details
     3.7 -		strabonWrapper.setConnectionDetails(
     3.8 -				request.getParameter("dbname"), 
     3.9 -				request.getParameter("username"), 
    3.10 -				request.getParameter("password"), 
    3.11 -				request.getParameter("port"),
    3.12 -				request.getParameter("hostname"), 
    3.13 -				request.getParameter("dbengine"));
    3.14 +		strabonWrapper.setConnectionDetails(request.getParameter("dbname"), 
    3.15 +											request.getParameter("username"), 
    3.16 +											request.getParameter("password"), 
    3.17 +											request.getParameter("port"),
    3.18 +											request.getParameter("hostname"), 
    3.19 +											request.getParameter("dbengine"));
    3.20  		
    3.21 -		// pass the query that had been issued to the dispatcher
    3.22 -		request.setAttribute("query", request.getAttribute("query"));
    3.23 +		// pass the query, format, and the handle that had been issued to the dispatcher
    3.24 +		request.setAttribute("query",  	request.getAttribute("query"));
    3.25 +		request.setAttribute("format",  request.getAttribute("format"));
    3.26 +		request.setAttribute("handle", 	request.getAttribute("handle"));
    3.27  
    3.28  		if (logger.isInfoEnabled()) {
    3.29  			logger.info("[StrabonEndpoint.ConnectionBean] Establishing connection with database using new connection details.");
    3.30 @@ -109,13 +110,12 @@
    3.31  			}
    3.32  			
    3.33  			// save the new connection details
    3.34 -			saveNewConnectionDetails(
    3.35 -									request.getParameter("dbname"),
    3.36 -									request.getParameter("username"), 
    3.37 -									request.getParameter("password"), 
    3.38 -									request.getParameter("port"), 
    3.39 -									request.getParameter("hostname"), 
    3.40 -									request.getParameter("dbengine"));
    3.41 +			saveNewConnectionDetails(request.getParameter("dbname"),
    3.42 +									 request.getParameter("username"), 
    3.43 +									 request.getParameter("password"), 
    3.44 +									 request.getParameter("port"), 
    3.45 +									 request.getParameter("hostname"), 
    3.46 +									 request.getParameter("dbengine"));
    3.47  			
    3.48  			if (logger.isInfoEnabled()) {
    3.49  				logger.info("[StrabonEndpoint.ConnectionBean] New connection details succesfully saved.");
    3.50 @@ -156,12 +156,12 @@
    3.51  			properties.load(input);
    3.52  			
    3.53  			// update them
    3.54 -			properties.setProperty("dbname", dbname);
    3.55 -			properties.setProperty("username", username);
    3.56 -			properties.setProperty("password", password);
    3.57 -			properties.setProperty("port", port);
    3.58 -			properties.setProperty("hostname", hostname);
    3.59 -			properties.setProperty("dbengine", dbengine);
    3.60 +			properties.setProperty("dbname", 	dbname);
    3.61 +			properties.setProperty("username", 	username);
    3.62 +			properties.setProperty("password", 	password);
    3.63 +			properties.setProperty("port", 		port);
    3.64 +			properties.setProperty("hostname", 	hostname);
    3.65 +			properties.setProperty("dbengine", 	dbengine);
    3.66  			
    3.67  			// store them
    3.68  			properties.store(new FileOutputStream(context.getRealPath(CONNECTION_PROPERTIES_FILE)), null);
    3.69 @@ -170,7 +170,4 @@
    3.70  			input.close();
    3.71  		}
    3.72  	}
    3.73 -
    3.74 -	
    3.75 -
    3.76  }
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue Sep 18 21:17:58 2012 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue Sep 18 21:30:07 2012 +0300
     4.3 @@ -116,13 +116,15 @@
     4.4  			// pass the current details of the connection
     4.5  			request.setAttribute("username", strabonWrapper.getUsername());
     4.6  			request.setAttribute("password", strabonWrapper.getPassword());
     4.7 -			request.setAttribute("dbname", strabonWrapper.getDatabaseName());
     4.8 +			request.setAttribute("dbname", 	 strabonWrapper.getDatabaseName());
     4.9  			request.setAttribute("hostname", strabonWrapper.getHostName());
    4.10 -			request.setAttribute("port", strabonWrapper.getPort());
    4.11 +			request.setAttribute("port", 	 strabonWrapper.getPort());
    4.12  			request.setAttribute("dbengine", strabonWrapper.getDBEngine());
    4.13  			
    4.14 -			// pass the query as well
    4.15 +			// pass the other parameters as well
    4.16  			request.setAttribute("query", request.getParameter("query"));
    4.17 +			request.setAttribute("format", request.getParameter("format"));
    4.18 +			request.setAttribute("handle", request.getParameter("handle"));
    4.19  			
    4.20  			// forward the request
    4.21  			dispatcher.forward(request, response);