Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to fetch workitem Approvals through Jazz API

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.

1

0 votes



13 answers

Permanent link
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.

0 votes


Permanent link
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);
*/
}
}

0 votes


Permanent link
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".

0 votes

1–15 items
page 2of 1 pagesof 2 pages

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jan 19 '12, 11:31 a.m.

Question was seen: 11,460 times

Last updated: Jan 19 '12, 11:31 a.m.

Confirmation Cancel Confirm