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

How to List all outgoing ChangeSets using plain Java API

 Hi,

How do I list all change sets in a given workspace which are waiting to be delivered (in the outgoing folder) using plain Java API?

This is the snippet of the code. The only issue here is the criteria. How to set it correctly?


  IChangeSetSearchCriteria criteria = IChangeSetSearchCriteria.FACTORY.newInstance();
  criteria.setOldestFirst(true);
  IProgressMonitor monitor;
  List<IChangeSetHandle> changeSets = 
  SCMPlatform.getWorkspaceManager(teamRepository).findChangeSets(criteria, Integer.MAX_VALUE, monitor);

Your assistance will be greatly appreciated.

Thanks,
Liora

0 votes


Accepted answer

Permanent link
I think you want to take a look at IWorkspaceConnection#compareTo for a comparison between your workspace and the target. You can specify the kind of comparison to do with the flags in WorkspaceComparisonFlags.

The result of the call is a IChangeHistorySyncReport where you can see the incoming and outgoing changes.

The code you've posted is for searching change sets. It doesn't include a context of where you want to search so depending on your criteria, it could return change sets that have been discarded and never delivered to any stream.
Liora Milbaum selected this answer as the correct answer

1 vote

Comments

Thanks Tim. I have started coding according to your suggestion. Now, I am stuck at initializing the workspaceHandle..


IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceHandle wh = ???.; (I have the name of the workspace)
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor); 

You can use IWorkspaceManager#findWorkspaces(IWorkspaceCriteria, int, IProgressMonitor) to find the workspace that you want. The criteria allows for searching by workspace name. You may want to add the owner to the criteria as well in case another user has the same workspace name.

The call will return a list of IWorkspaceHandle, which you can use to get the IWorkspaceConnection.


5 other answers

Permanent link
 I am on the last mile of the marathon:-)

My target is to deliver the change Sets one by one. The deliver method is not working.

IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceSearchCriteria criteria1 = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria1.setKind( IWorkspaceSearchCriteria.WORKSPACES );
criteria1.setExactName( INTEGRATION_WORKSPACE );
criteria1.setExactOwnerName(INTEGRATION_WORKSPACE_OWNER);
List<IWorkspaceHandle> workspaceHandles = wm.findWorkspaces(criteria1, Integer.MAX_VALUE, monitor);
IWorkspaceHandle wh = workspaceHandles.get( 0 );
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor);
IFlowTable flowTable = workspaceConnection.getFlowTable(); 
IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();
IFlowNodeHandle streamHandle = flowEntry.getFlowNode();
IWorkspaceConnection workspaceConnection1 = wm.getWorkspaceConnection((IWorkspaceHandle) streamHandle, monitor); 
IChangeHistorySyncReport changeHistorySyncReport = workspaceConnection.compareTo(workspaceConnection1, 
WorkspaceComparisonFlags.CHANGE_SET_COMPARISON_ONLY, 
Collections.EMPTY_LIST, monitor);
List<IChangeSetHandle> outgoingChangeSets = changeHistorySyncReport.outgoingChangeSets();
for (IChangeSetHandle changeSet : outgoingChangeSets) {
workspaceConnection.deliver(workspaceConnection1,changeHistorySyncReport ,Collections.EMPTY_LIST,Collections.singletonList(changeSet), monitor);
}

1 vote

Comments

Hello
Is there way to list all the files associated with these change set handlers ?

Follow the instructions in How to access change set file information.

Hello ,
Sorry for miscommunication. What I want is to have ChangeSet from ChangeSethandle to print the comments, owner  and work item ID for that.What API combination should I use for the Same ?


Permanent link
  Thanks Tim. Here is the code for the initialization part (I can't find how to add the owner criteria):-

IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);
IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria.setKind( IWorkspaceSearchCriteria.WORKSPACES );
criteria.setExactName( INTEGRATION_WORKSPACE );
List<IWorkspaceHandle> workspaceHandles = ((IItemQueryPage) wm.findWorkspaces(criteria, Integer.MAX_VALUE, monitor)).getItemHandles();
IWorkspaceHandle wh = workspaceHandles.get( 0 );
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(wh, monitor);

My next target is the find the steamConnection required by the compareTo method.

0 votes

Comments

IWorkspaceSearchCriteria allows you to set the partial or exact owner name.

For stream, you can do another search with a new IWorkspaceSearchCriteria and use #setKind to specify streams instead of workspaces.

Or, you can use the workspace IWorkspaceConnection to get the flow table and access the current accept flow. It will return the IFlowEntry, which has a IFlowHandle (it's the parent interface for IWorkspaceHandle).

The second method would be more reliable to find the stream since it checks the workspace's current flow target. However, the flow table may be a little confusing so feel free to ask questions about it. I only suggest the first method if you want to run a comparison between the workspace and a few different streams.

Found how to set the exact owner name. 


For the stream, I am still stuck. The output is WorkspaceHandle and not streamConnection. I am not sure, which method to use to find the streamConnection.

IWorkspaceSearchCriteria criteria2 = IWorkspaceSearchCriteria.FACTORY.newInstance();
criteria2.setKind( IWorkspaceSearchCriteria.STREAMS );
criteria2.setExactName( INTEGRATION_STREAM );
workspaceHandles = ((IItemQueryPage) wm.findWorkspaces(criteria2, Integer.MAX_VALUE, monitor)).getItemHandles();


Permanent link
 Tried also the second suggestions. This is what I have come up to.
I
IFlowTable flowTable = workspaceConnection.getFlowTable(); 
IFlowEntry flowEntry = flowTable.getCurrentDeliverFlow();
IChangeHistorySyncReport changeHistorySyncReport = workspaceConnection.compareTo(???, 
WorkspaceComparisonFlags.CHANGE_SET_COMPARISON_ONLY, 
Collections.EMPTY_LIST, monitor);

0 votes

Comments

Looks good.

Then IFlowEntry#getFlowNode() will get you the stream's handle. You can get the IWorkspaceConnection for that the same way as the workspace and use it for the first argument for IWorkspaceConnection#compareTo(..)


Permanent link
The deliver method is working. There was an issue with the preconditions. 

Tim, thanks for the personal attention.

Liora

0 votes


Permanent link
Hi Liora,

Could you please post the actual code of working Deliver method.

Regards,
Chethan

0 votes

Comments

 Few years passed :-) The code is no longer available to me.

:-) Bad luck to me.

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
× 1,202

Question asked: Oct 15 '12, 5:05 p.m.

Question was seen: 8,270 times

Last updated: Sep 07 '16, 7:18 p.m.

Confirmation Cancel Confirm