It's all about the answers!

Ask a question

create or delete iteration and timelines programatically


xx xx (461616) | asked Oct 17 '11, 9:54 a.m.
I want to create iteration and timelines programatically , is it possible? how can I do that?

Thanks.

Accepted answer


permanent link
Sapan Desai (5625) | answered Aug 14 '12, 4:21 p.m.
edited May 23 '13, 2:02 p.m. by Jared Burns (4.5k29)
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

Comments
Jared Burns commented May 23 '13, 2:03 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Sapan Desai (5625) | answered Aug 15 '12, 1:49 p.m.
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; 


permanent link
Lora Estey (7331920) | answered Aug 08 '12, 10:35 a.m.
Has anyone done this?

permanent link
Chris Goldthorpe (4287) | answered Aug 08 '12, 11:56 a.m.
JAZZ DEVELOPER
edited Aug 10 '12, 2:44 p.m. by Jared Burns (4.5k29)
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.

Comments
Rachid Halloul commented Aug 10 '12, 2:35 p.m.

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
Rachid Halloul (144) | answered Aug 10 '12, 2:36 p.m.
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)


permanent link
Rachid Halloul (144) | answered Aug 10 '12, 2:38 p.m.
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;
                                           
                    }
                }
             
            }

permanent link
Rachid Halloul (144) | answered Aug 15 '12, 12:33 p.m.
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 ?


                             

Comments
Sapan Desai commented Aug 15 '12, 1:40 p.m.

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
Sapan Desai (5625) | answered Aug 15 '12, 1:38 p.m.
 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.



permanent link
Rachid Halloul (144) | answered Aug 15 '12, 1:56 p.m.
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.

permanent link
Clement Liu (1.5k54349) | answered May 17 '14, 7:27 a.m.
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();
       
   
    }


    }

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.