问题
In Rally Webservices API, if I want to traverse a Story hierarchy, it's necessary to do a query for the parent story, then grab the Children collection(s) off of the returned Stories, and then recursively query on each Child until the process reaches the Leaf node results.
Question - is there a handy way to do this without iterating, by using a single query in the Lookback API?
回答1:
This is one of the best features of the Lookback API.
Let's say you have this hierarchy:
- Story 444
- Story 555
- Story 666
- Defect 777 (via the Requirement field)
- Task 12
- Task 13
- Defect 777 (via the Requirement field)
- Story 666
- Story 888
- Story 555
The document for Task 12 would look like this:
{
ObjectID: 12,
_Type: "Task",
WorkProduct: 777,
_ItemHierarchy: [444, 555, 666, 777, 12],
...
}
So when you submit a query against a field with an array value (like _ItemHierarchy), it will match any member of the array.
To get everything that descend from 444 your find clause would include _ItemHierarchy: 444
. See how that matches the _ItemHierarchy
value for Task 12?
To get everything that descend from 333 your find clause would include _ItemHierarchy: 333
. This also matches on Task 12.
To get just the Stories that descend from 444 (all Stories) your find clause would include:
_ItemHierarchy: 444,
_Type: "HierarchicalRequirement"
To get just the leaf Stories just add the clause Children: null
.
The _ItemHierarchy also goes all the way up to PortfolioItems.
_ItemHierarchy
is indexed so these queries should be very efficient.
来源:https://stackoverflow.com/questions/10725244/lookback-api-find-all-leaf-node-stories-under-a-known-parent