Strabon

changeset 1070:eec1a8547bc2

Endpoint-store now supports everything Strabon-store supports (named graphs and inference).
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Tue Apr 23 20:12:03 2013 +0300 (2013-04-23)
parents 49d07fd6367e
children 93f5d7b2d3cb
files endpoint/WebContent/store.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/endpoint/WebContent/store.jsp	Tue Apr 23 16:15:52 2013 +0300
     1.2 +++ b/endpoint/WebContent/store.jsp	Tue Apr 23 20:12:03 2013 +0300
     1.3 @@ -44,7 +44,7 @@
     1.4  
     1.5  <% if (request.getAttribute("error") != null) {%>
     1.6  		<!-- Error Message -->
     1.7 -	  		<TR><TD colspan=3>
     1.8 +	  		<TR><TD colspan=2>
     1.9  	  		<CENTER><P style="color: red;"><%=request.getAttribute("error") %></P></CENTER>
    1.10  	  		</TD></TR>
    1.11  		<!-- Error Message -->
    1.12 @@ -52,29 +52,47 @@
    1.13  
    1.14  <%if (request.getAttribute("info") != null) { %>
    1.15  	<!-- Info Message -->
    1.16 -  		<TR><TD colspan=3>
    1.17 +  		<TR><TD colspan=2>
    1.18    		<CENTER><P><%=request.getAttribute("info") %></P></CENTER>
    1.19    		</TD></TR>
    1.20  	<!-- Info Message -->
    1.21  <%}%>
    1.22  	<tr>
    1.23 -	<!--  direct input form -->
    1.24 -		<td id="output">Direct Input:</td>
    1.25 -		<td id="output">
    1.26 +		<td colspan=2 id="output">
    1.27  			<div style="font-size:13px"> 
    1.28  				You must be logged in to store.
    1.29 -			</div>	
    1.30 -			<textarea name="data" rows="15" cols="100"></textarea></td>
    1.31 -		<td rowspan=4 id="output">
    1.32 -			<CENTER>RDF Format:<br/>
    1.33 +			</div>
    1.34 +		</td>	
    1.35 +	</tr>
    1.36 +	<tr>
    1.37 +		<!--  direct input form -->
    1.38 +		<td id="output">Graph:</td>
    1.39 +		<td id="output">
    1.40 +			<textarea name="graph" title="URI of the named graph to store the input" rows="1" cols="100"></textarea>
    1.41 +		</td>
    1.42 +	</tr>
    1.43 +	<tr>
    1.44 +		<td id="output">RDF Format:</td>
    1.45 +		<td id="output">
    1.46  				<SELECT name="format" title="select one of the following RDF graph format types">
    1.47  				<% for (String format : Common.registeredFormats) {%>
    1.48  					<OPTION value="<%=format%>"><%=format%></OPTION>
    1.49  				<%}%>
    1.50  				</SELECT>
    1.51 -			</CENTER>
    1.52  		</td>
    1.53  	</tr>
    1.54 +		<tr>
    1.55 +		<td id="output">Inference:</td>
    1.56 +		<td id="output">
    1.57 +				<input type="checkbox" title="Enable Inference" name="inference" value="true"> <br>
    1.58 +		</td>
    1.59 +	</tr>
    1.60 +	<tr>
    1.61 +		<!--  direct input form -->
    1.62 +		<td id="output">Direct Input:</td>
    1.63 +		<td id="output">
    1.64 +			<textarea name="data" rows="15" cols="100"></textarea></td>
    1.65 +	</tr>
    1.66  	<tr>
    1.67  		<td colspan=2 id="output"><br/>
    1.68  		<CENTER>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Tue Apr 23 16:15:52 2013 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Tue Apr 23 20:12:03 2013 +0300
     2.3 @@ -3,7 +3,7 @@
     2.4   * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.5   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.6   * 
     2.7 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team
     2.8 + * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team
     2.9   * 
    2.10   * http://www.strabon.di.uoa.gr/
    2.11   */
    2.12 @@ -20,6 +20,7 @@
    2.13   * Keeps common variables shared by beans and .jsp pages.
    2.14   *
    2.15   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    2.16 + * @author Panayiotis Smeros <psmeros@di.uoa.gr>
    2.17   */
    2.18  public class Common {
    2.19  	  
    2.20 @@ -36,6 +37,10 @@
    2.21  	public static final String PARAM_DATA 		= "data";
    2.22  	public static final String PARAM_FORMAT 	= "format";
    2.23  	public static final String PARAM_DATA_URL	= "url";
    2.24 +	public static final String PARAM_INFERENCE	= "inference";
    2.25 +	public static final String PARAM_GRAPH	    = "graph";
    2.26 +
    2.27 +
    2.28  	
    2.29  	/**
    2.30  	 * Submit buttons in store.jsp
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Tue Apr 23 16:15:52 2013 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Tue Apr 23 20:12:03 2013 +0300
     3.3 @@ -13,6 +13,7 @@
     3.4  import java.io.UnsupportedEncodingException;
     3.5  import java.net.MalformedURLException;
     3.6  import java.net.URLDecoder;
     3.7 +import java.util.Map;
     3.8  
     3.9  import javax.servlet.RequestDispatcher;
    3.10  import javax.servlet.ServletConfig;
    3.11 @@ -138,6 +139,12 @@
    3.12      			
    3.13      	// the format of the data
    3.14      	RDFFormat format = (request.getParameter(Common.PARAM_FORMAT) != null) ? RDFFormat.valueOf(request.getParameter(Common.PARAM_FORMAT)):null;
    3.15 +
    3.16 +      	// graph
    3.17 +    	String graph = (request.getParameter(Common.PARAM_GRAPH) != null) ? request.getParameter(Common.PARAM_GRAPH):null;
    3.18 +    	    	
    3.19 +      	// inference
    3.20 +    	Boolean inference = (request.getParameter(Common.PARAM_INFERENCE) != null) ? Boolean.valueOf(request.getParameter(Common.PARAM_INFERENCE)):false;
    3.21      	
    3.22      	if (data == null || format == null) {
    3.23      		request.setAttribute(ERROR, PARAM_ERROR);
    3.24 @@ -146,7 +153,7 @@
    3.25      		
    3.26      		// store data
    3.27      		try {
    3.28 -    			strabon.store(data, format, !input);
    3.29 +    			strabon.store(data, graph, format.getName(), inference, !input);
    3.30      			
    3.31      			// store was successful, return the respective message
    3.32      			request.setAttribute(INFO, STORE_OK);
    3.33 @@ -189,7 +196,9 @@
    3.34  		
    3.35  		// store data
    3.36  		try {
    3.37 -			strabon.store(data, format, !input);
    3.38 +			
    3.39 +			//TODO!!!!!!!!!! remove comment
    3.40 +			//strabon.store(data, format, !input);
    3.41  			
    3.42  			// store was successful, return the respective message
    3.43  			response.sendError(HttpServletResponse.SC_OK);
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Tue Apr 23 16:15:52 2013 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Tue Apr 23 20:12:03 2013 +0300
     4.3 @@ -3,17 +3,14 @@
     4.4   * License, v. 2.0. If a copy of the MPL was not distributed with this
     4.5   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4.6   * 
     4.7 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team
     4.8 + * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team
     4.9   * 
    4.10   * http://www.strabon.di.uoa.gr/
    4.11   */
    4.12  package eu.earthobservatory.org.StrabonEndpoint;
    4.13  
    4.14 -import eu.earthobservatory.utils.Format;
    4.15 -
    4.16  import java.io.IOException;
    4.17  import java.io.OutputStream;
    4.18 -import java.io.StringReader;
    4.19  import java.net.URL;
    4.20  import java.util.ArrayList;
    4.21  import java.util.Iterator;
    4.22 @@ -21,18 +18,18 @@
    4.23  import java.util.regex.Matcher;
    4.24  import java.util.regex.Pattern;
    4.25  
    4.26 -import org.openrdf.model.Resource;
    4.27  import org.openrdf.query.MalformedQueryException;
    4.28  import org.openrdf.query.QueryEvaluationException;
    4.29  import org.openrdf.query.TupleQueryResultHandlerException;
    4.30  import org.openrdf.repository.RepositoryException;
    4.31 -import org.openrdf.repository.sail.SailRepositoryConnection;
    4.32 -import org.openrdf.rio.RDFFormat;
    4.33 +import org.openrdf.rio.RDFHandlerException;
    4.34 +import org.openrdf.rio.RDFParseException;
    4.35  import org.slf4j.Logger;
    4.36  import org.slf4j.LoggerFactory;
    4.37  
    4.38 -import eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapperConfiguration;
    4.39 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault;
    4.40  import eu.earthobservatory.runtime.generaldb.Strabon;
    4.41 +import eu.earthobservatory.utils.Format;
    4.42  
    4.43  
    4.44  public class StrabonBeanWrapper implements org.springframework.beans.factory.DisposableBean {
    4.45 @@ -242,41 +239,33 @@
    4.46  	 * @return
    4.47  	 * @throws MalformedQueryException
    4.48  	 * @throws RepositoryException
    4.49 +	 * @throws InvalidDatasetFormatFault 
    4.50 +	 * @throws RDFHandlerException 
    4.51 +	 * @throws RDFParseException 
    4.52  	 * @throws QueryEvaluationException
    4.53  	 * @throws TupleQueryResultHandlerException
    4.54  	 * @throws IOException
    4.55  	 * @throws ClassNotFoundException
    4.56  	 */
    4.57 -	public boolean store(String source_data, RDFFormat format, boolean url) throws Exception {
    4.58 +	public boolean store(String src, String context, String format, Boolean inference, Boolean url) throws RepositoryException, RDFParseException, RDFHandlerException, IOException, InvalidDatasetFormatFault {
    4.59  		logger.info("[StrabonEndpoint] Received STORE request.");
    4.60  		
    4.61  		if ((this.strabon == null) && (!init())) {
    4.62  			throw new RepositoryException("Could not connect to Strabon.");
    4.63  		}
    4.64  
    4.65 -		// get sail connection
    4.66 -		SailRepositoryConnection conn = strabon.getSailRepoConnection();
    4.67 -
    4.68 -		try {
    4.69 -			// store data
    4.70 -			if (url) {
    4.71 -				URL source = new URL(source_data);
    4.72 -				if (source.getProtocol().equalsIgnoreCase(FILE_PROTOCOL)) {
    4.73 -					// it would be a security issue if we read from the server's filesystem
    4.74 -					throw new IllegalArgumentException("The protocol of the URL should be one of http or ftp.");
    4.75 -				} 
    4.76 -				conn.add(source, "", format, new Resource[1]);
    4.77 -
    4.78 -			} else {
    4.79 -				conn.add(new StringReader(source_data), "", format, new Resource[1]);
    4.80 +		if (url) {
    4.81 +			URL source = new URL(src);
    4.82 +			if (source.getProtocol().equalsIgnoreCase(FILE_PROTOCOL)) {
    4.83 +				// it would be a security issue if we read from the server's filesystem
    4.84 +				throw new IllegalArgumentException("The protocol of the URL should be one of http or ftp.");
    4.85  			}
    4.86 -			
    4.87 -			logger.info("[StrabonEndpoint] STORE was successful.");
    4.88 -
    4.89 -		} catch (Exception e) {
    4.90 -			throw e;
    4.91  		}
    4.92  
    4.93 +		strabon.storeInRepo(src, null, context, format, inference);
    4.94 +		
    4.95 +		logger.info("[StrabonEndpoint] STORE was successful.");
    4.96 +		
    4.97  		return true;
    4.98  	}
    4.99  
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Apr 23 16:15:52 2013 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Tue Apr 23 20:12:03 2013 +0300
     5.3 @@ -332,16 +332,16 @@
     5.4  			uriContext = f.createURI(context);
     5.5  		}
     5.6  
     5.7 -		if(format.equalsIgnoreCase("N3")) {
     5.8 +		if(format.equalsIgnoreCase("N3") || format.equals(RDFFormat.N3.getName())) {
     5.9  			realFormat =  RDFFormat.N3;
    5.10  			
    5.11 -		} else if(format.equalsIgnoreCase("NTRIPLES")) {
    5.12 +		} else if(format.equalsIgnoreCase("NTRIPLES") || format.equals(RDFFormat.NTRIPLES.getName())) {
    5.13  			realFormat =  RDFFormat.NTRIPLES;
    5.14  			
    5.15 -		} else if(format.equalsIgnoreCase("RDFXML")) {
    5.16 +		} else if(format.equalsIgnoreCase("RDFXML") || format.equals(RDFFormat.RDFXML.getName())) {
    5.17  			realFormat =  RDFFormat.RDFXML;
    5.18  			
    5.19 -		} else if(format.equalsIgnoreCase("TURTLE")) {
    5.20 +		} else if(format.equalsIgnoreCase("TURTLE") || format.equals(RDFFormat.TURTLE.getName())) {
    5.21  			realFormat =  RDFFormat.TURTLE;
    5.22  			
    5.23  		} else {