aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2012-07-26 12:57:38 (EDT)
committerMichael Fiedler2012-08-01 16:33:24 (EDT)
commit118b40995eb0c7f68879ec6fd38585df31525f8a (patch)
treeb1ee7f3d941d1540d9e174cc9b164dd70df7eaa1
parent7c85286016f0996d7af1c41469d335aff7af367f (diff)
downloadorg.eclipse.lyo.docs-118b40995eb0c7f68879ec6fd38585df31525f8a.zip
org.eclipse.lyo.docs-118b40995eb0c7f68879ec6fd38585df31525f8a.tar.gz
org.eclipse.lyo.docs-118b40995eb0c7f68879ec6fd38585df31525f8a.tar.bz2
Bug 384760: Add Support for Paged Query Resultsrefs/changes/82/6982/2
Change-Id: Idf0d6c49e79cb4ad161efd287a007897cc458a68 Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java17
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/Constants.java2
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java63
3 files changed, 76 insertions, 6 deletions
diff --git a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
index 096ddf1..4791896 100644
--- a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
+++ b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java
@@ -301,6 +301,12 @@ public class BugzillaManager implements ServletContextListener {
} else if (fulltextSearch) {
buffer.append("&order=relevance+DESC");
+
+ } else {
+
+ // Always order at least by bug id, so we get
+ // non-random returns across pages
+ buffer.append("&order=bug_id");
}
Credentials credentials = (Credentials)httpServletRequest.getSession().getAttribute(CredentialsFilter.CREDENTIALS_ATTRIBUTE);
@@ -319,7 +325,14 @@ public class BugzillaManager implements ServletContextListener {
builder = factory.newDocumentBuilder();
- for (int idx = 0; idx < list.getLength(); idx++) {
+ int length = list.getLength();
+
+ if (length > limit) {
+ httpServletRequest.setAttribute(Constants.NEXT_PAGE, page + 1);
+ length--;
+ }
+
+ for (int idx = 0; idx < length; idx++) {
Element p = (Element)list.item(idx);
@@ -457,7 +470,7 @@ public class BugzillaManager implements ServletContextListener {
Map<String, String> prefixMap, final StringBuffer buffer) throws ParseException
{
buffer.append("&limit=");
- buffer.append(limit);
+ buffer.append(limit + 1);
buffer.append("&offset=");
buffer.append(page * limit);
diff --git a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/Constants.java b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/Constants.java
index e98e737..e5213c9 100644
--- a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/Constants.java
+++ b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/Constants.java
@@ -56,4 +56,6 @@ public interface Constants
public static String USAGE_LIST = CHANGE_MANAGEMENT_NAMESPACE + "list";
public static final String HDR_OSLC_VERSION = "OSLC-Core-Version";
+
+ public static final String NEXT_PAGE = "org.eclipse.lyo.oslc4j.bugzilla.NextPage";
}
diff --git a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
index c53bade..7f27f55 100644
--- a/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
+++ b/OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -125,6 +126,8 @@ public class BugzillaChangeRequestService
* @param pageString
* @param orderBy
* @param searchTerms
+ * @param paging
+ * @param pageSize
* @return
* @throws IOException
* @throws ServletException
@@ -137,8 +140,16 @@ public class BugzillaChangeRequestService
@QueryParam("oslc.prefix") final String prefix,
@QueryParam("page") final String pageString,
@QueryParam("oslc.orderBy") final String orderBy,
- @QueryParam("oslc.searchTerms") final String searchTerms) throws IOException, ServletException
+ @QueryParam("oslc.searchTerms") final String searchTerms,
+ @QueryParam("oslc.paging") final String paging,
+ @QueryParam("oslc.pageSize") final String pageSize) throws IOException, ServletException
{
+ boolean isPaging = false;
+
+ if (paging != null) {
+ isPaging = Boolean.parseBoolean(paging);
+ }
+
int page=0;
if (null != pageString) {
@@ -146,6 +157,11 @@ public class BugzillaChangeRequestService
}
int limit=10;
+
+ if (isPaging && pageSize != null) {
+ limit = Integer.parseInt(pageSize);
+ }
+
Map<String, String> prefixMap;
try {
@@ -176,8 +192,45 @@ public class BugzillaChangeRequestService
where, prefixMap,
propMap, orderBy, searchTerms);
+ Object nextPageAttr = httpServletRequest.getAttribute(Constants.NEXT_PAGE);
+
+ if (! isPaging && nextPageAttr != null) {
+
+ String location =
+ uriInfo.getBaseUri().toString() + uriInfo.getPath() + '?' +
+ (where != null ? ("oslc.where=" + URLEncoder.encode(where, "UTF-8") + '&') : "") +
+ (select != null ? ("oslc.select=" + URLEncoder.encode(select, "UTF-8") + '&') : "") +
+ (prefix != null ? ("oslc.prefix=" + URLEncoder.encode(prefix, "UTF-8") + '&') : "") +
+ (orderBy != null ? ("oslc.orderBy=" + URLEncoder.encode(orderBy, "UTF-8") + '&') : "") +
+ (searchTerms != null ? ("oslc.searchTerms=" + URLEncoder.encode(searchTerms, "UTF-8") + '&') : "") +
+ "oslc.paging=true&oslc.pageSize=" + limit;
+
+ try {
+ throw new WebApplicationException(Response.temporaryRedirect(new URI(location)).build());
+ } catch (URISyntaxException e) {
+ // XXX - Can't happen
+ throw new IllegalStateException(e);
+ }
+ }
+
httpServletRequest.setAttribute(OSLC4JConstants.OSLC4J_SELECTED_PROPERTIES,
propMap);
+
+ if (nextPageAttr != null) {
+
+ String location =
+ uriInfo.getBaseUri().toString() + uriInfo.getPath() + '?' +
+ (where != null ? ("oslc.where=" + URLEncoder.encode(where, "UTF-8") + '&') : "") +
+ (select != null ? ("oslc.select=" + URLEncoder.encode(select, "UTF-8") + '&') : "") +
+ (prefix != null ? ("oslc.prefix=" + URLEncoder.encode(prefix, "UTF-8") + '&') : "") +
+ (orderBy != null ? ("oslc.orderBy=" + URLEncoder.encode(orderBy, "UTF-8") + '&') : "") +
+ (searchTerms != null ? ("oslc.searchTerms=" + URLEncoder.encode(searchTerms, "UTF-8") + '&') : "") +
+ "oslc.paging=true&oslc.pageSize=" + limit + "&page=" + nextPageAttr;
+
+ httpServletRequest.setAttribute(OSLC4JConstants.OSLC4J_NEXT_PAGE,
+ location);
+
+ }
return results;
}
@@ -290,10 +343,12 @@ public class BugzillaChangeRequestService
httpServletRequest.setAttribute("queryUri",
uriInfo.getAbsolutePath().toString() + "?oslc.paging=true");
- if (results.size() > limit) {
- results.remove(results.size() - 1);
+
+ Object nextPageAttr = httpServletRequest.getAttribute(Constants.NEXT_PAGE);
+
+ if (nextPageAttr != null) {
httpServletRequest.setAttribute("nextPageUri",
- uriInfo.getAbsolutePath().toString() + "?oslc.paging=true&amp;page=" + (page + 1));
+ uriInfo.getAbsolutePath().toString() + "?oslc.paging=true&amp;page=" + nextPageAttr);
}
ServiceProvider serviceProvider = ServiceProviderCatalogSingleton.getServiceProvider(httpServletRequest, productId);