It's all about the answers!

Ask a question

How to create iteration and add as a child to existing iteration using java client libraries.


Nikhil Raut (1114) | asked Mar 11, 11:34 p.m.

 I want to automate iteration creation process.

One answer



permanent link
Ralph Schoon (63.5k33646) | answered Mar 12, 5:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I found this code


    /*
     * Creates a new iteration with the given name, id, parent, and development
     * line. If the given parent is not null, it must be a working copy
     * because the newly created iteration will be added to it as a child.
     * Otherwise, the given development line must be a working copy because the
     * iteration will be added to it instead. The returned iteration is a working
     * copy which has not yet been saved.
     /
    protected IIteration createIteration(String name, String id, IIteration parent, IDevelopmentLine line)
            throws TeamRepositoryException {

    IProcessItemService processService = (IProcessItemService) ((ITeamRepository) line.getOrigin())
            .getClientLibrary(IProcessItemService.class);

    IIteration iteration = processService.createIteration();
    iteration.setName(name);
    iteration.setId(id);
    iteration.setDevelopmentLine(line);
    if (parent != null) {
        iteration.setParent(parent);
        List children = new ArrayList();
        IIterationHandle[] currents = parent.getChildren();
        for (int i = 0; i < currents.length; i++) {
            children.add(currents[i]);
        }
        children.add(iteration);
        parent.setChildren((IIterationHandle[]) children.toArray(new IIterationHandle[children.size()]));
    } else {
        List iterations = new ArrayList();
        IIterationHandle[] currents = line.getIterations();
        for (int i = 0; i < currents.length; i++) {
            iterations.add(currents[i]);
        }
        iterations.add(iteration);
        line.setIterations((IIterationHandle[]) iterations.toArray(new IIterationHandle[iterations.size()]));
    }
    return iteration;
}


</pre>
You have to make sure to have a workingcopy of the development line. You have to add all the process items that are changed to an array and finally save the items in that list. The order of items matter.
<pre>
private void createDevelopmentLines(IProjectArea projectArea, IProgressMonitor monitor) throws TeamRepositoryException {
    projectArea = (IProjectArea) projectArea.getWorkingCopy();
    ArrayList<iitem> modified = new ArrayList<iitem>();
    for (int i = 0; i &lt; 2050; i++) {
        String nameID = NAME_PREFIX + NAMEANDID + i;  
        IDevelopmentLine devLine = createDevelopmentLine(nameID, nameID, projectArea);
        modified.add(devLine);
        if(i==0) { // add the project area the first time
            modified.add(projectArea);
        }
    }
    IProcessItemService processService = (IProcessItemService) ((ITeamRepository) projectArea.getOrigin())
            .getClientLibrary(IProcessItemService.class);
    processService.save(modified.toArray(new IProcessItem[0]), monitor);
    System.out.println("Saved items (" + modified.size() + ")...");
}

</iitem></iitem>

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.