RTC API confusion - defect creation - serverside
![]()
Hi guys
I'm trying to create a defect via the server RTC API through a deliver participant but I'm getting confused by the API once again. I'm running into problems setting the "filed against" field (At this point I can't tell whether it's a "Category" or an "Attribute" from RTC's perspective) The loop that prints the required "Attributes" that need to be set before you could save a given Item prints that "category" is one of the things that needs to be set (and not "filed against") luckily I happened to stumble upon getCategory which, according to the documentation, "Returns the 'filed against' category". Now what is it really returning a 'template' category or the actual category? (i.e will I have to use it to eventually call setCategory) or just call methods on it and those will eventually have a side effect of setting the category? I'm currently assuming the latter and have tried a couple of things: first of all I can't call setName on the category (which seems to be what I want) because it's deprecated. The documentation suggests that I try calling workItemService.renameCategory() in order to accomplish the same side effect (I think the function names are a bit misleading here in my humble opinion). Currently the call to renameCategory throws a "null arguement" exception with no other details and I can't find documentation for this method either, and I can't figure out which of the arguements it's complaining about (neither of them look null to me) unless it can't make sense out of "Scrum_area" and is unable to report the error more thoroughly. If I comment it out filedagainst.getName() returns "Unassigned" which would make sense if the Category's name represented the "filed against" attribute's (or Cateogry's) value. Collection<String> required_attributes = fWorkItemServer.findRequiredAttributes(newWorkItem, null, monitor); List list = new ArrayList<String>(required_attributes); for (String z : required_attributes){ System.out.println("required attribute: " + z); IAttribute attribute = fWorkItemServer.findAttribute(projectArea, z, monitor); if (attribute != null ){ System.out.println("Attribute isn't null"); } } ICategoryHandle filedagainsthandle = newWorkItem.getCategory(); if (filedagainsthandle!=null){ fWorkItemServer.renameCategory(filedagainsthandle, "Scrum_area", monitor); ICategory filedagainst = (ICategory) fItemService.fetchItem(filedagainsthandle, null); if (filedagainst!=null){ System.out.println("found Cateogry"); System.out.println(filedagainst.getName() + " - " + filedagainst.getHTMLDescription()); }else { System.out.println("found Category handle but not Cateogry"); } }else{ System.out.println("Category not found");} |
Accepted answer
![]()
Ok, you need to step back just a little
the system is 100% object oriented. and there are some basic rules..
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes I don't think it prints out the category name. but you could add that easily. I don't understand why you did the rename on the category.. that is an admin thing.. there are (usually) MANY categories in a project area that COULD be used.. getCategory() returns the one ALREADY assigned to this workitem, but as the workitem is NEW, that field is empty. you will want to use IWorkItemCommon findCategoriesOfProcessArea(IProcessAreaHandle processArea, ItemProfile<ICategory> profile, org.eclipse.core.runtime.IProgressMonitor monitor)to get the list of potential categories to use.. note that category is a team routing function. enumerations are also a list of items, the ID is whats needed, not the user readable name string. I suggest you learn to do this in a client app.. and then the API won't be so different.. just the service points client vs service Zaid Al-Khishman selected this answer as the correct answer
Comments "I don't understand why you did the rename on the category.. that is an admin thing.."
Ok, I think you are still stuck..
|
One other answer
![]()
Hi Sam, this is what was missing. Its a result of the answer that you pointed me to and this link https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation which I also dereferenced from your answer. Here is one approach to solve the problem. Scrum_area is the name of my project area and it can be chosen as a value for the 'Filed against' field in a defect .
ItemProfile<ICategory> profile = ICategory.DEFAULT_PROFILE; List<ICategory> listofCategories = fWorkItemServer.findCategories(projectArea, profile, monitor); for (ICategory cateogry : listofCategories){ if(cateogry.getName().equals("Scrum_area")){ newWorkItem.setCategory(cateogry); } } |