Search in sources :

Example 6 with RestoreRequest

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);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with RestoreRequest

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());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) Test(org.junit.Test)

Example 8 with RestoreRequest

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;
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest)

Example 9 with RestoreRequest

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());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) Test(org.junit.Test)

Example 10 with RestoreRequest

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());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) Test(org.junit.Test)

Aggregations

RestoreRequest (org.xwiki.refactoring.job.RestoreRequest)12 Test (org.junit.Test)5 JobGroupPath (org.xwiki.job.JobGroupPath)2 XWikiException (com.xpn.xwiki.XWikiException)1 JobException (org.xwiki.job.JobException)1 JobExecutor (org.xwiki.job.JobExecutor)1 WikiReference (org.xwiki.model.reference.WikiReference)1 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)1 ScriptService (org.xwiki.script.service.ScriptService)1