summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2012-07-23 15:05:11 (EDT)
committer Michael Fiedler2012-08-01 16:31:09 (EDT)
commita10b2889dcc3d6072a65f685258733f0de3d149e (patch)
tree4b1391bbfe882adc08c2d3923c8827c2b16a7018
parentb7d1ae42e0e505620275a380c6eddacca8873b43 (diff)
downloadorg.eclipse.lyo.docs-a10b2889dcc3d6072a65f685258733f0de3d149e.zip
org.eclipse.lyo.docs-a10b2889dcc3d6072a65f685258733f0de3d149e.tar.gz
org.eclipse.lyo.docs-a10b2889dcc3d6072a65f685258733f0de3d149e.tar.bz2
Bug 384760: Implement Use of oslc.orderByrefs/changes/25/6925/2
Change-Id: I1fe25d0ecad899b01d5eee2a3b3a4c8311729cbd Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/BugzillaManager.java85
-rw-r--r--OSLC4JBugzilla/src/main/java/org/eclipse/lyo/oslc4j/bugzilla/services/BugzillaChangeRequestService.java12
2 files changed, 90 insertions, 7 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 3d4a52a..c8706f8 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
@@ -47,10 +47,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.lyo.core.query.ComparisonTerm;
import org.eclipse.lyo.core.query.CompoundTerm;
import org.eclipse.lyo.core.query.InTerm;
+import org.eclipse.lyo.core.query.OrderByClause;
import org.eclipse.lyo.core.query.PName;
import org.eclipse.lyo.core.query.ParseException;
import org.eclipse.lyo.core.query.QueryUtils;
+import org.eclipse.lyo.core.query.ScopedSortTerm;
+import org.eclipse.lyo.core.query.SimpleSortTerm;
import org.eclipse.lyo.core.query.SimpleTerm;
+import org.eclipse.lyo.core.query.SortTerm;
+import org.eclipse.lyo.core.query.SortTerms;
import org.eclipse.lyo.core.query.Value;
import org.eclipse.lyo.core.query.WhereClause;
import org.eclipse.lyo.oslc4j.bugzilla.resources.BugzillaChangeRequest;
@@ -219,7 +224,11 @@ public class BugzillaManager implements ServletContextListener {
* @param limit
* @param oslcWhere
* @param prefixMap
- * @return The list of bugs, paged if necessary
+ * @param propMap
+ * @param orderBy
+ *
+ * @return The list of change requests, paged if necessary
+ *
* @throws IOException
* @throws ServletException
*/
@@ -230,7 +239,8 @@ public class BugzillaManager implements ServletContextListener {
int limit,
String oslcWhere,
Map<String, String> prefixMap,
- Map<String, Object> propMap) throws IOException, ServletException
+ Map<String, Object> propMap,
+ String orderBy) throws IOException, ServletException
{
List<BugzillaChangeRequest> results=new ArrayList<BugzillaChangeRequest>();
@@ -249,6 +259,16 @@ public class BugzillaManager implements ServletContextListener {
createBugSearch(page, limit, serviceProvider, oslcWhere, prefixMap, buffer);
+ if (orderBy != null && orderBy.length() != 0) {
+
+ OrderByClause orderByClause =
+ QueryUtils.parseOrderBy(orderBy, prefixMap);
+
+ buffer.append("&order=");
+
+ addSort(buffer, orderByClause, toplevelQueryProperties, true);
+ }
+
Credentials credentials = (Credentials)httpServletRequest.getSession().getAttribute(CredentialsFilter.CREDENTIALS_ATTRIBUTE);
BugzillaHttpClient client = new BugzillaHttpClient(getBugzillaUri(), credentials);
@@ -517,6 +537,65 @@ public class BugzillaManager implements ServletContextListener {
return index;
}
+ private static void addSort(final StringBuffer buffer,
+ final SortTerms orderByClause,
+ final Map<String, Object> queryProperties,
+ boolean first)
+ {
+ for (SortTerm term : orderByClause.children()) {
+
+ switch (term.type())
+ {
+ case SIMPLE:
+ break;
+ case SCOPED:
+ PName property = term.identifier();
+ Object field = queryProperties.get(property.namespace
+ + property.local);
+
+ if (field == null || field instanceof String) {
+ throw new WebApplicationException(
+ new UnsupportedOperationException(
+ "Unsupported oslc.orderBy scoped term sort term: "
+ + term), Status.BAD_REQUEST);
+ }
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> nestedQueryProperties = (Map<String, Object>) field;
+
+ addSort(buffer, ((ScopedSortTerm) term).sortTerms(),
+ nestedQueryProperties, first);
+
+ first = false;
+
+ continue;
+ }
+
+ PName property = term.identifier();
+ Object field = queryProperties.get(property.namespace
+ + property.local);
+
+ if (field == null || !(field instanceof String)) {
+ throw new WebApplicationException(
+ new UnsupportedOperationException(
+ "Unsupported oslc.orderBy property: "
+ + term), Status.BAD_REQUEST);
+ }
+
+ if (first) {
+ first = false;
+ } else {
+ buffer.append(',');
+ }
+
+ buffer.append((String)field);
+
+ if (! ((SimpleSortTerm)term).ascending()) {
+ buffer.append("+DESC");
+ }
+ }
+ }
+
private static void createInQuery(final StringBuffer buffer, int index,
InTerm inTerm,
Map<String, Object> queryProperties)
@@ -764,7 +843,7 @@ public class BugzillaManager implements ServletContextListener {
static {
toplevelQueryProperties.put(OslcConstants.DCTERMS_NAMESPACE + "identifier",
- "big_id");
+ "bug_id");
toplevelQueryProperties.put(OslcConstants.DCTERMS_NAMESPACE + "title",
"short_desc");
toplevelQueryProperties.put(Constants.CHANGE_MANAGEMENT_NAMESPACE + "status",
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 e9d1cab..4d1c0e6 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
@@ -123,6 +123,7 @@ public class BugzillaChangeRequestService
* @param select
* @param prefix
* @param pageString
+ * @param orderBy
* @return
* @throws IOException
* @throws ServletException
@@ -133,7 +134,8 @@ public class BugzillaChangeRequestService
@QueryParam("oslc.where") final String where,
@QueryParam("oslc.select") final String select,
@QueryParam("oslc.prefix") final String prefix,
- @QueryParam("page") final String pageString) throws IOException, ServletException
+ @QueryParam("page") final String pageString,
+ @QueryParam("oslc.orderBy") final String orderBy) throws IOException, ServletException
{
int page=0;
@@ -170,7 +172,7 @@ public class BugzillaChangeRequestService
final List<BugzillaChangeRequest> results =
BugzillaManager.getBugsByProduct(httpServletRequest, productId, page, limit,
where, prefixMap,
- propMap);
+ propMap, orderBy);
httpServletRequest.setAttribute(OSLC4JConstants.OSLC4J_SELECTED_PROPERTIES,
propMap);
@@ -230,6 +232,7 @@ public class BugzillaChangeRequestService
* @param where
* @param prefix
* @param pageString
+ * @param orderBy
* @return
* @throws ServletException
* @throws IOException
@@ -239,7 +242,8 @@ public class BugzillaChangeRequestService
public Response getHtmlCollection(@PathParam("productId") final String productId,
@QueryParam("oslc.where") final String where,
@QueryParam("oslc.prefix") final String prefix,
- @QueryParam("page") final String pageString) throws ServletException, IOException
+ @QueryParam("page") final String pageString,
+ @QueryParam("oslc.orderBy") final String orderBy) throws ServletException, IOException
{
int page=0;
@@ -272,7 +276,7 @@ public class BugzillaChangeRequestService
final List<BugzillaChangeRequest> results =
BugzillaManager.getBugsByProduct(httpServletRequest, productId, page, limit,
- where, prefixMap, propMap);
+ where, prefixMap, propMap, orderBy);
if (results != null) {
final String bugzillaUri = BugzillaManager.getBugzillaUri().toString();