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

Fetching change set for work item

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?

0 votes



10 answers

Permanent link
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());

}

1 vote

Comments

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

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
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

0 votes


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

0 votes


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

0 votes

Comments

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


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

0 votes


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

0 votes


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

									

0 votes


Permanent link

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.

0 votes


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

0 votes


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

0 votes

Comments

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

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
× 10,938

Question asked: Feb 13 '08, 4:49 a.m.

Question was seen: 12,189 times

Last updated: Nov 08 '12, 7:05 p.m.

Confirmation Cancel Confirm