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

How to get and set the 'Iteration - target(ID)' using java API ?

Hi.

I'm trying to set an Iteration as current target but it did not work..

The focus are that

How to:
1) get each Iteration's name from project area ?
2) set the Iteration..

I'd like you to give the sample code to me.

I just couldn't do that by myself. :(

Please any ask..

Thanks for help,

Sungyeun

0 votes


Accepted answer

Permanent link
Hi Hwang,

The following functions will help you to read all the Iteration's from the project area.

it will return iteration names as String of Array.

public String[] getPlannedForList() {

        ArrayList<String> list = new ArrayList<String>();

        ArrayList<ArrayList<String>> listall = new ArrayList<ArrayList<String>>();

        IDevelopmentLineHandle[] developmentHandles = ((IProjectArea) projectArea)
                .getDevelopmentLines();

        IDevelopmentLine line = null;
        if (developmentHandles != null) {
            List developmentLines = null;
            try {
                developmentLines = teamRepository.itemManager()
                        .fetchCompleteItems(Arrays.asList(developmentHandles),
                                IItemManager.DEFAULT, null);
            } catch (TeamRepositoryException e1) {
               
                e1.printStackTrace();
            }

            for (Iterator e = developmentLines.iterator(); e.hasNext();) {
                line = (IDevelopmentLine) e.next();
                IIterationHandle[] iterationHandles = line.getIterations();
                list = PlannedForRecursive(iterationHandles);
                if (list != null)
                    listall.add(list);
            }

        }

        int size = listall.size();

        int i = 1;

        for (ArrayList<String> lis : listall) {
            if (lis != null) {
                for (String s : lis) {
                    if (s != null) {
                        i++;
                    }
                }
            }
        }

        String[] data = new String[i];
        data[0] = "Unassigned";
        i = 1;

        for (ArrayList<String> lis : listall) {
            if (lis != null) {
                for (String s : lis) {
                    if (s != null) {
                        data[i] = s;

                        i++;
                    }
                }
            }
        }

        return data;

    }

    public static ArrayList<String> PlannedForRecursive(
            IIterationHandle[] iterationHandles)
{

        ArrayList<String> interation_name = new ArrayList<String>();
        int i = 0;
        if (iterationHandles != null) {
            List iterationlines = null;
            try {

                iterationlines = teamRepository.itemManager()
                        .fetchCompleteItems(Arrays.asList(iterationHandles),
                                IItemManager.DEFAULT, null);
            } catch (TeamRepositoryException e) {
               
                e.printStackTrace();
            }
            IIteration iteration = null;
            for (Iterator e1 = iterationlines.iterator(); e1.hasNext();) {
                iteration = (IIteration) e1.next();
                if (iteration.getName() != null&&!iteration.isArchived())
                    interation_name.add(iteration.getName());
                i++;
                ArrayList<String> templist = null;
                if (iteration.getChildren() != null) {
                    templist = PlannedForRecursive(iteration.getChildren());

                }
                if (templist != null)
                    for (String s : templist) {
                        if (s != null) {
                            interation_name.add(s);
                            // System.out.println("planned for recursive :"+s);
                        }
                        // i++;
                    }

            }
        }
        return interation_name;
    }

code for set Target :

workItem.setTarget(getPlannedForLiteral("targetstring"));

Modify the above functions to get Literal value for a given target string.

Please ignore if its not relevant to your question.

Regards,
Pugazh S




Sungyeun Hwang selected this answer as the correct answer

3 votes

Comments

Hi Pugazh, nice code, thanks for contributing.

Thanks!!

But, I can't apply to my code. :(

That's difficult.

Hi. Ralph.

Thanks for your comment!!

But, I couldn't try to use that code(http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/). That's difficult.

I mean, I'd like use a code as like other attribute(Category, date etc..)

For example > for setCategory :

 List<ICategory> findCategories= workItemClient.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
            ICategory category = findCategories.get(5);
            workItemNew.setCategory(category);

Like this.. :(

But, 'setTarget ' that to setting 'IIterationHandle' is so difficult to me..

Please any help. :)

Thanks,

That is the only way I know of. I have mentioned the difference to the category in the blog post. I think you should really read it.

The code in the blog It is also the same principle as the code in this post. The blog provides simple helper classes that mimic the code to find a category. The API is as it is, so I can't help more.

Thanks!!

All of your Answer !

I got it for your help :)

I really thank you !!!

showing 5 of 6 show 1 more comments

4 other answers

Permanent link
Here is another helper I developed: http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/

0 votes

Comments

Hi. Ralph.

Thanks for your comment!!

But, I couldn't try to use that code(http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/) That's difficult.

I mean, I'd like use a code as like other attribute(Category, date etc..)

For example > for setCategory :

 List<ICategory> findCategories= workItemClient.findCategories(projectArea, ICategory.FULL_PROFILE, monitor);
            ICategory category = findCategories.get(5);
            workItemNew.setCategory(category);

