Search in sources :

Example 1 with JobExecutor

use of org.xwiki.job.JobExecutor in project xwiki-platform by xwiki.

the class DeleteAction method startDeleteJob.

private Job startDeleteJob(EntityReference entityReference, XWikiContext context) throws XWikiException {
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    EntityRequest deleteRequest = refactoring.createDeleteRequest(Arrays.asList(entityReference));
    deleteRequest.setInteractive(isAsync(context.getRequest()));
    try {
        JobExecutor jobExecutor = Utils.getComponent(JobExecutor.class);
        return jobExecutor.execute(RefactoringJobs.DELETE, deleteRequest);
    } catch (JobException e) {
        throw new XWikiException(String.format("Failed to schedule the delete job for [%s]", entityReference), e);
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) JobException(org.xwiki.job.JobException) EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobExecutor(org.xwiki.job.JobExecutor) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with JobExecutor

use of org.xwiki.job.JobExecutor in project xwiki-platform by xwiki.

the class UndeleteActionTest method setUp.

@Before
public void setUp() throws Exception {
    mocker.registerMockComponent(CSRFToken.class);
    mocker.registerComponent(ScriptService.class, "refactoring", refactoringScriptService);
    Utils.setComponentManager(mocker);
    when(context.getRequest()).thenReturn(request);
    when(context.getWiki()).thenReturn(xwiki);
    when(xwiki.getRightService()).thenReturn(rightsService);
    when(context.getDoc()).thenReturn(document);
    when(document.getDocumentReference()).thenReturn(new DocumentReference("xwiki", "Main", "DeletedDocument"));
    jobExecutor = mocker.registerMockComponent(JobExecutor.class);
    when(jobExecutor.execute(anyString(), any())).thenReturn(job);
    jobRequest = mock(RestoreRequest.class);
    when(refactoringScriptService.createRestoreRequest(any(List.class))).thenReturn(jobRequest);
    when(refactoringScriptService.createRestoreRequest(anyString())).thenReturn(jobRequest);
}
Also used : JobExecutor(org.xwiki.job.JobExecutor) List(java.util.List) RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 3 with JobExecutor

use of org.xwiki.job.JobExecutor 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)

Aggregations

JobExecutor (org.xwiki.job.JobExecutor)3 XWikiException (com.xpn.xwiki.XWikiException)2 JobException (org.xwiki.job.JobException)2 RestoreRequest (org.xwiki.refactoring.job.RestoreRequest)2 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)2 ScriptService (org.xwiki.script.service.ScriptService)2 List (java.util.List)1 Before (org.junit.Before)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityRequest (org.xwiki.refactoring.job.EntityRequest)1