It's all about the answers!

Ask a question

How to fetch workitem Approvals through Jazz API


0
1
Kelvin Lui (51299) | asked Jan 19 '12, 11:31 a.m.
Hi,

I developed a java client to retrieve a workitem base on several criteria.

Now I tried to retrieve the Approvals associated with this workitem and retrieve the Reviewer/submitter of the Approvals:

IApprovals approvals = searchWorkItem.getApprovals();
java.util.List<IApproval> approval = approvals.getContents() ;

From the JavaDoc the object com.ibm.team.workitem.common.model.IApprovals has the following method:

IContributorHandle getApprover() -> Returns the contributor that is asked for approval.
IApprovalDescriptor getDescriptor() -> Returns the approval descriptor this approval belongs to.

I tried to retrieve both IContributorHandle and IApprovalDescriptor objects but have no luck here.

Could someone please help here?

Thanks.

13 answers



permanent link
Kelvin Lui (51299) | answered Mar 13 '12, 11:15 a.m.
Thanks. I think my question is regarding on this method:

findLinksByTarget(java.lang.String[] linkTypeIds, IReference target, IProgressMonitor monitor)

From the sample code :
linkManager.findLinksByTarget("com.ibm.team.filesystem.workitems.change_set", workItemReference, monitor);

The target is set to com.ibm.team.filesystem.workitems.change_set. The method returns the link of the changeset associated with the workitem.

My question is if I want to retrieve the link of the related worktitem assoicated to the original workitem (parent, children, related, etc), I would expect we have to set the target to one of the following:

public static final String RELATED_WORK_ITEM= "com.ibm.team.workitem.linktype.relatedworkitem"; //$NON-NLS-1$
public static final String DUPLICATE_WORK_ITEM= "com.ibm.team.workitem.linktype.duplicateworkitem"; //$NON-NLS-1$
public static final String COPIED_WORK_ITEM= "com.ibm.team.workitem.linktype.copiedworkitem"; //$NON-NLS-1$
public static final String RELATED_ARTIFACT= "com.ibm.team.workitem.linktype.relatedartifact"; //$NON-NLS-1$
public static final String ATTACHMENT= "com.ibm.team.workitem.linktype.attachment"; //$NON-NLS-1$
public static final String BLOCKS_WORK_ITEM= "com.ibm.team.workitem.linktype.blocksworkitem"; //$NON-NLS-1$
public static final String PARENT_WORK_ITEM= "com.ibm.team.workitem.linktype.parentworkitem"; //$NON-NLS-1$


Thanks.





I'm not sure I understand the question:
> If my assumption is correct what would be the link type name, which returns the ILink objects.

The ILinkManager.find* methods can be used to find any kind of links between two items. ILink is the type of object returned in all cases. An ILink represents a link between a source reference and a target reference, where a reference (IReference) may be either an item reference (item handle) to an item in the same repostiory, or an URI reference (arbitrary URL, sometimes used to refer to items in other repositories).

In the case of the "com.ibm.team.filesystem.workitems.change_set" link type id, the source reference is a change set handle (IChangeSetHandle) and the target is a work item handle (IWorkItemHandle).

To search for change sets associated with a given work item, you'd use findLinksByTarget. To search for work items associated with a given change set, you'd use findLinksBySource.

To get the resulting item handles from the ILinks in the result, use:

IReference ref = link.getSourceReference(); // or getTargetReference()
if (ref.isItemReference()) {
IItemReference itemRef = (IItemReference) ref;
IItemHandle itemHandle = itemRef.getReferencedItem();
}


Then cast the itemHandle down to IChangeSetHandle or IWorkItemHandle as appropriate.

permanent link
Kelvin Lui (51299) | answered Mar 13 '12, 3:28 p.m.
Nick,

I tried to run the following code.

By running in the debug mode:

There is an object returned by this method:
linkQueryPage = linkManager.findLinksByTarget("com.ibm.team.workitem.common.model.WorkItemLinkTypes.RELATED_WORK_ITEM", workItemReference, monitor);

Now when the code proceeds on this method it returns null.
ILinkCollection linkCollection = linkQueryPage.getAllLinksFromHereOn();

There are two different workitems (APAR workitem 54, APAR subTask 55) and I set the Related link between 54 and 55.

Any advise?








public void getRelatedWorkItem(IWorkItem workItem, IProgressMonitor monitor) throws TeamRepositoryException{

System.out.println("getRelatedWorkItem starts");
ILinkManager linkManager = (ILinkManager) teamRepository.getClientLibrary(ILinkManager.class);
IReferenceFactory referenceFactory = linkManager.referenceFactory();
IReference workItemReference = referenceFactory.createReferenceToItem(workItem.getItemHandle());


//Find all ILinks which attach a change set to the work item.
ILinkQueryPage linkQueryPage = null;
try {

linkQueryPage = linkManager.findLinksByTarget("com.ibm.team.workitem.common.model.WorkItemLinkTypes.RELATED_WORK_ITEM", workItemReference, monitor);
} catch (TeamRepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ILinkCollection linkCollection = linkQueryPage.getAllLinksFromHereOn();

//Put the ILinks in a list.
List<ILink> linksById = (List<ILink>)linkCollection.getLinksById("com.ibm.team.workitem.common.model.WorkItemLinkTypes.RELATED_WORK_ITEM");
List <IItemHandle> temp21 = new ArrayList<IItemHandle>();
for (ILink link : linksById){
IReference ref = link.getTargetRef();// or getTargetReference()
if (ref.isItemReference()) {
IItemReference itemRef = (IItemReference) ref;
IItemHandle itemHandle = itemRef.getReferencedItem();
IWorkItemHandle iworkitemHandle = (IWorkItemHandle)itemHandle;
temp21.add(0, iworkitemHandle);
}

IItemManager itemManager = teamRepository.itemManager();
IFetchResult temp100 = itemManager.fetchCompleteItemsPermissionAware(temp21, 0, monitor);
List <com> temp200 = null;
temp200 = temp100.getRetrievedItems();

if (temp200!=null){
System.out.println ("temp200 is not null");
for (int i=0; i < temp200.size(); i++){
com.ibm.team.workitem.common.model.IWorkItem _iworkItem = (com.ibm.team.workitem.common.model.IWorkItem) temp200.get(i);
System.out.println("_iworkItem: "+ _iworkItem.getId());
}
}
/* //List<ILink> changeSetLinks = linksById;
System.out.println("********************"+ linksById.size()); //ALWAYS getting size 0
List<IReference> changeSetReferences = new ArrayList<IReference>();
for (ILink link : changeSetLinks) {
IChangeSetHandle changeSetHandle = (IChangeSetHandle)link.getSourceRef().resolve();
ItemId<IChangeSet> changeSetItemId = ChangeSetUtil.getChangeSet(changeSetHandle);
*/
}
}

permanent link
Nick Edgar (6.5k711) | answered Mar 14 '12, 11:37 a.m.
JAZZ DEVELOPER
You're passing "com.ibm.team.workitem.common.model.WorkItemLinkTypes.RELATED_WORK_ITEM" as a literal string. Try using the constant instead:
com.ibm.team.workitem.common.model.WorkItemLinkTypes.RELATED_WORK_ITEM
(i.e. without quotes)

Its value is: "com.ibm.team.workitem.linktype.relatedworkitem".

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.