Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 I want to automate iteration creation process.

0 votes



One answer

Permanent link

 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>

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 7,495
× 1,325
× 1,220

Question asked: Mar 11, 11:34 p.m.

Question was seen: 753 times

Last updated: Mar 13, 1:04 a.m.

Confirmation Cancel Confirm