我正在尝试在工作项目中实际设置“讨论”的值。
我设法设置了“描述”属性,但是当我尝试设置讨论时,我得到了空指针异常:
IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);
IProgressMonitor monitor = SysoutProgressMonitor.getMonitor();
IWorkItemClient service = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);
IAttribute discussionAttribute = service.findAttribute(projectArea, "discussion", monitor);//Here I got a null "discussionAttribute"?
wc.getWorkItem().setValue(discussionAttribute, "New Value for Discussion");
任何想法!
答案 0 :(得分:1)
//Here I got a null "discussionAttribute"?
Attribute discussionAttribute = service.findAttribute(projectArea, "discussion", monitor);
我怀疑“discussion
”不是有效的WorkItem属性ID。
尝试使用问题“Where can I find a list of IWorkItem
attributes”来查询工作项的所有属性,以便获取“discussion
”的正确属性名称(可能是“comments
”?)
使用
IItemManager.fetchCompleteItem
获取任何句柄的项目 这些物品带有实际信息;句柄基本上就像指针/ URL一样。例如:
IContributorHandle contributorHandle = ...
IContributor contributor = (IContributor) teamRepository.itemManager.fetchCompleteItem(contributorHandle, IItemManager.DEFAULT, null); // should really provide a progress monitor in last arg for progress / cancelaton
String name = contributor.getName();
那是客户端的。对于服务器端,使用IRepositoryItemService来获取项目。
在项目区域配置的属性中,我看到
“评论”:ID“com.ibm.team.workitem.attribute.comments”,但没有“讨论”。
在Jazz.net上,您会找到指向this discussion的链接,并提及名为“ internalComments
”的ID。
然后尝试:
Attribute discussionAttribute =
service.findAttribute(projectArea, "internalComments", monitor);
不要忘记保存修改后的工作项,如“Modify a WorkItem”
IDetailedStatus s = wc.save(null);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item",
s.getException());
}
答案 1 :(得分:1)
这是最终解决方案,它的工作原理:) 感谢VonC&萨姆。
IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);
IAttribute commentsAttr = findAttribute(repository, projectArea, "internalComments");
IComments comments= wc.getWorkItem().getComments();
IComment comment= comments.createComment( repository.loggedInContributor(),
XMLString.createFromPlainText( "Aloo from Mars"));
comments.append(comment);
wc.save(null);