Search in sources :

Example 1 with RefactoringScriptService

use of org.xwiki.refactoring.script.RefactoringScriptService 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 RefactoringScriptService

use of org.xwiki.refactoring.script.RefactoringScriptService in project xwiki-platform by xwiki.

the class SaveAction method startCreateJob.

private Job startCreateJob(EntityReference entityReference, EditForm editForm) throws XWikiException {
    if (StringUtils.isBlank(editForm.getTemplate())) {
        // No template specified, nothing more to do.
        return null;
    }
    // If a template is set in the request, then this is a create action which needs to be handled by a create job,
    // but skipping the target document, which is now already saved by the save action.
    RefactoringScriptService refactoring = (RefactoringScriptService) Utils.getComponent(ScriptService.class, "refactoring");
    CreateRequest request = refactoring.createCreateRequest(Arrays.asList(entityReference));
    // Set the target document.
    request.setEntityReferences(Arrays.asList(entityReference));
    // Set the template to use.
    DocumentReferenceResolver<String> resolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
    EntityReference templateReference = resolver.resolve(editForm.getTemplate());
    request.setTemplateReference(templateReference);
    // We`ve already created and populated the fields of the target document, focus only on the remaining children
    // specified in the template.
    request.setSkippedEntities(Arrays.asList(entityReference));
    Job createJob = refactoring.create(request);
    if (createJob != null) {
        return createJob;
    } else {
        throw new XWikiException(String.format("Failed to schedule the create job for [%s]", entityReference), refactoring.getLastError());
    }
}
Also used : RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) ScriptService(org.xwiki.script.service.ScriptService) CreateRequest(org.xwiki.refactoring.job.CreateRequest) EntityReference(org.xwiki.model.reference.EntityReference) RefactoringScriptService(org.xwiki.refactoring.script.RefactoringScriptService) Job(org.xwiki.job.Job) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with RefactoringScriptService

use of org.xwiki.refactoring.script.RefactoringScriptService 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

XWikiException (com.xpn.xwiki.XWikiException)3 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)3 ScriptService (org.xwiki.script.service.ScriptService)3 JobException (org.xwiki.job.JobException)2 JobExecutor (org.xwiki.job.JobExecutor)2 Job (org.xwiki.job.Job)1 EntityReference (org.xwiki.model.reference.EntityReference)1 CreateRequest (org.xwiki.refactoring.job.CreateRequest)1 EntityRequest (org.xwiki.refactoring.job.EntityRequest)1 RestoreRequest (org.xwiki.refactoring.job.RestoreRequest)1