How do I find the original pathname of a moved file?
The code in https://jazz.net/forum/questions/94927 doesn't seem to work if the original directory the file was renamed from no longer exists.
e.g., start with directories foo and bar. Assume you have this file:
foo/fubar.java
Drag fubar.java from foo into bar to move it (IChange.REPARENT operation). Then delete the empty foo directory. Check these changes in. Your changeset will contain a delete of foo and a move of fubar.java.
Now using the API, with the IChangeSet you get the IChange for the file fubar.java and get beforeState(). With this returned object, I cannot find any way to get the old path, either using the IConfiguration for the component, or IVersionableManager.
IConfiguration.fetchCompleteItem() throws an ItemNotFoundException when you pass it the fileItem's getParent() returned object, claiming it doesn't exist in the configuration.
If you instead use IVersionableManager.fetchCompleteState() on the getParent() object, it claims that the state does not exist.
Is there no way to get the previous (deleted) path when you only have the IChange object of the file to use?
e.g., start with directories foo and bar. Assume you have this file:
foo/fubar.java
Drag fubar.java from foo into bar to move it (IChange.REPARENT operation). Then delete the empty foo directory. Check these changes in. Your changeset will contain a delete of foo and a move of fubar.java.
Now using the API, with the IChangeSet you get the IChange for the file fubar.java and get beforeState(). With this returned object, I cannot find any way to get the old path, either using the IConfiguration for the component, or IVersionableManager.
IConfiguration.fetchCompleteItem() throws an ItemNotFoundException when you pass it the fileItem's getParent() returned object, claiming it doesn't exist in the configuration.
If you instead use IVersionableManager.fetchCompleteState() on the getParent() object, it claims that the state does not exist.
Is there no way to get the previous (deleted) path when you only have the IChange object of the file to use?
2 answers
The short answer is "no".
The explanation is that a file-move change set in RTC does not remember the "previous" path (it only remembers the "previous" parent directory item-uuid, and the name the moved file had in that parent directory). When you accept a "file move" change set into a workspace, it moves that file from wherever that previous parent directory currently exist in that workspace. The previous pathname of a file in the workspace where the move change set was originally created is not considered interesting, and is not stored in the file-move change set.
The explanation is that a file-move change set in RTC does not remember the "previous" path (it only remembers the "previous" parent directory item-uuid, and the name the moved file had in that parent directory). When you accept a "file move" change set into a workspace, it moves that file from wherever that previous parent directory currently exist in that workspace. The previous pathname of a file in the workspace where the move change set was originally created is not considered interesting, and is not stored in the file-move change set.
Comments
Ok, finally figured it out. The quick-and-dirty gist of it is below. The goofy thing is that determineAncestorsInHistory() does not work on the beforeState versionable, only on its stateless parent object. And config.locateAncestors() does not work with either. Makes no sense to me, but it's working now, so thanks for the hints, Geoff.
IConfiguration config;
IChange change; // the move/rename change
IVersionable beforeState = versionableManager.fetchCompleteState( change.beforeState() );
IFolderHandle parent = beforeState.getParent();
try {
// for normal cases where the parent folder still exists...
config.fetchCompleteItem( parent, ... );
// etc.
}
catch (ItemNotFoundException e)
{
List<IVersionableHandle> fileAsList; // container for parent item
fileAsList.add( parent );
IAncestorReport ancestors = config.determineAncestorsInHistory( fileAsList, monitor );
// get the name/item pairs and cobble together the path from that
}
IConfiguration config;
IChange change; // the move/rename change
IVersionable beforeState = versionableManager.fetchCompleteState( change.beforeState() );
IFolderHandle parent = beforeState.getParent();
try {
// for normal cases where the parent folder still exists...
config.fetchCompleteItem( parent, ... );
// etc.
}
catch (ItemNotFoundException e)
{
List<IVersionableHandle> fileAsList; // container for parent item
fileAsList.add( parent );
IAncestorReport ancestors = config.determineAncestorsInHistory( fileAsList, monitor );
// get the name/item pairs and cobble together the path from that
}