It's all about the answers!

Ask a question

Searching for change sets programatically.


Thomas Foyle (12) | asked Aug 10 '10, 7:13 a.m.
Hi everyone,

I'm trying to programmatically emulate the function in the RTC GUI where you can click Search -> Jazz Source Control -> Change sets... and then specify various criteria to search by, for example "Location", which lets you pick a stream/workspace/baseline to search in. Specifically, I want to search for all change sets in a particular stream.

I'm doing this by using IChangeSetSearchCriteria but I can't figure out how to properly set the Location criteria. I'm guessing it's something to do with IChangeSetSearchCriteria.setContext(IContextHandle). Am I correct? And if so, how would I specify that I want to find all change sets in "My Stream"? In other words, how do I relate a string name of a stream "My Stream" to an IContextHandle?

Thanks a lot,

Tom

/*

* Set change set search criteria.
*/
IChangeSetSearchCriteria changeSetSearchCriteria =
IChangeSetSearchCriteria.FACTORY.newInstance();

changeSetSearchCriteria.setContext(???);

List<IChangeSetHandle> changeSetHandles;

try {
/*
* Retrieve change set handles from RTC based on search criteria.
*/
changeSetHandles =
SCMPlatform.getWorkspaceManager(repository).findChangeSets
(changeSetSearchCriteria, Integer.MAX_VALUE, null);
} catch (TeamRepositoryException e) {
throw new RuntimeException(e);
}

5 answers



permanent link
Evan Hughes (2.4k1318) | answered Aug 10 '10, 9:42 a.m.
JAZZ DEVELOPER
I'm doing this by using IChangeSetSearchCriteria but I can't figure out how to properly set the Location criteria. I'm guessing it's something to do with IChangeSetSearchCriteria.setContext(IContextHandle). Am I correct?


Yes. Both IWorkspace and IBaseline implement IContextHandle, so you can search either of those with an IChangeSetSearchCriteria criteria.

And if so, how would I specify that I want to find all change sets in "My Stream"? In other words, how do I relate a string name of a stream "My Stream" to an IContextHandle?


That depends on how the user invokes your code. If they're running from within the UI, you should provide some kind of picker to find the stream to search in. If they're running on the command line, then you can take the UUID of the stream, create a handle from it and set the value in the search criteria (although you may want to fetch the stream first, since the user may have made a typo).

You could use an IWorkspaceSearchCriteria hardcoded to find a stream with the given name, but that will break if another stream with the same name is created, or if the stream name is changed.

e

permanent link
Tom Roach (2121) | answered Aug 10 '10, 10:20 a.m.
If I could ask another question on top of that then.

What's the process of going from a UUID to an ItemHandle?

Edit: Nevermind - found:
workspaceHandle = (IWorkspaceHandle)IWorkspace.ITEM_TYPE.createItemHandle(workspaceID, null);

permanent link
Kelvin Lui (51299) | answered Nov 25 '12, 10:33 p.m.
 I extended the sample code above and developed the code snippet to search whether  a changeset (associated with Workitem) has been delivered to a specific stream.

I have set two criterion in IChangeSetSearchCriteria:  setHandle(), setItem()

IWorkspaceManager iworkspaceManager = (IWorkspaceManager) rtcInternalAttribute.get_teamRepository()
.getClientLibrary(IWorkspaceManager.class);

// Find the stream
IWorkspaceHandle streamHandle = findStream(streamName, iworkspaceManager);
IWorkspaceConnection workspaceConnection = iworkspaceManager.getWorkspaceConnection(streamHandle, null);
// Target IChangeSetSearchCriteria for specific stream
IChangeSetSearchCriteria changesetCriteria = IChangeSetSearchCriteria.FACTORY.newInstance();
IContextHandle workspaceContexthandle = workspaceConnection.getContextHandle();
changesetCriteria.setContext(workspaceContexthandle);


I think  setItem(IVersionableHandle value)  allows someone to pass in the IVersionHandle to look for specific changeset.

However I am getting confused what to be passed on in the  setItem(IVersionableHandle value)  method.

From javadoc IChangeSet doesn't have any method to return IVersionableHandle object.   It seems IChange has several methods defined to return IVersionableHandle object (item(), beforeState(), afterState()).  

IChangeSet.changes() returns an list of IChange object.  However I am not sure the difference between IChangeSet and IChange, and as if what IVersionableHandle object I should pass in to the IChangeSetSearchCriteria.

