It's all about the answers!

Ask a question

Fetching change set for work item


Kim Herzig (2612) | asked Feb 13 '08, 4:49 a.m.
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?

10 answers



permanent link
Desh Sharma (4669) | answered Feb 01 '12, 10:30 a.m.
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());

}

Comments
S M commented Oct 23 '12, 5:16 a.m.

Hi, have you ever found a solution for this problem?


Tim Mok commented Oct 23 '12, 1:29 p.m.
JAZZ DEVELOPER

You may want to check the posts further down that seem to have solved the problem or provide sample code that solves the problem.


permanent link
Jean-Michel Lemieux (2.5k11) | answered Feb 13 '08, 8:48 p.m.
JAZZ DEVELOPER
kim wrote:
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

permanent link
Kim Herzig (2612) | answered Feb 14 '08, 5:15 a.m.
Thanks. That's exectly what I needed! Thank you

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.

permanent link
Kim Herzig (2612) | answered Feb 19 '08, 7:33 a.m.
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

Comments
praveen patidar commented Nov 08 '12, 7:05 p.m.

what type of object is change ? from where it is originated ?


permanent link
John Camelon (1.7k14) | answered Feb 20 '08, 11:28 p.m.
JAZZ DEVELOPER
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:
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

permanent link
Yehiel Glass (25548986) | answered Jan 02 '12, 12:37 p.m.
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!

permanent link
Kim Herzig (2612) | answered Jan 03 '12, 7:09 a.m.
Hi yehiel,

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!

		                                        

permanent link
SEC Servizi (97123860) | answered Jan 12 '12, 5:40 a.m.

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 Link type "com.ibm.team.filesystem.workitems.change_set" has not been defined in the "WorkItemLinkTypes.class"?
We found only these Link types mapped:
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 Link "Change Sets" has been defined in another "FooLinkTypes.class"?
Thanks in advance.

permanent link
Michele Pegoraro (1.8k14119103) | answered Jan 25 '12, 7:48 a.m.
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 Link type "com.ibm.team.filesystem.workitems.change_set" has not been defined in the "WorkItemLinkTypes.class"?
We found only these Link types mapped:
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 Link "Change Sets" has been defined in another "FooLinkTypes.class"?
Thanks in advance.

permanent link
Jason Fregien (58910) | answered Feb 06 '12, 1:51 p.m.
In 2.0.0.2 there is a one-off constant for this that I use:

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 Link type "com.ibm.team.filesystem.workitems.change_set" has not been defined in the "WorkItemLinkTypes.class"?
We found only these Link types mapped:
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 Link "Change Sets" has been defined in another "FooLinkTypes.class"?
Thanks in advance.

Comments
SEC Servizi commented Oct 19 '12, 10:03 a.m.

Thanks Jason, that is the class we was looking for.

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.