获取特定迭代下的所有任务(符合条件)?

时间:2014-06-23 07:23:05

标签: java rest iteration task rally

我想使用Rally Rest Toolkit java来获取2014-06-01和2014-06-08之间的所有迭代,然后在这些迭代下完成所有任务。我怎么办?

任何帮助都会很棒!非常感谢!

1 个答案:

答案 0 :(得分:1)

要获取属于特定日期的迭代任务,请使用以下语法:

taskRequest.setQueryFilter(new QueryFilter("Iteration.StartDate", ">=", "2014-06-01").and(new QueryFilter("Iteration.EndDate", "<=", "2014-06-08")));

并设置请求的工作空间:

taskRequest.setWorkspace("123456); //use your ObjectID

以便结果中包含具有相同开始日期和结束日期的子迭代(来自工作区中的所有项目)。

public static void main(String[] args) throws URISyntaxException, IOException {

    String host = "https://rally1.rallydev.com";
    String username = "user@co.com";
    String password = "psw";
    String workspaceRef = "/workspace/12352608129"; 
    String applicationName = "ExampleFindTasks";

    RallyRestApi restApi = null;

    try{
        restApi = new RallyRestApi(
                new URI(host),
                username,
                password);
        restApi.setApplicationName(applicationName); 

        QueryRequest taskRequest = new QueryRequest("Task");
        taskRequest.setFetch(new Fetch("Name","FormattedID","Iteration","Project"));
        taskRequest.setLimit(1000);
        taskRequest.setScopedDown(true);
        taskRequest.setScopedUp(false);
        taskRequest.setWorkspace(workspaceRef);
        taskRequest.setQueryFilter(
                new QueryFilter("Iteration.StartDate", ">=", "2014-06-01").and(
                        new QueryFilter("Iteration.EndDate", "<=", "2014-06-08")));

        QueryResponse taskQueryResponse = restApi.query(taskRequest);
        int numberOfResults = taskQueryResponse.getTotalResultCount();
        System.out.println(numberOfResults);

        if(numberOfResults > 0){
            for (int i=0;i<numberOfResults;i++){
                JsonObject taskJsonObject = taskQueryResponse.getResults().get(i).getAsJsonObject();
                System.out.println("Name: " + taskJsonObject.get("Name") + " " + "FormattedID: " +
                taskJsonObject.get("FormattedID"));
                JsonElement iteration = taskJsonObject.get("Iteration");
                JsonElement project = taskJsonObject.get("Project");
                try{
                    JsonObject iterationObject = iteration.getAsJsonObject().getAsJsonObject();
                    JsonObject projectObject = project.getAsJsonObject().getAsJsonObject();
                    System.out.println(iterationObject.get("Name"));
                    System.out.println(projectObject.get("Name"));
                }
                catch (java.lang.IllegalStateException ise) {
                    System.out.println("ise");
                }
            }
        }
    }
    finally{
        if (restApi != null) {
            restApi.close();
        }
    }
}