Strabon
changeset 678:caee6223be94
added full support for capabilities of QueryBean (the most needed one)
line diff
1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java Wed Oct 31 17:26:52 2012 +0200 1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java Thu Nov 01 00:18:19 2012 +0200 1.3 @@ -95,90 +95,109 @@ 1.4 1.5 @Override 1.6 public RequestCapabilities getQueryCapabilities() { 1.7 + RequestCapabilities request = new RequestCapabilitiesImpl(); 1.8 + 1.9 String query = "SELECT * WHERE {?s ?p ?o. FILTER(regex(str(?p), \"geometry\"))} LIMIT 1"; 1.10 - String[] queryParams = {"sparqlQuery", "query"}; 1.11 - String[] formatParams = {"format", null}; 1.12 + 1.13 + String[] queryParams = {"SPARQLQuery", "query"}; 1.14 + 1.15 String[] formatValues = {"XML", "KML", "KMZ", "GeoJSON", "HTML", "TSV"}; 1.16 - String[] acceptValues = {null, "application/sparql-results+xml", "text/tab-separated-values", 1.17 + 1.18 + String[] acceptValues = {"application/sparql-results+xml", "text/tab-separated-values", 1.19 "application/vnd.google-earth.kml+xml", "application/vnd.google-earth.kmz", "text/html", 1.20 "application/json"}; 1.21 1.22 + // check query parameter and format parameter 1.23 for (int q = 0; q < queryParams.length; q++) { 1.24 - for (int f = 0; f < formatParams.length; f++) { 1.25 - for (int v = 0; v < formatValues.length; v++) { 1.26 - for (int a = 0; a < acceptValues.length; a++) { 1.27 - HttpClient hc = new HttpClient(); 1.28 - 1.29 - // create a post method to execute 1.30 - PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 1.31 - 1.32 - // set the query parameter 1.33 - method.setParameter(queryParams[q], query); 1.34 - if (formatParams[f] != null) { 1.35 - method.setParameter(formatParams[f], formatValues[v]); 1.36 - 1.37 - } else { // check for accept value as well, but only when 1.38 - // we are not using the format parameter 1.39 - 1.40 - // set the accept format 1.41 - if (acceptValues[a] != null) { 1.42 - method.addRequestHeader("Accept", acceptValues[a]); 1.43 - } 1.44 - } 1.45 - 1.46 - try { 1.47 - // execute the method 1.48 - int statusCode = hc.executeMethod(method); 1.49 - 1.50 - //System.out.println(method.getResponseBodyAsString()); 1.51 - System.out.println(statusCode); 1.52 - 1.53 - if (statusCode == 200) { 1.54 - if (formatParams[f] != null) { 1.55 - System.err.println(queryParams[q] + ", " + formatParams[f] + ", " + formatValues[v]); 1.56 - 1.57 - } else { 1.58 - System.err.println(queryParams[q] + ", " + acceptValues[a]); 1.59 - } 1.60 - 1.61 - } 1.62 + for (int v = 0; v < formatValues.length; v++) { 1.63 + HttpClient hc = new HttpClient(); 1.64 + 1.65 + // create a post method to execute 1.66 + PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 1.67 + 1.68 + // set the query parameter 1.69 + method.setParameter(queryParams[q], query); 1.70 + 1.71 + // set the format parameter 1.72 + method.setParameter("format", formatValues[v]); 1.73 + 1.74 + try { 1.75 + // execute the method 1.76 + int statusCode = hc.executeMethod(method); 1.77 + 1.78 + if (statusCode == 301 || statusCode == 200) { 1.79 + //System.out.println(queryParams[q] + ", " + formatValues[v]); 1.80 + request.getParametersObject().addParameter(new Parameter(queryParams[q], null)); 1.81 + request.getParametersObject().addParameter(new Parameter("format", null)); 1.82 + request.getParametersObject().getParameter("format").addAcceptedValue(formatValues[v]); 1.83 + } 1.84 1.85 - } catch (IOException e) { 1.86 - e.printStackTrace(); 1.87 - 1.88 - } finally { 1.89 - // release the connection. 1.90 - method.releaseConnection(); 1.91 - } 1.92 - } 1.93 + } catch (IOException e) { 1.94 + e.printStackTrace(); 1.95 + 1.96 + } finally { 1.97 + // release the connection. 1.98 + method.releaseConnection(); 1.99 } 1.100 } 1.101 } 1.102 1.103 - return null; 1.104 + // check query parameter and accept header 1.105 + for (int q = 0; q < queryParams.length; q++) { 1.106 + for (int a = 0; a < acceptValues.length; a++) { 1.107 + HttpClient hc = new HttpClient(); 1.108 + 1.109 + // create a post method to execute 1.110 + PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 1.111 + 1.112 + // set the query parameter 1.113 + method.setParameter(queryParams[q], query); 1.114 + 1.115 + // check for accept value as well 1.116 + // set the accept format 1.117 + method.addRequestHeader("Accept", acceptValues[a]); 1.118 + 1.119 + try { 1.120 + // execute the method 1.121 + int statusCode = hc.executeMethod(method); 1.122 + 1.123 + if (statusCode == 301 || statusCode == 200) { 1.124 + //System.out.println(queryParams[q] + ", " + acceptValues[a]); 1.125 + request.getParametersObject().addParameter(new Parameter(queryParams[q], null)); 1.126 + request.getParametersObject().addParameter(new Parameter("Accept", null)); 1.127 + request.getParametersObject().getParameter("Accept").addAcceptedValue(acceptValues[a]); 1.128 + } 1.129 + 1.130 + } catch (IOException e) { 1.131 + e.printStackTrace(); 1.132 + 1.133 + } finally { 1.134 + // release the connection. 1.135 + method.releaseConnection(); 1.136 + } 1.137 + } 1.138 + } 1.139 + 1.140 + return request; 1.141 } 1.142 1.143 @Override 1.144 public RequestCapabilities getUpdateCapabilities() { 1.145 - // TODO Auto-generated method stub 1.146 return null; 1.147 } 1.148 1.149 @Override 1.150 public RequestCapabilities getStoreCapabilities() { 1.151 - // TODO Auto-generated method stub 1.152 return null; 1.153 } 1.154 1.155 @Override 1.156 public RequestCapabilities getBrowseCapabilities() { 1.157 - // TODO Auto-generated method stub 1.158 return null; 1.159 } 1.160 1.161 @Override 1.162 public RequestCapabilities getConnectionCapabilities() { 1.163 - // TODO Auto-generated method stub 1.164 return null; 1.165 } 1.166
2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java Wed Oct 31 17:26:52 2012 +0200 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java Thu Nov 01 00:18:19 2012 +0200 2.3 @@ -9,7 +9,6 @@ 2.4 */ 2.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 2.6 2.7 -import java.util.Collection; 2.8 import java.util.List; 2.9 2.10 2.11 @@ -34,20 +33,17 @@ 2.12 } 2.13 2.14 @Override 2.15 - public Collection<Parameter> getParameters() { 2.16 - // TODO Auto-generated method stub 2.17 + public Parameters getParametersObject() { 2.18 return null; 2.19 } 2.20 2.21 @Override 2.22 public List<String> getAcceptedValues(String param) { 2.23 - // TODO Auto-generated method stub 2.24 return null; 2.25 } 2.26 2.27 @Override 2.28 public boolean isOptional(String param) { 2.29 - // TODO Auto-generated method stub 2.30 return false; 2.31 } 2.32
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java Wed Oct 31 17:26:52 2012 +0200 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java Thu Nov 01 00:18:19 2012 +0200 3.3 @@ -114,13 +114,26 @@ 3.4 out.println("Supports DESCRIBE : " + getYesNo(caps.supportsDescribing())); 3.5 out.println("Supports CONSTRUCT : " + getYesNo(caps.supportsDescribing())); 3.6 out.println("Supports browsing : " + getYesNo(caps.supportsBrowsing())); 3.7 + out.println(); 3.8 3.9 if (caps instanceof AutoDiscoveryCapabilities) { 3.10 AutoDiscoveryCapabilities autocaps = (AutoDiscoveryCapabilities) caps; 3.11 autocaps.setEndpointDetails(request.getServerName(), request.getServerPort(), appName); 3.12 + //autocaps.setEndpointDetails("localhost", 8080, "NOA"); 3.13 } 3.14 3.15 - caps.getQueryCapabilities(); 3.16 + RequestCapabilities reCap = caps.getQueryCapabilities(); 3.17 + 3.18 + for (Parameter param : reCap.getParametersObject().getParameters()) { 3.19 + out.println("Supports parameter : " + param.getName()); 3.20 + 3.21 + if (param.getAcceptedValues().size() > 0) { 3.22 + out.println(" Accepted values : "); 3.23 + for (String acceptedValue : param.getAcceptedValues()) { 3.24 + out.println("\t\t " + acceptedValue); 3.25 + } 3.26 + } 3.27 + } 3.28 } 3.29 3.30 private String getYesNo(boolean val) {
4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java Wed Oct 31 17:26:52 2012 +0200 4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java Thu Nov 01 00:18:19 2012 +0200 4.3 @@ -9,7 +9,6 @@ 4.4 */ 4.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 4.6 4.7 -import java.util.Collection; 4.8 import java.util.List; 4.9 4.10 4.11 @@ -34,20 +33,17 @@ 4.12 } 4.13 4.14 @Override 4.15 - public Collection<Parameter> getParameters() { 4.16 - // TODO Auto-generated method stub 4.17 + public Parameters getParametersObject() { 4.18 return null; 4.19 } 4.20 4.21 @Override 4.22 public List<String> getAcceptedValues(String param) { 4.23 - // TODO Auto-generated method stub 4.24 return null; 4.25 } 4.26 4.27 @Override 4.28 public boolean isOptional(String param) { 4.29 - // TODO Auto-generated method stub 4.30 return false; 4.31 } 4.32
5.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameter.java Wed Oct 31 17:26:52 2012 +0200 5.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameter.java Thu Nov 01 00:18:19 2012 +0200 5.3 @@ -9,8 +9,8 @@ 5.4 */ 5.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 5.6 5.7 -import java.util.List; 5.8 -import java.util.Vector; 5.9 +import java.util.HashSet; 5.10 +import java.util.Set; 5.11 5.12 /** 5.13 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 5.14 @@ -21,13 +21,13 @@ 5.15 private String name; 5.16 private String value; 5.17 5.18 - private List<String> acceptedValues; 5.19 + private Set<String> acceptedValues; 5.20 5.21 public Parameter(String name, String value) { 5.22 this.name = name; 5.23 this.value = value; 5.24 5.25 - this.acceptedValues = new Vector<String>(); 5.26 + this.acceptedValues = new HashSet<String>(); 5.27 } 5.28 5.29 public String getName() { 5.30 @@ -42,7 +42,7 @@ 5.31 acceptedValues.add(value); 5.32 } 5.33 5.34 - public List<String> getAcceptedValues() { 5.35 + public Set<String> getAcceptedValues() { 5.36 return acceptedValues; 5.37 } 5.38 }
6.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameters.java Wed Oct 31 17:26:52 2012 +0200 6.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameters.java Thu Nov 01 00:18:19 2012 +0200 6.3 @@ -24,8 +24,16 @@ 6.4 params = new Hashtable<String, Parameter>(); 6.5 } 6.6 6.7 + /** 6.8 + * Adds a new parameter. If the parameter already exists, 6.9 + * the operation does nothing. 6.10 + * 6.11 + * @param param 6.12 + */ 6.13 public void addParameter(Parameter param) { 6.14 - params.put(param.getName(), param); 6.15 + if (params.get(param.getName()) == null) { 6.16 + params.put(param.getName(), param); 6.17 + } 6.18 } 6.19 6.20 public Parameter getParameter(String name) {
7.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java Wed Oct 31 17:26:52 2012 +0200 7.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java Thu Nov 01 00:18:19 2012 +0200 7.3 @@ -9,7 +9,6 @@ 7.4 */ 7.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 7.6 7.7 -import java.util.Collection; 7.8 import java.util.List; 7.9 7.10 7.11 @@ -34,7 +33,7 @@ 7.12 } 7.13 7.14 @Override 7.15 - public Collection<Parameter> getParameters() { 7.16 + public Parameters getParametersObject() { 7.17 return null; 7.18 } 7.19
8.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java Wed Oct 31 17:26:52 2012 +0200 8.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java Thu Nov 01 00:18:19 2012 +0200 8.3 @@ -9,7 +9,6 @@ 8.4 */ 8.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 8.6 8.7 -import java.util.Collection; 8.8 import java.util.List; 8.9 8.10 /** 8.11 @@ -27,7 +26,7 @@ 8.12 * 8.13 * @return 8.14 */ 8.15 - public Collection<Parameter> getParameters(); 8.16 + public Parameters getParametersObject(); 8.17 8.18 /** 8.19 * Get the accepted values of a service parameter.
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilitiesImpl.java Thu Nov 01 00:18:19 2012 +0200 9.3 @@ -0,0 +1,40 @@ 9.4 +/** 9.5 + * This Source Code Form is subject to the terms of the Mozilla Public 9.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 9.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9.8 + * 9.9 + * Copyright (C) 2012, Pyravlos Team 9.10 + * 9.11 + * http://www.strabon.di.uoa.gr/ 9.12 + */ 9.13 +package eu.earthobservatory.org.StrabonEndpoint.capabilities; 9.14 + 9.15 +import java.util.List; 9.16 + 9.17 +/** 9.18 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 9.19 + */ 9.20 +public class RequestCapabilitiesImpl implements RequestCapabilities { 9.21 + 9.22 + private Parameters params; 9.23 + 9.24 + public RequestCapabilitiesImpl() { 9.25 + params = new Parameters(); 9.26 + } 9.27 + 9.28 + @Override 9.29 + public Parameters getParametersObject() { 9.30 + return params; 9.31 + } 9.32 + 9.33 + @Override 9.34 + public List<String> getAcceptedValues(String param) { 9.35 + return null; 9.36 + } 9.37 + 9.38 + @Override 9.39 + public boolean isOptional(String param) { 9.40 + return false; 9.41 + } 9.42 + 9.43 +}
10.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java Wed Oct 31 17:26:52 2012 +0200 10.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java Thu Nov 01 00:18:19 2012 +0200 10.3 @@ -9,7 +9,6 @@ 10.4 */ 10.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 10.6 10.7 -import java.util.Collection; 10.8 import java.util.List; 10.9 10.10 10.11 @@ -34,20 +33,17 @@ 10.12 } 10.13 10.14 @Override 10.15 - public Collection<Parameter> getParameters() { 10.16 - // TODO Auto-generated method stub 10.17 + public Parameters getParametersObject() { 10.18 return null; 10.19 } 10.20 10.21 @Override 10.22 public List<String> getAcceptedValues(String param) { 10.23 - // TODO Auto-generated method stub 10.24 return null; 10.25 } 10.26 10.27 @Override 10.28 public boolean isOptional(String param) { 10.29 - // TODO Auto-generated method stub 10.30 return false; 10.31 } 10.32
11.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java Wed Oct 31 17:26:52 2012 +0200 11.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java Thu Nov 01 00:18:19 2012 +0200 11.3 @@ -9,7 +9,6 @@ 11.4 */ 11.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 11.6 11.7 -import java.util.Collection; 11.8 import java.util.List; 11.9 11.10 11.11 @@ -34,20 +33,17 @@ 11.12 } 11.13 11.14 @Override 11.15 - public Collection<Parameter> getParameters() { 11.16 - // TODO Auto-generated method stub 11.17 + public Parameters getParametersObject() { 11.18 return null; 11.19 } 11.20 11.21 @Override 11.22 public List<String> getAcceptedValues(String param) { 11.23 - // TODO Auto-generated method stub 11.24 return null; 11.25 } 11.26 11.27 @Override 11.28 public boolean isOptional(String param) { 11.29 - // TODO Auto-generated method stub 11.30 return false; 11.31 } 11.32 }