{
backupManagerImpl.stopBackup(bch);
}
// restore
RepositoryBackupChainLog rblog = new RepositoryBackupChainLog(new File(bch.getLogFilePath()));
// clean existing repository
// list of components to clean
List<Backupable> backupable = new ArrayList<Backupable>();
//Create local copy of WorkspaceEntry for all workspaces
ArrayList<WorkspaceEntry> workspaceList = new ArrayList<WorkspaceEntry>();
workspaceList.addAll(rblog.getOriginalRepositoryEntry().getWorkspaceEntries());
// get all backupable components
for (WorkspaceEntry wEntry : workspaceList)
{
backupable.addAll(repositoryService.getRepository(rblog.getOriginalRepositoryEntry().getName())
.getWorkspaceContainer(wEntry.getName()).getComponentInstancesOfType(Backupable.class));
}
//close all session
for (WorkspaceEntry wEntry : workspaceList)
{
forceCloseSession(rblog.getOriginalRepositoryEntry().getName(), wEntry.getName());
}
//remove repository
repositoryService.removeRepository(rblog.getOriginalRepositoryEntry().getName());
// clean
for (Backupable component : backupable)
{
component.clean();
}
Map<String, BackupChainLog> workspacesMapping = new HashMap<String, BackupChainLog>();
Map<String, BackupChainLog> backups = new HashMap<String, BackupChainLog>();
for (String path : rblog.getWorkspaceBackupsInfo())
{
BackupChainLog bLog = new BackupChainLog(new File(path));
backups.put(bLog.getBackupConfig().getWorkspace(), bLog);
}
for (WorkspaceEntry wsEntry : rblog.getOriginalRepositoryEntry().getWorkspaceEntries())
{
workspacesMapping.put(wsEntry.getName(), backups.get(wsEntry.getName()));
}
JobRepositoryRestore job =
new JobRepositoryRestore(repositoryService, backupManagerImpl, rblog.getOriginalRepositoryEntry(),
workspacesMapping, rblog, false);
job.run();
assertEquals(JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL, job.getStateRestore());