Obtaining subcategory using findCategories method
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?
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
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
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: