RepositoryEntry repositoryEntry =
repositoryService.getConfig().getRepositoryConfiguration(this.repositoryEntry.getName());
if (repositoryEntry == null)
{
throw new RepositoryRestoreExeption("Current repository configuration " + this.repositoryEntry.getName()
+ " did not found");
}
boolean isDefault =
repositoryService.getDefaultRepository().getConfiguration().getName().equals(repositoryEntry.getName());
//Create local copy of WorkspaceEntry for all workspaces
ArrayList<WorkspaceEntry> workspaceList = new ArrayList<WorkspaceEntry>();
workspaceList.addAll(repositoryEntry.getWorkspaceEntries());
//close all session
for (WorkspaceEntry wEntry : workspaceList)
{
forceCloseSession(repositoryEntry.getName(), wEntry.getName());
}
List<DataCleaner> dataCleaners = new ArrayList<DataCleaner>();
// collect all DataCleaners
for (WorkspaceEntry wEntry : workspaceList)
{
forceCloseSession(repositoryEntry.getName(), wEntry.getName());
List<Backupable> backupable =
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
.getComponentInstancesOfType(Backupable.class);
for (Backupable component : backupable)
{
dataCleaners.add(component.getDataCleaner());
}
}
//remove repository
if (isDefault)
{
((RepositoryServiceImpl)repositoryService).removeDefaultRepository();
}
else
{
repositoryService.removeRepository(repositoryEntry.getName());
}
//clean database
for (DataCleaner cleaner : dataCleaners)
{
cleaner.clean();
}
//clean index
for (WorkspaceEntry wEntry : workspaceList)
{
indexCleanHelper.removeWorkspaceIndex(wEntry,
repositoryEntry.getSystemWorkspaceName().equals(wEntry.getName()));
}
//clean value storage
for (WorkspaceEntry wEntry : workspaceList)
{
valueStorageCleanHelper.removeWorkspaceValueStorage(wEntry);
}
super.restoreRepository();
}
catch (Throwable t)
{
throw new RepositoryRestoreExeption("Repository " + repositoryEntry.getName() + " was not restored", t);
}
}