use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class UndeleteAction method startRestoreJob.
private Job startRestoreJob(XWikiDeletedDocument deletedDocument, XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
RestoreRequest restoreRequest = null;
if (TRUE.equals(request.getParameter(INCLUDE_BATCH_PARAMETER))) {
// Restore the entire batch, including the current document.
String batchId = deletedDocument.getBatchId();
restoreRequest = refactoring.createRestoreRequest(batchId);
} else {
// Restore just the current document.
restoreRequest = refactoring.createRestoreRequest(Arrays.asList(deletedDocument.getId()));
}
restoreRequest.setInteractive(isAsync(request));
try {
JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
return jobExecutor.execute(RefactoringJobs.RESTORE, restoreRequest);
} catch (JobException e) {
throw new XWikiException(String.format("Failed to schedule the restore job for deleted document [%s], id [%s] of batch [%s]", deletedDocument.getFullName(), deletedDocument.getId(), deletedDocument.getBatchId()), e);
}
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method restoreBatch.
@Test
public void restoreBatch() throws Throwable {
long deletedDocumentId1 = 13;
long deletedDocumentId2 = 42;
String batchId = "abc123";
when(modelBridge.getDeletedDocumentIds(batchId)).thenReturn(Arrays.asList(deletedDocumentId1, deletedDocumentId2));
RestoreRequest request = createRequest();
request.setBatchId(batchId);
run(request);
verifyContext();
// Verify that the individual documents from the batch are restored.
verify(this.modelBridge).restoreDeletedDocument(deletedDocumentId1, request.isCheckRights());
verify(this.modelBridge).restoreDeletedDocument(deletedDocumentId2, request.isCheckRights());
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method createRequest.
private RestoreRequest createRequest() {
RestoreRequest request = new RestoreRequest();
request.setCheckRights(false);
request.setUserReference(userReference);
request.setWikiReference(wikiReference);
return request;
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method restoreSingleDocument.
@Test
public void restoreSingleDocument() throws Throwable {
long deletedDocumentId = 13;
RestoreRequest request = createRequest();
request.setDeletedDocumentIds(Arrays.asList(deletedDocumentId));
run(request);
verifyContext();
// Verify that the specified document is restored.
verify(this.modelBridge).restoreDeletedDocument(deletedDocumentId, request.isCheckRights());
}
use of org.xwiki.refactoring.job.RestoreRequest in project xwiki-platform by xwiki.
the class RestoreJobTest method failToExecuteIfNoWikiSpecified.
@Test
public void failToExecuteIfNoWikiSpecified() throws Throwable {
long deletedDocumentId = 13;
RestoreRequest request = createRequest();
request.setDeletedDocumentIds(Arrays.asList(deletedDocumentId));
request.setWikiReference(null);
try {
run(request);
} catch (IllegalArgumentException actual) {
// Verify that the job threw an exception.
Throwable expected = new IllegalArgumentException("No wiki reference was specified in the job request");
assertEquals(expected.getClass(), actual.getClass());
assertEquals(expected.getMessage(), actual.getMessage());
}
// Verify that the document is not restored.
verify(this.modelBridge, never()).restoreDeletedDocument(deletedDocumentId, request.isCheckRights());
}
Aggregations