1

我正在尝试检索一个用户故事,它的所有子项、子项的子项等的 formattedID...

我在检索 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 服务的多次调用,并将所有内容都放在一个查询中。

4

2 回答 2

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; }
        }
    }
}
于 2013-07-04T17:34:35.497 回答
0

出于服务器性能原因,层次结构仅限于 WSAPI 查询中的一级。像您这样的查询(包括所有修订历史和整个故事层次结构的修订)是超级昂贵请求的一个很好的例子。

您需要为每个故事沿树递归,在还有孩子要阅读的时候获取孩子。

于 2013-07-04T15:26:20.023 回答