It's all about the answers!

Ask a question

Programmatically restore deleted file


Scott Pecnik (1336) | asked Sep 06 '12, 3:25 p.m.
 Hi Everyone,

Is it possible to programatically restore a deleted file?  The configuration object doesn't seem to have anything that supports files that it no longer knows about it.  Is it possible to find the versionableHandle and save it to the configuration?  What options do I have?

Thanks,
Scott

Comments
Scott Pecnik commented Sep 07 '12, 12:35 p.m. | edited Sep 10 '12, 5:26 p.m.

 I've been able to get a versionableHandle by using IConfiguration#determineAncestorsInHistory(), but that only gets me a versionableHandle.  If I want to save it to a configuration, I need a versionable.  Does anybody know how to grab a versionable of a previously deleted file?


Thanks,
Scott


Scott Pecnik commented Sep 07 '12, 4:25 p.m. | edited Sep 10 '12, 5:26 p.m.

 Switching gears a bit, attempting to grab the versionable using IVersionableManager#fetchCompleteState().  The problem is, my IVersionableHandle that I retrieve from determineAncestorsInHistory() does not have a stateID.  However, the javadoc for the IAncestorReport#getNameItemPairs() says that "all item handles within the ancestor report carry state ids."  I assume that my IVersionableHandle has no stateid because it's been deleted.


Still struggling here, any help on getting an IVersionable from a deleted item would be great.

Thanks,
Scott

One answer



permanent link
Heather Fraser-Dube (4512) | answered Sep 10 '12, 2:23 p.m.
JAZZ DEVELOPER
What you want to do is determine which of the versions you want to restore. One way to do this is determine the history of the item within the configuration and choose the version. IFlowNodeConnection#changeHistory(IComponentHandle) will get you an IChangeHistory which you can use to get the history of the versionable. The history will identify the change sets it was changed in.  The change set has changes with before/after and merge states to help you choose the right state to restore.

To restore the state, you just need to commit it in a change set. Using IWorkspaceConfiguration#IConfigurationOpFactory#revert will create an op to commit, or you can retrieve the full versionable and save it again using IConfigurationOpFactory#save to get the commit op. Going the save route will result in a new state id being generated.


Comments
Scott Pecnik commented Sep 10 '12, 3:01 p.m. | edited Sep 10 '12, 5:26 p.m.

Hi Heather,


Thanks so much for the response.  The problem I'm having is during the #revert() #save() stage, sorry for not articulating this well enough.  I'm grabbing the IVersionableHandle a little differently than you describe, via IChangeSetSearchCritera (I don't think this matters, however).

Once I have the IVersionableHandle that I want to revert to, when calling IWorkspaceConfiguration#IConfigurationOpFactory#revert(), I get an IllegalArguementException.  I tried going the save() route as well, but saving requires an IVersionable not an IVersionableHandle.  I've been unable to figure out how to get an IVersionable of an IVersionableHandle that has been deleted.  Doing a fetch from the configuration throws a "does not exist in configuration exception".

Thanks in advance,
Scott


Heather Fraser-Dube commented Sep 10 '12, 4:01 p.m. | edited Sep 10 '12, 4:02 p.m.
JAZZ DEVELOPER

Hi Scott

If you are using IChangeSetSearchCriteria, not a problem. Once you have picked the change set that has a reference to the version you want restored, retrieve the IChangeSet using IItemManager. IChangeSet#changes() will provide a list of all the versionables changed in the change set. Iterate to find the IChange for your versionable. Get the versionable state handle from IChange#beforeState() IChange#afterState() or IChange#mergeStates() (which you pick depends on which version you are picking).

You can use IConfigurationOpFactory#revert on that handle. The parent folder must still be in the configuration. If thats not the case, then you can retrieve the full versionable (using IVersionableManager), create a working copy, set a different parent and use IConfigurationOpFactory#save.

  • Heather

ps. You may want to use the comment link rather than adding new answers to your question.


Scott Pecnik commented Sep 10 '12, 5:29 p.m.

Hi Heather,

Thanks so much. I was not grabbing the versionableStateHandle. Instead, I was using IChange#item(). Grabbing a state handle has resolved my issue!

Scott

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.