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

create or delete iteration and timelines programatically

I want to create iteration and timelines programatically , is it possible? how can I do that?

Thanks.

0 votes


Accepted answer

Permanent link
Not sure if this will be of any use to you anymore, but here is a sample code of how you can do it:

Create Development lines:

    IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
    projectArea = (IProjectArea) service.getMutableCopy(projectArea);  

    IDevelopmentLine developmentLine = (IDevelopmentLine) IDevelopmentLine.ITEM_TYPE.createItem();
    developmentLine.setId("156");
    developmentLine.setName("New Development Line");
    developmentLine.setProjectArea(projectArea);

    projectArea.addDevelopmentLine(developmentLine);

    service.save(new IProcessItem[] { projectArea, developmentLine }, monitor);

Create Iterations:

    IProcessItemService service= (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);

    IIteration newIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
    newIteration.setName("Ssdfecowsdfnd Iteration");
    newIteration.setId("193");

    IDevelopmentLine workingDevLine = (IDevelopmentLine) devLine.getWorkingCopy();
    workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());

    newIteration.setDevelopmentLine(workingDevLine);

    service.save(new IProcessItem[] { workingDevLine, newIteration }, monitor);
Jared Burns selected this answer as the correct answer

1 vote

Comments

Moderator note: I made a change to the code to eliminate an unnecessary line and reformatted the text to make it readable.


9 other answers

Permanent link
Here is the method to create child iteration for an iteration:

IProcessItemService service = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);

IDevelopmentLine workingDevLine = (IDevelopmentLine) createIterationDevLine.getWorkingCopy();

IIteration iterationCopy = (IIteration) newIteration.getWorkingCopy();

IIteration newSubIteration = (IIteration) IIteration.ITEM_TYPE.createItem();

newSubIteration.setName("Sub Iteration - 5");

newSubIteration.setId("185");

iterationCopy.addChild(newSubIteration);

newSubIteration.setParent(iterationCopy);

newSubIteration.setDevelopmentLine(workingDevLine);

service.save(new IProcessItem[] { newSubIteration, iterationCopy, workingDevLine }, monitor);

return newSubIteration; 

1 vote


Permanent link
Has anyone done this?

0 votes


Permanent link
You should be able to do that through our Java client library. Once you have a com.ibm.team.process.common.IProjectArea you can use methods getDevelopmentLines(), addDevelopmentLine() and  setDevelopmentLines() to manage the timelines. Iterations are children of timelines and there are methods in com.ibm.team.process.common.IDevelopmentLine to manage the iterations.

edit: Please note that our Java client library is available as-is and will change over time. It is not a supported API.

0 votes

Comments

I was able to get the Timeline using GetDevelopmentLines Method, but I'm still having an issue creating the iteration.

for (IIterationHandle iteration : line.getIterations()) { IIteration iter = (IIteration) repo.itemManager().fetchCompleteItem(iteration, 0, monitor); System.out.println("Iteration: " + iter.getName()); if (iter.getName().trim().equals(str)) { System.out.println("Iteration " + str + " already exists ............." ); }else { projectArea.set iter.getWorkingCopy();

                    projectArea.set
                    line.addIteration((IIterationHandle) iter.getItemHandle());
                    break;

                }
            }


Permanent link
Here is the error that I'm getting

Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException
    at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2060)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
    at com.ibm.team.process.internal.common.impl.DevelopmentLineImpl.setName(DevelopmentLineImpl.java:364)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
    at $Proxy14.setName(Unknown Source)
    at com.progress.iterationCreation.createIteration(iterationCreation.java:73)
    at com.progress.iterationCreation.main(iterationCreation.java:31)

0 votes


Permanent link
String str =  "myiteration"

 for (Iterator e = developmentLines.iterator(); e.hasNext();)
            {
                IDevelopmentLine line = (IDevelopmentLine) e.next();
                IIterationHandle[] iterationHandle =  line.getIterations() ;
                                
                for (IIterationHandle iteration : line.getIterations()) {
                    IIteration iter = (IIteration) repo.itemManager().fetchCompleteItem(iteration, 0, monitor);
                    System.out.println("Iteration: " + iter.getName());
                    if (iter.getName().trim().equals(str)) {
                        System.out.println("Iteration " + str + " already exists ............." );
                    }else {
                        iter.getWorkingCopy();
                        line.setName(str);
                           line.addIteration((IIterationHandle) iter.getItemHandle());
                        break;
                                           
                    }
                }
             
            }

0 votes


Permanent link
I'm trying to create a child iteration, here is my code

  newIteration.setId(str);
  newIteration.setName(str);
  newIteration.setParent(iter);
  workingDevLine.setName(iter.getName());
  workingDevLine.addIteration((IIterationHandle) newIteration.getItemHandle());
   newIteration.setDevelopmentLine(workingDevLine);
  service.save(new IProcessItem[]{workingDevLine, newIteration}, monitor);

but here is the error that I'm getting


