It's all about the answers!

Ask a question

How to get FileItem from a FileHandle?


Nazia C (111) | asked Aug 03 '09, 1:30 p.m.
Hi Jazz Team,
I want to retrieve all file changes from a work item including the authors and the filenames. I have reached the stage where I can get the File IDs. How can I get the FileItem from the FileHandle to get the contributor and file names?
My code:

IWorkItemWorkingCopyManager workingCopyManager= this.wi_client.getWorkItemWorkingCopyManager();

IWorkItemHandle handle = (IWorkItemHandle)workitem.getItemHandle();
workingCopyManager.connectCurrent(handle, com.ibm.team.workitem.common.model.IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workingCopy= workingCopyManager.getWorkingCopy(handle);
IWorkItemReferences references = workingCopy.getReferences();
ILinkType linkType = ILinkTypeRegistry.INSTANCE.getLinkType(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID);
IEndPointDescriptor descriptor = linkType.getSourceEndPointDescriptor();
//References for each work item
List<IReference> iRefs = references.getReferences(descriptor);
for(IReference iRef : iRefs)
{

if(iRef.isItemReference())
{
//Getting a change set for each reference
IItemHandle changeSetHandle = ((IItemReference) iRef).getReferencedItem();
IChangeSet changeSet = (IChangeSet) this.itemManager.getItem(changeSetHandle);
//Get changes from change set
List<IChange> changes = changeSet.changes();
for(IChange change : changes)
{
//for each change, get the file (id, name and the contributor)
/*change.
IVersionable file = this.scmManager.getFileFromHandle(change.item());
String name = file.getName();
//String id = change.item().getItemId().getUuidValue();// file.getItemId().getUuidValue();*/
}
}



Thanks
Nac

One answer



permanent link
Andrew Hoo (1.0k1) | answered Aug 06 '09, 9:22 a.m.
JAZZ DEVELOPER
You can get the full state from:
(IFileItem)SCMPlatform.getWorkspaceManager(repo).versionableManager().fetchCompleteState(remoteHandle,
progressMonitor)

Note that the versionable handle should be the beforeState or afterState
of your IChange. Sometimes those fields are null (in the cases of a
change that shares a file, or a change that deletes a file).



On Mon, 03 Aug 2009 13:37:59 -0400, Nac
<naziakc> wrote:

Hi Jazz Team,
I want to retrieve all file changes from a work item including the
authors and the filenames. I have reached the stage where I can get
the File IDs. How can I get the FileItem from the FileHandle to get
the contributor and file names?
My code:

IWorkItemWorkingCopyManager workingCopyManager=
this.wi_client.getWorkItemWorkingCopyManager();

IWorkItemHandle handle =
(IWorkItemHandle)workitem.getItemHandle();
workingCopyManager.connectCurrent(handle,
com.ibm.team.workitem.common.model.IWorkItem.FULL_PROFILE, null);

WorkItemWorkingCopy workingCopy=
workingCopyManager.getWorkingCopy(handle);
IWorkItemReferences references =
workingCopy.getReferences();
ILinkType linkType =
ILinkTypeRegistry.INSTANCE.getLinkType(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID);
IEndPointDescriptor descriptor =
linkType.getSourceEndPointDescriptor();
//References for each work item
List<IReference> iRefs =
references.getReferences(descriptor);
for(IReference iRef : iRefs)
{

if(iRef.isItemReference())
{
//Getting a change set for each reference
IItemHandle changeSetHandle = ((IItemReference)
iRef).getReferencedItem();
IChangeSet changeSet = (IChangeSet)
this.itemManager.getItem(changeSetHandle);
//Get changes from change set
List<IChange> changes = changeSet.changes();
for(IChange change : changes)
{
//for each change, get the file (id, name and the
contributor)
/*change.
IVersionable file =
this.scmManager.getFileFromHandle(change.item());
String name = file.getName();
//String id =
change.item().getItemId().getUuidValue();//
file.getItemId().getUuidValue();*/
}
}



Thanks
Nac



--

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.