Any help/advise is appreciated!!!

Thanks.








Comments
Chris McGee commented Nov 26 '12, 5:03 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

There is a new feature in RTC SCM (as of 4.0) that allows you to quickly find if a change set has been delivered to a stream. The feature is called "Locate Change Sets."

More details can be found here:
https://jazz.net/library/article/126#How_do_I_know_if_my_change_set_is_in_a_release


Chris McGee commented Nov 29 '12, 2:53 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Kelvin, can you post this as a new question in a new forum post? Things are starting to veer off-topic on this forum post.


permanent link
Kelvin Lui (51299) | answered Nov 26 '12, 2:34 p.m.
 I did a bit of further search.    In my scenario the IChangeSet object returns three IChange objects.

To print the toString(), item(), afterState(), and beforeState():

_ichange.item().getItemId() : [UUID _o3d8wMxcEeGiYpK76El5SQ]
 ichange.afterstate(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@7cde7cde (stateId: [UUID _Y04oxv0WEeGjaIuQWqAQog], itemId: [UUID _o3d8wMxcEeGiYpK76El5SQ], origin: <unset>, immutable: <unset>) 
ichange.beforeState(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@7900790 (stateId: [UUID _KmQ3BN2SEeGTPbdyGjjCIA], itemId: [UUID _o3d8wMxcEeGiYpK76El5SQ], origin: <unset>, immutable: <unset>) 
 _ichange.toString() : com.ibm.team.scm.common.internal.impl.ChangeImpl@51ec51ec (internalId: [UUID _Y2hnhf0WEeGjaIuQWqAQog]) (kind: 2, before: [UUID _KmQ3BN2SEeGTPbdyGjjCIA], after: [UUID _Y04oxv0WEeGjaIuQWqAQog])


_ichange.item().getItemId() : [UUID _OLHBsPN9EeCjgPTlO5cr8Q]
 ichange.afterstate(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@1f3c1f3c (stateId: [UUID _Y05P1f0WEeGjaIuQWqAQog], itemId: [UUID _OLHBsPN9EeCjgPTlO5cr8Q], origin: <unset>, immutable: <unset>) 
 ichange.beforeState(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@24842484 (stateId: [UUID _AbACRPEtEeGNo493VT-hlw], itemId: [UUID 
_OLHBsPN9EeCjgPTlO5cr8Q], origin: <unset>, immutable: <unset>) 
 _ichange.toString() : com.ibm.team.scm.common.internal.impl.ChangeImpl@184e184e (internalId: [UUID _Y2hnhv0WEeGjaIuQWqAQog]) (kind: 2, before: [UUID _AbACRPEtEeGNo493VT-hlw], after: [UUID _Y05P1f0WEeGjaIuQWqAQog])


_ichange.item().getItemId() : [UUID _7iSlYISYEeGD_Iq6etwH1g]
 ichange.afterstate(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@5ee85ee8 (stateId: [UUID _v5Yf5P2qEeGIk-E6VqGQng], itemId: [UUID _7iSlYISYEeGD_Iq6etwH1g], origin: <unset>, immutable: <unset>) 
 ichange.beforeState(): com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl@64306430 (stateId: [UUID _ANblNoShEeG6GuvuPqIj5g], itemId: [UUID _7iSlYISYEeGD_Iq6etwH1g], origin: <unset>, immutable: <unset>) 
 _ichange.toString() : com.ibm.team.scm.common.internal.impl.ChangeImpl@1c7c1c7c (internalId: [UUID _Y2hnh_0WEeGjaIuQWqAQog]) (kind: 2, before: [UUID _ANblNoShEeG6GuvuPqIj5g], after: [UUID _v5Yf5P2qEeGIk-E6VqGQng])


Now the ONLY common ID is the internalId which is _Y2hnh_0WEeGjaIuQWqAQog.  However this ID can't be retrieved through the IChange Object.  

Thanks.





Comments
Chris McGee commented Nov 29 '12, 2:53 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Again, can we move this out to a new forum post. It's veering off topic for this post.


permanent link
Kelvin Lui (51299) | answered Nov 29 '12, 11:11 p.m.
 sure. have done that.  Here is the url:  https://jazz.net/forum/questions/95487/programatically-locate-changeset-in-a-stream

Thanks.

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.