Rally:检查Iteration是否属于Release

时间:2014-04-28 14:30:01

标签: rally

我必须检查给定的Iteration是否属于给定版本。例如:Iteration 5.2属于Release PSI 5.我想这样做的唯一方法是检查:IterationStartDate >= ReleaseStartDate && IterationEndDate<= ReleaseDate(我正在使用拉力赛Java工具包)。我的问题是:

  1. 如何将返回的JsonElement(迭代或发布日期)转换为可用于比较日期的日期格式? (它是SimpleDateFormat类吗?)。我有一个Iteration和Release类,用于包含值。
  2. 稍后在代码中,我想做类似的事情:

    if(iteration.startDate >= release.startDate && iteration.endDate <= release.endDate){
     System.out.println("The Iteration "+iteration.name+" falls under "+release.name);
    } 
    

    我自己尝试了,也查了一下,但找不到相关的答案。感谢。

    编辑:

    这是比较的正确方法吗?

    DateFormat iterationStartDate = new SimpleDateFormat(iter.StartDate()); //iter.StartDate() is of type String
    DateFormat iterationEndDate = new SimpleDateFormat(iter.EndDate());
    DateFormat releaseStartDate = new SimpleDateFormat(release.StartDate());
    DateFormat releaseEndDate = new SimpleDateFormat(release.EndDate());
    //then compare
    

1 个答案:

答案 0 :(得分:1)

以下是按发布日期查询迭代的示例:

public class FindIterationsByReleaseDate {

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


        String host = "https://rally1.rallydev.com";
            String username = "user@co.com";
            String password = "secret";
            String projectRef = "/project/1234";
            String applicationName = "RESTExampleFindReleasesByProject";

            RallyRestApi restApi = null;

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

                System.out.println(restApi.getWsapiVersion()); 

                QueryRequest  releaseRequest = new QueryRequest("Release");
                releaseRequest.setFetch(new Fetch("ReleaseStartDate", "ReleaseDate"));
                releaseRequest.setScopedDown(false);
                releaseRequest.setScopedUp(false);
                releaseRequest.setProject(projectRef);
                releaseRequest.setQueryFilter(new QueryFilter("Name", "=", "r1"));

                QueryResponse releaseQueryResponse = restApi.query(releaseRequest);

                JsonObject releaseJsonObject = releaseQueryResponse.getResults().get(0).getAsJsonObject();

                String rsd = releaseJsonObject.get("ReleaseStartDate").getAsString();
                String rd = releaseJsonObject.get("ReleaseDate").getAsString();

                QueryRequest  iterationRequest = new QueryRequest("Iteration");
                iterationRequest.setFetch(new Fetch("Name","StartDate","EndDate"));
                iterationRequest.setScopedDown(false);
                iterationRequest.setScopedUp(false);
                iterationRequest.setProject(projectRef);
                iterationRequest.setQueryFilter(new QueryFilter("StartDate", ">=", rsd).and(new QueryFilter("EndDate", "<=", rd)));

                QueryResponse iterationQueryResponse = restApi.query(iterationRequest);
                int numberOfIteraitons = iterationQueryResponse.getTotalResultCount();
                System.out.println(numberOfIteraitons);
                if(numberOfIteraitons >0){
                    for (int i=0;i<numberOfIteraitons;i++){
                        JsonObject iterationJsonObject = iterationQueryResponse.getResults().get(i).getAsJsonObject();
                        System.out.println(iterationJsonObject.get("Name"));
                    }
                }       
        }
        finally{
            if (restApi != null) {
                restApi.close();
            }
        }

    }
}