【问题标题】:How to get work item Id using link source Reference?如何使用链接源参考获取工作项 ID?
【发布时间】:2018-03-20 06:39:15
【问题描述】:

我正在使用下面的代码来获取工作项的父项和子项,并且我得到了链接引用,现在我想从对象中获取工作项 ID。请帮忙

IReference reference = linkManager.referenceFactory().createReferenceToItem(workItem 
                               .getItemHandle()); 
                               ILinkQueryPage page; 
                               ILinkQueryPage page1; 

                               page = linkManager.findLinksByTarget("com.ibm.team.workitem.linktype.parentworkitem", reference, monitor); 

                               ILinkCollection linkCollection = page.getLinks(); 


                               Collection childWI = linkCollection.getLinksById("com.ibm.team.workitem.linktype.parentworkitem");

                               System.out.println(childWI);

【问题讨论】:

  • 一个简单的 getId() 就足够了吗? (如rsjazz.wordpress.com/2012/09/20/…所示,代码中紧跟一句“如果另一端是工作项,则使用位置信息获取工作项。”)
  • @VonC 我们无法将链接投射到工作项中。
  • 你能解决这个链接吗?到工作项?如jazz.net/forum/questions/174327/…
  • @VonC 此代码未返回子或父工作项 ID。
  • 同意。我并不是要您按原样重用该代码。看看,从您自己的代码(其中包含 ILink 集合)中,您可以将所述 ILink 解析为您可以从中获取 Id 的工作项。

标签: java api rtc workitem


【解决方案1】:
ILinkCollection linkCollection = page.getLinks(); 
Collection childWI = linkCollection.getLinksById(...)

这意味着您有一个 ILink 集合。

作为seen here,很容易解析到WorkItem的链接:

for (ILink l : links) {
    IItemHandle linkHandle = (IItemHandle) l.getTargetRef().resolve();
    if (linkHandle instanceof IWorkItemHandle) {
        IWorkItem aWorkItem = (IWorkItem) teamRepository.itemManager().fetchCompleteItem(linkHandle, IItemManager.DEFAULT, monitor);
    }
}

每个WorkItem 都有一个getId() 方法来访问其ID。

【讨论】:

猜你喜欢
  • 2018-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-07
  • 1970-01-01
  • 2013-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多