Question

I have to check if a given Iteration comes under a given release.For example: Iteration 5.2 falls under Release PSI 5. I guess the only way to do this is to check if: IterationStartDate >= ReleaseStartDate && IterationEndDate<= ReleaseDate ( I am using Rally Java toolkit). My question is:

  1. How to convert the returned JsonElement (Iteration or Release date) into a date format that can be used to compare the dates? ( is it the SimpleDateFormat class? ). I have a Iteration and Release class that I am using to contain values.

Later on in the code, I want to do something like:

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

I tried it on my own and also looked it up but couldn't find a relevant answer. Thanks.

EDIT:

Is this the right way to compare?

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
Was it helpful?

Solution

Here is an example of querying iterations by release dates:

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();
            }
        }

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top