It's all about the answers!

Ask a question

Obtaining subcategory using findCategories method


Tom Schmidt (645) | asked Jun 21 '12, 3:20 p.m.
edited Jun 21 '12, 3:27 p.m.
I am implementing an interface for users to open RTC work items.
One part of that interface allows users to select from a list of categories.

I use the following method to obtain that list:

----
public String[] getFiledAgainstList(String projectAreaString, IProgressMonitor monitor) throws TeamRepositoryException {
        String[] fileAgainstList = null;
        IProjectArea projectArea = null;
       
        try {
            projectArea = findProjectAreaByName(projectAreaString);
        } catch (Exception e) {
            MyPlugin.println("Unable to obtain projectArea in getFiledAgainstList:" + e + ":" + e.getMessage());
        }
       
        int i =0;
        try {
            ItemProfile<ICategory> profile= ICategory.DEFAULT_PROFILE.createExtension(ICategory.CATEGORY_ID);
   
            List<ICategory> enumeration = workItemClient.findCategories(projectArea, profile, monitor);
            fileAgainstList = new String[enumeration.size()];
            for (ICategory literal : enumeration) {
                fileAgainstList[i] = literal.getName();
                System.out.println(literal.getName());
                i++;
            }
        }
        catch (TeamRepositoryException e) {
            MyPlugin.println("Unable to obtain profile/enumeration in getFiledAgainstList:" + e + ":" + e.getMessage());
        }
        return fileAgainstList;
    }
-----

We have a set of categories with subcategories as follows.

C1
C2
C3
  C3.S1
  C3.S2
  C3.S3
C4
C5

The code above ends up producing a flat list:

C1
C2
C3
C3.S1
C3.S2
C3.S3
C4
C5

There is no way for me to associate C3.S1 to the C3 category.

In fact what I want is something like:
C1
C2
C3
C3/C3.S1
C3/C3.S2
C3/C3.S3
C4
C5

Otherwise, when I attempt to set the Category using the following method, I get a failure due to the category not being recognized by findCategoryByNamePath.


---
public void setWorkItemCategory(IWorkItem workItemCopy, IProjectArea projectArea, String categoryName) throws TeamRepositoryException
    {
        List<String> path= Arrays.asList(categoryName);
       
        ICategoryHandle category = null;
       
        try {
            category = getWorkItemClient().findCategoryByNamePath(projectArea, path, null);
        }
        catch (Exception e) {
            MyPlugin.println("RTCClient: setWorkItemCategory() - findCategoryByNamePath() failed for categoryName '"+ categoryName + "'!!" + e + ":" + e.getMessage());
            throw new TeamRepositoryException(e);
        }
       
        if (category == null)
        {
            throw new TeamRepositoryException("RTCClient: modifyWorkItemWorkingCopyWithoutSave() - findCategoryByNamePath() failed for categoryName '"+ categoryName + "'!!");
        }
       
        workItemCopy.setCategory(category);
    }
---

Is there any way to accomplish what I described above?


Comments
Tom Schmidt commented Jun 21 '12, 5:03 p.m.

I just found the method getHierarchicalName(), which appears to be deprecated. This method successfully obtains the format I was looking for (C2/C2.S2), however I'm still unable to subsequently set the category using that value. Based on other forum posts I've found it is likely due to some problem with '/' acting as a special character. I'm investigating that now.

Is there a non-deprecated method that can provide this value?


Tom Schmidt commented Jun 21 '12, 5:14 p.m.

RTCClient: setWorkItemCategory() - findCategoryByNamePath() failed for categoryName 'Back-End/TOBEY'!!org.eclipse.core.runtime.AssertionFailedException: assertion failed: :assertion failed:

2 answers



permanent link
Tom Schmidt (645) | answered Jun 21 '12, 5:21 p.m.
I was able to get this to work using the following minor change in my setWorkItemCategory method.

List<String> path= Arrays.asList(categoryName.split("/"));

I'm still looking for a non-deprecated way to obtain the full hierarchical category name if anyone can help with that.

Thanks.

permanent link
Renan Silva (11) | answered Mar 12 '15, 2:21 p.m.
Hello Tom Schmidt,

I think you already solved this problem, however for anyone who may need, here is a non-deprecated way to get the full hierarchical category name:

category.getCategoryId().getSubtreePattern();

Hope it helps.

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.