我正在尝试检索一个用户故事,包括其所有孩子的格式化ID,孩子们的孩子等...
我在检索RevisionHistory和Revisions方面遇到了问题,但ProjectScopeDown
属性有效。获得所有子树需要什么?
我的查询权限如下:
Request storyRequest = new Request("hierarchicalrequirement")
{
ProjectScopeUp = false,
ProjectScopeDown = true,
Fetch = new List<string>()
{
"Name",
"ObjectID",
"FormattedID",
"LastUpdateDate",
"Owner",
"Children",
"Description",
"RevisionHistory",
"Revisions"
},
Query = new Query("FormattedID", Query.Operator.Equals, _formattedID)
};
try
{
QueryResult queryStoryResults = m_rallyApi.Query(storyRequest);
if (queryStoryResults.Results.Count() > 0)
{
var myStory = queryStoryResults.Results.First();
userStory = new HierarchicalRequirement(myStory);
}
}
我可以通过检查DirectChildrenCount
并通过引用获取其他孩子来获得另一个孩子,但我想避免这种对Web服务的多次调用并将所有内容都放在一个查询中。
答案 0 :(得分:1)
这是一个快速示例,说明了根据Kyle的建议行走故事层次结构的递归查询:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;
namespace RestExample_QueryStoryHierarchy
{
class Program
{
static void Main(string[] args)
{
// This will be the FormattedID of the top-level story from which we want to start traversing down
string queryFormattedID = "US1";
Console.WriteLine("Starting to walk Story Tree at: " + queryFormattedID);
WalkTree.queryStoryTree(queryFormattedID);
Console.WriteLine("Finished walking the tree...");
Console.ReadKey();
}
}
// Class with Static function to recursively walk a story tree
static class WalkTree
{
public static void queryStoryTree(string inputFormattedID)
{
//Query for items
Request request = new Request("hierarchicalrequirement");
request.Fetch = new List<string>()
{
"Name",
"Description",
"FormattedID",
"Children"
};
// Query Rally for Story
request.Query = new Query("FormattedID", Query.Operator.Equals, inputFormattedID);
RallyRestApi restApi = rallyRestApiRef.getRestApi;
QueryResult queryResult = restApi.Query(request);
// Grab story Children and process each Child
foreach (var result in queryResult.Results)
{
Console.WriteLine(" Parent:");
Console.WriteLine(result["Name"]);
var resultChildren = result["Children"];
foreach (var resultChild in resultChildren)
{
string childFormattedID = resultChild["FormattedID"];
string childName = resultChild["Name"];
Console.WriteLine("Child/Grandchild Name:");
Console.WriteLine(childName);
// Call self recursively on Children to continue walking the tree
queryStoryTree(childFormattedID);
}
}
}
}
// Static class providing reference to Rally to other member Classes
static class rallyRestApiRef
{
private static String userName = "user@company.com";
private static String userPassword = "topsecret";
private static String serverUrl = "https://rally1.rallydev.com";
private static String wsapiVersion = "1.43";
private static RallyRestApi _restApi =
new RallyRestApi(userName,
userPassword,
serverUrl,
wsapiVersion);
public static RallyRestApi getRestApi
{
get { return _restApi; }
}
}
}
答案 1 :(得分:0)
出于服务器性能原因,层次结构仅限于WSAPI查询中的一个级别。像你这样的查询(包括所有修订历史记录和整个故事层次结构的修订版)都是超级昂贵请求的一个很好的例子。
你需要为每个故事递归树,抓住孩子,同时还有孩子可以阅读。