Unable to login: Timeline 'Parent Backlog' contains iteration 'child iteration' which has a non-null parent iteration. Any idea ?


                             

0 votes

Comments

Hello Rachid,

I have a question on how do you get the id field for iteration. I am not able to find a method that will give me the last id, so that I can increment it by 1 and use it.

So I have to manually come up with an id to pass to the method : newIteration.setId(str).

Can you please help me with that?


Permanent link
 Hello Rachid,

What you are trying to do is to create a child iteration of an already existing iteration.  The method I suggested was for creating Iteration directly under a timeline.  It is something like this.

---> Development Line
       ---> Iteration 1
              --->Child Iteration 1.1 
              --->Child Iteration 1.2
       ---> Iteration 2
              --->Child Iteration 2.1 
              --->Child Iteration 2.2


The method I suggested will create iteration 1 or iteration 2.  But you cannot create any of the child iteration.  I will post another code in a few minutes for creating child iteration.


0 votes


Permanent link
Thanks Sapan for your help,  it looks like my issue was during service.save, I have made the change and I was able to create the child iteration.

0 votes


Permanent link
This is my program to create sub-iterations:

public static void createNewIterations(IDevelopmentLine line, Date lastIterationDate) 
    throws TeamRepositoryException, IOException {
    IDevelopmentLine devLineCopy = ((IDevelopmentLine)line.getWorkingCopy());
   
    IIteration newYearIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
    newYearIteration.setName(color + " (" + startEnd + ") " + year);
    newYearIteration.setId(color + " (" + startEnd + "e33ee20e3ifd " + year);
    newYearIteration.setHasDeliverable(true);
    newYearIteration.setDevelopmentLine(devLineCopy);
    devLineCopy.addIteration(newYearIteration);
    IProcessItem[] items = service.save(new IProcessItem[]{devLineCopy, newYearIteration}, null);
    IDevelopmentLine devLine2 = (IDevelopmentLine)teamRepository.itemManager().fetchCompleteItem(items[0].getItemHandle(), IItemManager.DEFAULT, null);
    IIteration trueNewYearIteration = (IIteration)teamRepository.itemManager().fetchCompleteItem(items[1].getItemHandle(), IItemManager.DEFAULT, null);
   
    IDevelopmentLine devLineCopy2 = ((IDevelopmentLine)devLine2.getWorkingCopy());
    IIteration newYearIterationCopy = (IIteration) trueNewYearIteration.getWorkingCopy();
   
    Date newWeekIterationStartDate = dateHelper.addDays(lastIterationDate,1);
    Date newWeekIterationEndDate = dateHelper.addDays(lastIterationDate,14);
   
   
    //Red 2014 I26 (12.22)
    int iterationNumber = 1;

    while(dateHelper.getYear(newWeekIterationStartDate) != Integer.parseInt(year) + 1){
   
    String weekIterationName = "";
    String monthAndDay = (newWeekIterationStartDate.getMonth() + 1) + "." + newWeekIterationStartDate.getDate();
    if(iterationNumber <= 9)
    weekIterationName = color + " " + year + " IIdei0" + iterationNumber + " (" + monthAndDay + ")";
    else
    weekIterationName = color + " " + year + " IIdei0" + iterationNumber + " (" + monthAndDay + ")";
   
    IIteration newWeekIteration = (IIteration) IIteration.ITEM_TYPE.createItem();
    newWeekIteration.setName(weekIterationName);
    newWeekIteration.setId(weekIterationName);
    newWeekIteration.setStartDate(newWeekIterationStartDate);
    newWeekIteration.setEndDate(newWeekIterationEndDate);
    newWeekIteration.setHasDeliverable(true);
   
    newYearIterationCopy.addChild(newWeekIteration);
    newWeekIteration.setParent(newYearIterationCopy);
    newWeekIteration.setDevelopmentLine(devLineCopy2);
   
   
    newWeekIterationStartDate = dateHelper.addDays(newWeekIterationEndDate, 1);
    newWeekIterationEndDate = dateHelper.addDays(newWeekIterationStartDate, 13);
    iterationNumber++;
   
        System.out.println(weekIterationName);
        IProcessItem[] iitems = service.save(new IProcessItem[]{devLineCopy2,newYearIterationCopy,newWeekIteration}, null);
       
        devLineCopy2 = (IDevelopmentLine)teamRepository.itemManager().fetchCompleteItem
        (iitems[0].getItemHandle(), IItemManager.DEFAULT, null).getWorkingCopy();
        newYearIterationCopy = (IIteration)teamRepository.itemManager().fetchCompleteItem
        (iitems[1].getItemHandle(), IItemManager.DEFAULT, null).getWorkingCopy();
       
   
    }


    }

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
× 10,936

Question asked: Oct 17 '11, 9:54 a.m.

Question was seen: 8,105 times

Last updated: Oct 08 '18, 7:33 a.m.

Confirmation Cancel Confirm