Create iterations and sub iterations under timeline section of RTC prgramatically
Can anybody help me to create iterations under timeline using RTC JAVA API.
I want to handle it dynamically by reading mapping through XML
where it would maintain mapping for each iteration like below
<Workitems>
<Workitem>
<UId>12345</UId>
<Id>1</Id>
<Name>Testing iteration creation 10-09-2018</Name>
<StartDate>2018-09-10 10:30:00</StartDate>
<EndDate>2018-09-20 19:15:00</EndDate>
<Identifier>parent</Identifier>
<Level>timeline</Level>
<ChildWorkitems>
<Child level="parent">
<ChildName>Child_1</ChildName>
<ChildStartDate>2018-09-11 10:40:00</ChildStartDate>
<ChildEndDate>2018-09-15 15:40:00</ChildEndDate>
<Identifier>child1</Identifier>
<Level>parent</Level>
</Child>
<Child level="child1">
<ChildName>Child_2</ChildName>
<ChildStartDate>2018-09-16 12:00:00</ChildStartDate>
<ChildEndDate>2018-09-20 19:05:00</ChildEndDate>
<Identifier>child2</Identifier>
<Level>child1</Level>
</Child>
</ChildWorkitems>
</Workitem>
<Workitem>
<UId>12345</UId>
<Id>1</Id>
<Name>Testing iteration creation 21-09-2018</Name>
<StartDate>2018-09-21 10:30:00</StartDate>
<EndDate>2018-09-30 19:15:00</EndDate>
<Identifier>parent</Identifier>
<Level>timeline</Level>
<ChildWorkitems>
<Child level="parent">
<ChildName>Child_1</ChildName>
<ChildStartDate>2018-09-23 10:40:00</ChildStartDate>
<ChildEndDate>2018-09-27 18:40:00</ChildEndDate>
<Identifier>child1</Identifier>
<Level>parent</Level>
</Child>
<Child level="child1">
<ChildName>Child_2</ChildName>
<ChildStartDate>2018-09-28 12:00:00</ChildStartDate>
<ChildEndDate>2018-09-30 19:05:00</ChildEndDate>
<Identifier>child2</Identifier>
<Level>child1</Level>
</Child>
</ChildWorkitems>
</Workitem>
</Workitems>
So out of this I would want to get iteration hierarchy like below
---> Development Line(timeline level)
---> Iteration 1(parent level)
--->Child Iteration 1.1 (child1 level)
--->Child Iteration 1.1.1
---> Iteration 2(parent level)
--->Child Iteration 2.1 (child1 level)
--->Child Iteration 2.1.1
Thanks.
One answer
Here is the piece of code to create categories. Rest I hope you can build up according to your business needs. Most likely you need to have recursion for creating child categories to 'n' levels
Note: The below code to give you an idea of using the API.
private void createCategories(IProjectArea pa,
String[] categoriesFromConfigfile, ITeamRepository repo,
IProgressMonitor monitor) throws TeamRepositoryException {
String rtcCategoryName = "";
for (int i = 0; i <= categoriesFromConfigfile.length - 1; i++) {
List<String> splitsubCategory = new ArrayList<String>();
splitsubCategory.add(categoriesFromConfigfile[i]);
IWorkItemClient workItemClient = (IWorkItemClient) repo
.getClientLibrary(IWorkItemClient.class);
ICategoryHandle subCategoryHandle =workItemClient.findCategoryByNamePath(pa, splitsubCategory,monitor);
rtcCategoryName = categoriesFromConfigfile[i];
Pattern pattern = Pattern.compile("/");
Matcher matcher = pattern.matcher(rtcCategoryName);
if (matcher.find()) {
// Creation of Subcategories
if(splitsubCategory.size() > 1)
splitsubCategory.remove(1);
//System.out.println(iCategoryHandle.getItemId());
createSubCategory(subCategoryHandle,splitsubCategory.get(1), repo, monitor);
} else {
createCategory(pa, rtcCategoryName, repo, monitor);
}
}
}
public static ICategory createCategory(IProjectArea iProjectArea,
String categoryName, ITeamRepository repo, IProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItemClient workItemClient = (IWorkItemClient) repo
.getClientLibrary(IWorkItemClient.class);
ICategory category = workItemClient.createCategory(iProjectArea,
categoryName, monitor);
return workItemClient.saveCategory(category, monitor);
}
public static ICategory createSubCategory(ICategoryHandle parentCategory,
String categoryName, ITeamRepository repo, IProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItemClient workItemClient = (IWorkItemClient) repo
.getClientLibrary(IWorkItemClient.class);
ICategory category = workItemClient.createSubcategory(parentCategory,
categoryName, monitor);
return workItemClient.saveCategory(category, monitor);
}