edwin.greene
edwin.greene

Reputation: 139

Rally Rest Api: QueryFilter: Get defects by timestamp

Is there a way to use the QueryFilter to get defects updated since a timestamp? Something like this:

String timeStamp = "2012-08-24T19:10:09.154Z";
QueryRequest defectRequest = new QueryRequest("defect");
defectRequest.setFetch(new Fetch("LastUpdateDate"));
defectRequest.setQueryFilter(new QueryFilter("LastUpdateDate", ">", timeStamp);
QueryResponse projectDefects = rallyApi.query(defectRequest);

Upvotes: 3

Views: 3202

Answers (1)

osulehria
osulehria

Reputation: 751

The Rally Web Services API intro page has a couple of explanations of gotchas with writing complex queries (have a look at the Query Syntax and Object Collection Attributes and Queries sections). The Java version does handle chain expressions easily but it's a little hard to read. Here's a query that sorts out open defects since August 1st that have a high severity or priority:

String timeStamp = "2012-08-01T19:10:09.154Z";

Map<String, QueryFilter> filters = new HashMap<String, QueryFilter>();

filters.put("LastUpdateDate", new QueryFilter("LastUpdateDate", ">", timeStamp));
filters.put("State", new QueryFilter("State", "=", "Open"));
filters.put("Severity", new QueryFilter("Severity", "<=", "Major Problem"));
filters.put("Priority", new QueryFilter("Priority", "<=", "High Attention"));

// Evaluates to ((Severity <= Major Problem) OR (Priority <= High Attention)) AND ((LastUpdateDate > timeStamp) AND (State = Open))
QueryFilter complexFilter = filters.get("Severity").or(filters.get("Priority")).and(filters.get("LastUpdateDate").and(filters.get("State")));

A big gotcha is querying for attributes that are collections (like Tasks in User Stories). Chaining queries together will get you the wrong result. For example, if you're looking for user stories that have tasks that are both in progress AND blocked, the query will evaluate the expression as an OR statement. This happens because the query translates it to "find any task in the collection that has a blocked status and then find any task that's in progress." The query doesn't narrow the scope of the list after the first expression; each expression queries all of the tasks within the collection.

One way around this is to do one of the queries (let's say we get all tasks in-progress). Then, we filter that list to get all tasks that are blocked. After you get that filtered list, you can find out which User Story each of those tasks belong to.

References:

The Rally Web Services API linked above.

http://developer.rallydev.com/help/java-toolkit-rally-rest-api (I used the last example at the end of the page as a basis of creating the query filter above).

Upvotes: 5

Related Questions