Fetching change set for work item
10 answers
I am trying to do the same but I am not getting results
getChangeSets(repository, workItem, null);
Where repository = login(repositoryURI, userId, password); and
IWorkItem workItem = resolved.getItem();
public static void getChangeSets(ITeamRepository repository, IWorkItem workItem, IProgressMonitor monitor) throws TeamRepositoryException {
//Get an IReference to the work item.
ILinkManager linkManager = (ILinkManager) repository.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.filesystem.workitems.change_set", 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.filesystem.workitems.change_set");
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);
// changeSetReferences.add(link.getSourceRef());
}
getChangeSets(repository, workItem, null);
Where repository = login(repositoryURI, userId, password); and
IWorkItem workItem = resolved.getItem();
public static void getChangeSets(ITeamRepository repository, IWorkItem workItem, IProgressMonitor monitor) throws TeamRepositoryException {
//Get an IReference to the work item.
ILinkManager linkManager = (ILinkManager) repository.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.filesystem.workitems.change_set", 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.filesystem.workitems.change_set");
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);
// changeSetReferences.add(link.getSourceRef());
}
kim wrote:
If you have a set of ILinks in hand, then links of type
"com.ibm.team.filesystem.workitems.change_set" are change-set to work
item links. The source is the change-set item and the target the work
item. We changed the change-set item reference after beta 2, previously
it was a URI that could be resolved using the IItemManager. Now it's an
item.
Jean-Michel
Jazz Source Control Team
Hi all,
I am trying to fetch change sets for resolved work items.
So far I have the workItem and can fetch all kind of Links to other
WorkItems and URIs. But how do I get a change set. I was trying to
follow the steps of the WorkItemEditor but I couldn't figure it out.
Can anybody help?
If you have a set of ILinks in hand, then links of type
"com.ibm.team.filesystem.workitems.change_set" are change-set to work
item links. The source is the change-set item and the target the work
item. We changed the change-set item reference after beta 2, previously
it was a URI that could be resolved using the IItemManager. Now it's an
item.
Jean-Michel
Jazz Source Control Team
Thanks. That's exectly what I needed! Thank you
Cheers,
Kim
For all those people searching for direct code:
Cheers,
Kim
For all those people searching for direct code:
ILinkManager fLinkManager = (ILinkManager) _teamRepository.getClientLibrary(ILinkManager.class);
IReferenceFactory fReferenceFactory = fLinkManager.referenceFactory();
IReference reference = fReferenceFactory.createReferenceToItem(_workItem.getItemHandle());
ILinkQueryPage page = fLinkManager.findLinksByTarget("com.ibm.team.filesystem.workitems.change_set", reference, _monitor);
ILinkCollection linkCollection = page.getAllLinksFromHereOn();
Collection<ILink> links = linkCollection.getLinksById("com.ibm.team.filesystem.workitems.change_set");
*
Now that you have the correct links to change sets, you can use link.getSourceRef() to get the ChangeSet itself. It hope it helps.
Hi Jean-Michel,
I have another question closely connected to this topic.
Now, I managed to extract the IFileItemHandle from the IChangeSet.
Now, I want to get the path of this IFileItem(Handle). How this and more info for the file? I really can't find any help in the source code.
Thank you
Kim
I have another question closely connected to this topic.
Now, I managed to extract the IFileItemHandle from the IChangeSet.
IChangeSet changeSet = iter.next();
if(change.item() instanceof IFileItemHandle){
IFileItemHandle fileItemHandle = (IFileItemHandle)change.afterState();
try {
IFileItem fileItem = (IFileItem) SCMPlatform.getWorkspaceManager(item.getTeamRepository()).versionableManager().fetchCompleteState(fileItemHandle, null);
String a = fileItem.getContent().toString();
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
Now, I want to get the path of this IFileItem(Handle). How this and more info for the file? I really can't find any help in the source code.
Thank you
Kim
Hi Kim,
The path of a versionable state is relative to the configuration for
which you wish to interpret the state in. All the IVersionable item
itself knows is who its parent folder is, and what name it has with
respect to that parent.
The (full) paths you see in the TeamConcert UI are interpreted against
workspaces or other SCM artifacts from which we can derive a configuration.
JohnC
SCM Server
kim wrote:
The path of a versionable state is relative to the configuration for
which you wish to interpret the state in. All the IVersionable item
itself knows is who its parent folder is, and what name it has with
respect to that parent.
The (full) paths you see in the TeamConcert UI are interpreted against
workspaces or other SCM artifacts from which we can derive a configuration.
JohnC
SCM Server
kim wrote:
Hi Jean-Michel,
I have another question closely connected to this topic.
Now, I managed to extract the IFileItemHandle from the IChangeSet.
IChangeSet changeSet = iter.next();
if(change.item() instanceof IFileItemHandle){
IFileItemHandle fileItemHandle =
(IFileItemHandle)change.afterState();
try {
IFileItem fileItem = (IFileItem)
SCMPlatform.getWorkspaceManager(item.getTeamRepository()).versionableManager().fetchCompleteState(fileItemHandle,
null);
String a = fileItem.getContent().toString();
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
Now, I want to get the path of this IFileItem(Handle). How this and
more info for the file? I really can't find any help in the source
code.
Thank you
Kim
Hi yehiel,
Well, the whole code is a bit long but you get the _teamRepository very simply:
Code for getting the change sets:
Where the ChangeSetUtil is
What do you mean by complete them on workitem state?
//Kim
Well, the whole code is a bit long but you get the _teamRepository very simply:
IProjectAreaHandle projectAreaHandle = ProjectAreas.getInstance().getByName(projectAreaName);
ITeamRepository teamRepository = (ITeamRepository) projectAreaHandle.getOrigin();
Code for getting the change sets:
protected void fetchChangeSets(IWorkItem workItem,IProgressMonitor _monitor, ITeamRepository teamRepository){
try {
Collection<ILink> links = fetchLinksByTarget("com.ibm.team.filesystem.workitems.change_set", workItem, _monitor, teamRepository);
for (ILink link : links){
IChangeSetHandle changeSetHandle = (IChangeSetHandle)link.getSourceRef().resolve();
ItemId<IChangeSet> changeSetItemId = ChangeSetUtil.getChangeSet(changeSetHandle);
_changeSets.add(new HibernateChangeSet(RepoFetcher.fetchCurrent(teamRepository,
changeSetItemId, _monitor),teamRepository));
}
} catch (TeamRepositoryException e) {
logger.debug("TeamRepositoryException",e);
}catch (Throwable t){
logger.error("",t);
}
}
Where the ChangeSetUtil is
import com.ibm.team.filesystem.common.internal.util.ChangeSetUtil;
What do you mean by complete them on workitem state?
//Kim
Hi Kim,
Is it possible to get the change-set list out of workitem and complete them on workitem state change?
Am I right that your code run from the client side?
Can you write all the code? I don't know how to get the _teamRepository variable ..
Thanks!
If you have a set of ILinks in hand, then links of type
"com.ibm.team.filesystem.workitems.change_set" are change-set to work
item links. The source is the change-set item and the target the work
item.
Why the
We found only these
package com.ibm.team.workitem.common.model;
public class WorkItemLinkTypes {
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$
Or instead the
Thanks in advance.
This link type had been defined since 3.x version. For what I know it does not appear on 2.x version so it has to be set manually.
Michele.
Why theLink type "com.ibm.team.filesystem.workitems.change_set" has not been defined in the "WorkItemLinkTypes.class"?
We found only theseLink types mapped:
Or instead theLink "Change Sets" has been defined in another "Foo LinkTypes.class"?
Thanks in advance.
Michele.
If you have a set of ILinks in hand, then links of type
"com.ibm.team.filesystem.workitems.change_set" are change-set to work
item links. The source is the change-set item and the target the work
item.
Why the
We found only these
package com.ibm.team.workitem.common.model;
public class WorkItemLinkTypes {
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$
Or instead the
Thanks in advance.
In 2.0.0.2 there is a one-off constant for this that I use:
Why theLink type "com.ibm.team.filesystem.workitems.change_set" has not been defined in the "WorkItemLinkTypes.class"?
We found only theseLink types mapped:
Or instead theLink "Change Sets" has been defined in another "Foo LinkTypes.class"?
Thanks in advance.
com.ibm.team.filesystem.common.workitems.ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID
This link type had been defined since 3.x version. For what I know it does not appear on 2.x version so it has to be set manually.
Michele.
If you have a set of ILinks in hand, then links of type
"com.ibm.team.filesystem.workitems.change_set" are change-set to work
item links. The source is the change-set item and the target the work
item.
Why the
We found only these
package com.ibm.team.workitem.common.model;
public class WorkItemLinkTypes {
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$
Or instead the
Thanks in advance.