I'm trying to retrieve the history of a snapshot.
What is the correct way to get the full IFileItem/IFolder path
in the context of the recent changeset of a component baseline?
Using information from searching this forum and
the wordpress and SCM Lounge site's mentioned in this forum,
I've come up with the following method.
But it doesn't seem to work correctly.
What am I doing wrong?
<hr>
<h3>
Starting with a snapshot reference
</h3>
<hr>
<pre>
UUID: [_82Vvo-7ZEeCnCsCCLJyoMA]
NAME: [2011_10_04_22_41_07_685 TestBuildDef_20111004-1842]
</pre>
<hr>
<h3>
I get snapshot using
</h3>
<hr>
<pre>
1) From the string UUID get object UUID using
UUID uuid = UUID.valueOf(id)
2) From the UUID get handle using
IBaselineSetHandle snapshotHandle = (IBaselineSetHandle) IBaselineSet.ITEM_TYPE.createItemHandle(uuid, null)
3) From handle get instance
IBaselineSet snapshot = (IBaselineSet) itemManager.fetchCompleteItem(snapshotHandle, IItemManager.DEFAULT, monitor)
<br>
</pre>
<hr>
<h3>
I get a list of baselines using
</h3>
<hr>
<pre>
List<ibaselinehandle> baselineHandles = iBaselineSet.getBaselines()
</ibaselinehandle><br>
</pre>
<hr>
<h3>
Iterate over baselines using
</h3>
<hr>
<pre>
IBaselineConnection baselineConnection = workspaceManager.getBaselineConnection(baselineHandle, null)
IBaseline baseline = baselineConnection.getResolvedBaseline()
IHistoricBaselineIterator history = baselineConnection.getBaselinesInHistory(1, monitor)
IBaselineHandle previousBaselineHandle = history.getBaselines().get(0)
IBaseline previousBaseline = (IBaseline) itemManager.fetchCompleteItem(previousBaselineHandle, IItemManager.DEFAULT, monitor)
</pre>
<hr>
<h3>
I get a list of changeSets using
</h3>
<hr>
<pre>
IChangeHistory changeHistory = baselineConnection.changeHistory()
IConfiguration configuration = changeHistory.configuration()
List<IChangeHistoryEntryChange> recentChanges = changeHistory.getHistoryDescriptor(true, null).recent()
IChangeSetHandle changeSetHandle = iChangeHistoryEntryChange.changeSet();
IChangeSet changeSet = (IChangeSet) itemManager.fetchCompleteItem(changeSetHandle, IItemManager.DEFAULT, monitor);
<br>
</pre>
<hr>
<h3>
Iterate over changeSets using
</h3>
<hr>
<pre>
IChange change = iChangeSet.changes();
<br>
</pre>
<hr>
<h3>
Method 1
</h3>
<hr>
<hr>
<h3>
Iterate over changes using
</h3>
<hr>
<pre>
int kind = change.kind()
IVersionableHandle before = change.beforeState()
IVersionableHandle after = change.afterState()
based on kind use before, after or both to determine paths
<br>
</pre>
<hr>
<h3>
Determine paths using
</h3>
<hr>
<pre>
(this doesn't seem to always give a path or the right path for the change)
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(baselineHandle);
IVersionable item = scmService.fetchState(afer, null, null);
IAncestorReport[] reports = scmService.configurationLocateAncestors(configProvider, iVersionableHandles, null, null);
List<INameItemPair> nameItemPairs = reports[0].getNameItemPairs();
join pairs to build path
<br>
</pre>
<hr>
<h3>
Method 2
</h3>
<hr>
<hr>
<h3>
Get previous baseline configuration
</h3>
<hr>
<pre>
IBaselineConnection previousBaselineConnection = workspaceManager.getBaselineConnection(previousBaselineHandle, null)
IConfiguration previousConfiguration = previousBaselineConnection.configuration()
<br>
</pre>
<hr>
<h3>
Iterate over configuration tree to build up a configuration map to hold the Items/States of each node with there name and parent.
</h3>
<hr>
<pre>
if it has state I first try
iFolder = (IFolder) versionableManager.fetchCompleteState(handle, monitor);
if it only has itemId then I use
iFolder = (IFolder) previousConfiguration.fetchCompleteItem(handle, monitor);
<br>
</pre>
<hr>
<h3>
Iterate over changes using
</h3>
<hr>
<pre>
get configuration of changeHistory being iterated over and containing changeSet
int kind = change.kind()
IVersionableHandle before = change.beforeState()
IVersionableHandle after = change.afterState()
based on kind use before, after or both to determine paths
get parent handle for IVersionable
get IFolder for handle using configuration ( at this point I get ItemNotFound exceptions from various IFolderhandle to IFolder queries )
If I do not get an exception add current IFolder of IFileItem to my configuration item/state map
<br>
</pre>
<hr>
<h3>
Determine paths using
</h3>
<hr>
<pre>
(this doesn't seem to always give a path or the right path for the change)
Keep looking up parent and finding it in configuration map to get name building up path.
The problem with this is the error's in previous step cause items to be missing in this baseline configuration current state map
<br>
</pre>
Comments
https://github.ibm.com/awhawks/RTCSnapshots2git/tree/springJPA
The code is now on master branch at
https://github.ibm.com/awhawks/RTCSnapshots2git/tree/master