Strabon
changeset 629:e6d414360f33
#6: Now maxLimit variable can be set at beans.xml. It can be also passed as parameter at the url.
author | Stella Giannakopoulou <sgian@di.uoa.gr> |
---|---|
date | Mon Oct 08 22:29:21 2012 +0300 (2012-10-08) |
parents | 9e0cad04ccd9 |
children | 206d8add2a85 |
files | endpoint/WebContent/WEB-INF/beans.xml endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java |
line diff
1.1 --- a/endpoint/WebContent/WEB-INF/beans.xml Mon Oct 08 21:15:46 2012 +0300 1.2 +++ b/endpoint/WebContent/WEB-INF/beans.xml Mon Oct 08 22:29:21 2012 +0300 1.3 @@ -54,6 +54,11 @@ 1.4 <value>${dbengine}</value> 1.5 </constructor-arg> 1.6 1.7 + <constructor-arg type="int" > 1.8 + <!-- Query limit --> 1.9 + <value>1000</value> 1.10 + </constructor-arg> 1.11 + 1.12 <constructor-arg> 1.13 <list> 1.14 <list>
2.1 --- a/endpoint/WebContent/query.jsp Mon Oct 08 21:15:46 2012 +0300 2.2 +++ b/endpoint/WebContent/query.jsp Mon Oct 08 22:29:21 2012 +0300 2.3 @@ -197,7 +197,6 @@ 2.4 2.5 <FORM enctype="UTF-8" accept-charset="UTF-8" method="post" action="Query"> 2.6 <INPUT type=hidden name="view" value="HTML"/> 2.7 -<INPUT type=hidden name="limitQuery" value="true"/> 2.8 2.9 <table border="0" width="100%"> 2.10 <tr>
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Mon Oct 08 21:15:46 2012 +0300 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Mon Oct 08 22:29:21 2012 +0300 3.3 @@ -208,19 +208,18 @@ 3.4 String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 3.5 String format = request.getParameter("format"); 3.6 String handle = request.getParameter("handle"); 3.7 - String limitQuery = request.getParameter("limitQuery"); 3.8 + String maxLimit = request.getParameter("maxLimit"); 3.9 3.10 // get stSPARQLQueryResultFormat from given format name 3.11 stSPARQLQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format); 3.12 3.13 - if (query == null || format == null || queryResultFormat == null || limitQuery == null) { 3.14 + if (query == null || format == null || queryResultFormat == null) { 3.15 dispatcher = request.getRequestDispatcher("query.jsp"); 3.16 request.setAttribute(ERROR, PARAM_ERROR); 3.17 dispatcher.forward(request, response); 3.18 3.19 } else { 3.20 - if(limitQuery.equals("true")) 3.21 - query = strabonWrapper.addLimit(query); 3.22 + query = strabonWrapper.addLimit(query, maxLimit); 3.23 if ("download".equals(handle)) { // download as attachment 3.24 ServletOutputStream out = response.getOutputStream(); 3.25
4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Mon Oct 08 21:15:46 2012 +0300 4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Mon Oct 08 22:29:21 2012 +0300 4.3 @@ -39,7 +39,6 @@ 4.4 private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.class); 4.5 4.6 private static final String FILE_PROTOCOL = "file"; 4.7 - private static final int MAX_LIMIT = 300; 4.8 4.9 private String serverName; 4.10 private int port; 4.11 @@ -47,6 +46,7 @@ 4.12 private String user; 4.13 private String password; 4.14 private String dbBackend; 4.15 + private int maxLimit; 4.16 4.17 private Strabon strabon = null; 4.18 4.19 @@ -54,7 +54,7 @@ 4.20 private List<StrabonBeanWrapperConfiguration> entries; 4.21 4.22 public StrabonBeanWrapper(String databaseName, String user, String password, 4.23 - int port, String serverName, boolean checkForLockTable, String dbBackend, List<List<String>> args) { 4.24 + int port, String serverName, boolean checkForLockTable, String dbBackend, int maxLimit, List<List<String>> args) { 4.25 this.serverName = serverName; 4.26 this.port = port; 4.27 this.databaseName = databaseName; 4.28 @@ -62,6 +62,7 @@ 4.29 this.password = password; 4.30 this.checkForLockTable = checkForLockTable; 4.31 this.dbBackend = dbBackend; 4.32 + this.maxLimit = maxLimit; 4.33 this.entries = new ArrayList<StrabonBeanWrapperConfiguration>(args.size()); 4.34 4.35 Iterator<List<String>> entryit = args.iterator(); 4.36 @@ -343,27 +344,37 @@ 4.37 /* 4.38 * Limit the number of solutions returned. 4.39 * */ 4.40 - public String addLimit(String queryString){ 4.41 + public String addLimit(String queryString, String maxLimit){ 4.42 String limitedQuery = queryString; 4.43 - Pattern limitPattern = Pattern.compile("limit \\d.*", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); 4.44 - Matcher limitMatcher = limitPattern.matcher(queryString); 4.45 + int max; 4.46 4.47 - // check whether the query contains a limit clause 4.48 - if(limitMatcher.find()) 4.49 - { 4.50 - String limitString = limitMatcher.group(); 4.51 - 4.52 - Pattern rowsNumberPattern = Pattern.compile("\\d+"); 4.53 - Matcher rowsNumberMatcher = rowsNumberPattern.matcher(limitString); 4.54 - rowsNumberMatcher.find(); 4.55 + if(maxLimit == null) 4.56 + max = this.maxLimit; 4.57 + else 4.58 + max = Integer.valueOf(maxLimit); 4.59 + 4.60 + if(max > 0) 4.61 + { 4.62 + Pattern limitPattern = Pattern.compile("limit \\d.*", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); 4.63 + Matcher limitMatcher = limitPattern.matcher(queryString); 4.64 4.65 - // if the initial limit is greater than the maximum, set it to the maximum 4.66 - if(Integer.valueOf(rowsNumberMatcher.group()) > MAX_LIMIT) 4.67 - limitedQuery = limitMatcher.replaceAll("limit "+MAX_LIMIT); 4.68 - } 4.69 - else // add a limit to the query 4.70 - limitedQuery = queryString+"limit "+MAX_LIMIT; 4.71 + // check whether the query contains a limit clause 4.72 + if(limitMatcher.find()) 4.73 + { 4.74 + String limitString = limitMatcher.group(); 4.75 + 4.76 + Pattern rowsNumberPattern = Pattern.compile("\\d+"); 4.77 + Matcher rowsNumberMatcher = rowsNumberPattern.matcher(limitString); 4.78 + rowsNumberMatcher.find(); 4.79 + 4.80 + // if the initial limit is greater than the maximum, set it to the maximum 4.81 + if(Integer.valueOf(rowsNumberMatcher.group()) > max) 4.82 + limitedQuery = limitMatcher.replaceAll("limit "+max); 4.83 + } 4.84 + else // add a limit to the query 4.85 + limitedQuery = queryString+"limit "+max; 4.86 4.87 + } 4.88 return limitedQuery; 4.89 } 4.90