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
Accepted answer
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
Comments
Hi Pugazh, nice code, thanks for contributing.
Thanks!!
But, I can't apply to my code. :(
That's difficult.
There are some typos and minor errors in the code above. Try http://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/
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 !!!
4 other answers
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,
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
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.
Comments
I can also get the current iteration using the following code
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);