It's all about the answers!

Ask a question

Fetching also sub-categories from a project area

Lior Zimmerman (122) | asked May 08 '11, 6:20 a.m.
Hi Everyone,
I saw several examples demonstrating how to fetch available categories from RTC project area.
Problem is, the fetched categories are only the ones that are positioned as root categories - their children sub categories aren't fetched along with them.
I haven't noticed any way of doing that using the latest 2.0 SDK and the pure java API... If anyone is familiar with such a way, I would be thankful.


One answer

permanent link
Ajay Mallikarjunaiah (148310) | answered May 22 '14, 2:46 a.m.
Hi Mr.Lior Zimmerman,

There are no apis available for fetching sub categories for a given project area. Nevertheless, for a given category, we can fetch all its immediate sub categories.

1 public void getImmediateSubCategories(ICategory iCategory,
2            IProjectArea iProjectArea) throws TeamRepositoryException {
4       //initialise the workitem client
5         IWorkItemClient workItemClient = (IWorkItemClient) repo
6                .getClientLibrary(IWorkItemClient.class);
8        //get all categories of a given project area
9        List<ICategory> categories = workItemClient.findCategories(
10                iProjectArea, ICategory.FULL_PROFILE, monitor);
12        //printing all the immediate sub categories for the given category
13        for (ICategory iCategoryChild : categories) {
14            if (iCategoryChild.getParentId().equals(iCategory.getCategoryId())) {
15                System.out.println(iCategoryChild.getName());
16            }
17        }

Using this method, we can find all the sub categories of root categories and recursively all of them.

Note to be noted: API used in line 9 will fetch the categories which are active i.e unarchived. we cannot obtain archived categories using the same. I'm yet to find a way to list all archived categories.

Hope this suffice your query.

Your answer

Register or to post your answer.