Like this.. :(

But, 'setTarget ' that to setting 'IIterationHandle' is so difficult to me..

Please any help. :)

Thanks,


Permanent link
Hi Hwang,

check the below code to set Target:

workItem.setTarget(getIterationLiteral("Iteration String"));

Declare the below Variable as common to both function:

private  IIterationHandle listitehandle;

Functions to get Literal value for a given Value:

public IIterationHandle getIterationLiteral(String val)
            throws TeamRepositoryException {

        IDevelopmentLineHandle[] developmentHandles = ((IProjectArea) projectArea)
                .getDevelopmentLines();

        IDevelopmentLine line = null;
        if (developmentHandles != null) {
            List developmentLines = teamRepository.itemManager()
                    .fetchCompleteItems(Arrays.asList(developmentHandles),
                            IItemManager.DEFAULT, null);

            for (Iterator e = developmentLines.iterator(); e.hasNext();) {
                line = (IDevelopmentLine) e.next();
                IIterationHandle[] iterationHandles = line.getIterations();
                IterationRecursiveLiteral(iterationHandles, val);
            }

        }

        return listitehandle;
    }

    public  void IterationRecursiveLiteral(
            IIterationHandle[] iterationHandles, String val) {

        String interation_name = null;
        IIteration iteration = null;
        IIteration iteration_r = null;
        int i = 0;
        if (iterationHandles != null) {
            List iterationlines = null;

            try {
                iterationlines = teamRepository.itemManager()
                        .fetchCompleteItems(Arrays.asList(iterationHandles),
                                IItemManager.DEFAULT, null);
            } catch (TeamRepositoryException e) {
               
                e.printStackTrace();
            }
            for (Iterator e1 = iterationlines.iterator(); e1.hasNext();) {
                iteration = (IIteration) e1.next();
                if (iteration.getName().equalsIgnoreCase(val)) {
                    listitehandle = iteration;
                    return;
                }
                if (iteration.getChildren() != null) {
                    IterationRecursiveLiteral(iteration.getChildren(), val);
                }

            }
        }

    }


0 votes

Comments

Thanks!!!!

Finally, I got it due to your help !! :)

Thanks ,Pugazh !!!


Permanent link
 HI,

The code here talks about get the iteration on the client side .
could you please help me in getting the  all the iterations of a projectarea on the server side.

Thanks
Surender

0 votes

Comments

Most of the code e.g. also published here: https://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/ uses common API that is available on client as well as server.


Permanent link
 Ralph,

the following is the code I have as part of my implementation
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
     if (workItemServer == null)
       {
           workItemServer = getService(IWorkItemServer.class);
       }

     Object data = operation.getOperationData();
       
       if(data instanceof ISaveParameter) {
        IAuditable auditable = ((ISaveParameter)data).getNewState();

           if (auditable instanceof IWorkItem)
           {
               IWorkItem workItem = (IWorkItem)auditable;
               {
                       IAuditableCommon iac = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon();
                       WorkflowManager wfm = new WorkflowManager(iac);
                       IWorkflowInfo workflowInfo = wfm.getWorkflowInfo(workItem, monitor);
                       IDevelopmentLineHandle developmentHandle = ((IProjectArea) workItem.getProjectArea()).getProjectDevelopmentLine(); 
                                               
              /*        if (developmentHandles != null) { 
                           try { 
                               developmentLines = teamRepository.itemManager() 
                                       .fetchCompleteItems(Arrays.asList(developmentHandles), 
                                               IItemManager.DEFAULT, null); 
                           } catch (TeamRepositoryException e1) { 
                               e1.printStackTrace(); 
                           } 
       
       }*/
               }
           }
       }
       }
}

This code gets called when the user tries to save a work item and I need to find the current iteration and set it to one for the attribute.

how can i get the teamRepository Instance  here.

0 votes

Comments

I can also get the current iteration using the following code


IAuditableCommon iac = ((ISaveParameter)data).getSaveOperationParameter().getAuditableCommon();
                       IDevelopmentLine dev = iac.getDevelopmentLine(teamArea, monitor);
                       dev.getCurrentIteration();

But I dont know how to get the teamArea here i mean which API method is used to get the Team Area.

Please suggest me If Im going in awrong path.

Thanks
Surender 

http://rsjazz.wordpress.com/2013/06/26/attribute-customization-java-based-value-providers-conditions-and-validators/ shows an example for how to access that data from work items. e.g.

        IProcessAreaHandle processAreaHandle = workItemCommon.findProcessArea(workItem, monitor);
        IProcessArea processArea = (IProcessArea) workItemCommon.getAuditableCommon().resolveAuditable(processAreaHandle,
                ItemProfile.PROCESS_AREA_DEFAULT,monitor);

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

Question asked: Oct 04 '12, 10:04 p.m.

Question was seen: 9,180 times

Last updated: Sep 29 '16, 10:41 a.m.

Confirmation Cancel Confirm