It's all about the answers!

Ask a question

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


Sungyeun Hwang (537) | asked Oct 04 '12, 10:04 p.m.

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

Accepted answer


permanent link
pugazhenthi samidurai (26423942) | answered Oct 05 '12, 2:01 a.m.
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

Comments
Ralph Schoon commented Oct 05 '12, 4:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Hi Pugazh, nice code, thanks for contributing.


Sungyeun Hwang commented Oct 08 '12, 12:45 a.m.

Thanks!!

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

That's difficult.


Ralph Schoon commented Oct 08 '12, 1:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sungyeun Hwang commented Oct 08 '12, 4:09 a.m.

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,


Ralph Schoon commented Oct 08 '12, 5:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Sungyeun Hwang commented Oct 08 '12, 8:50 p.m.

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
Ralph Schoon (63.1k33646) | answered Oct 05 '12, 3:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Here is another helper I developed: http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/

Comments
Sungyeun Hwang commented Oct 08 '12, 4:09 a.m.

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
pugazhenthi samidurai (26423942) | answered Oct 08 '12, 5:03 a.m.
edited Oct 08 '12, 5:06 a.m.
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);
                }

            }
        }

    }



Comments
Sungyeun Hwang commented Oct 08 '12, 8:49 p.m.

Thanks!!!!

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

Thanks ,Pugazh !!!


permanent link
Surender Biyyala (403548) | answered Mar 10 '14, 4:35 a.m.
 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

Comments
Ralph Schoon commented Mar 10 '14, 4:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Surender Biyyala (403548) | answered Mar 10 '14, 4:55 a.m.
 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.

Comments
Surender Biyyala commented Mar 10 '14, 5:02 a.m.

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 


Ralph Schoon commented Mar 10 '14, 5:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 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.