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);
}
}
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());
}
}
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);
}
}
Aggregations