use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method install.
/**
* Start the asynchronous installation process for an extension if the context document has programming rights.
*
* @param installRequest installation instructions
* @return the {@link Job} object which can be used to monitor the progress of the installation process, or
* {@code null} in case of failure
*/
public Job install(InstallRequest installRequest) {
setError(null);
// Force proper id
String extensionId = installRequest.getExtensions().iterator().next().getId();
String namespace = installRequest.getNamespaces() == null ? null : installRequest.getNamespaces().iterator().next();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId, namespace));
// Check rights
if (!this.authorization.hasAccess(Right.PROGRAM)) {
// Make sure only PR user can remove the right checking or change the users
setRightsProperties(installRequest);
}
// Remember current user
DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
if (currentUserReference != null) {
// We set the string value because the extension repository doesn't know how to serialize/parse an extension
// property whose value is a DocumentReference, and adding support for it requires considerable refactoring
// because ExtensionPropertySerializers are not components (they are currently hard-coded).
installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, currentUserReference.toString());
}
// Start job
Job job = null;
try {
job = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
} catch (JobException e) {
setError(e);
}
return job;
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class ExtensionManagerScriptService method createUpgradePlan.
/**
* Schedule the upgrade plan creation job.
*
* @param request the request to pass to pass to the upgrade plan job
* @return the {@link Job} object which can be used to monitor the progress of the upgrade plan creation process, or
* {@code null} in case of failure
*/
public Job createUpgradePlan(InstallRequest request) {
request.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, this.documentAccessBridge.getCurrentUserReference());
XWikiDocument callerDocument = getCallerDocument();
if (callerDocument != null) {
request.setProperty(AbstractExtensionValidator.PROPERTY_CALLERREFERENCE, callerDocument.getContentAuthorReference());
}
request.setProperty(AbstractExtensionValidator.PROPERTY_CHECKRIGHTS, true);
Job job = null;
try {
job = safe(this.jobExecutor.execute(UpgradePlanJob.JOBTYPE, request));
} catch (JobException e) {
setError(e);
}
return job;
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class OutdatedExtensionsDistributionStep method createRepairPlan.
private ExtensionPlan createRepairPlan(ExtensionId invalidExtension, String namespace) throws JobException, InterruptedException {
// Install the default UI
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, invalidExtension.getId(), namespace));
installRequest.addExtension(invalidExtension);
installRequest.addNamespace(namespace);
// Don't take any risk
installRequest.setUninstallAllowed(false);
// Indicate if it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(true);
installRequest.setInteractive(false);
// Set user to use as author (for example) to be superadmin
installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, XWikiRightService.SUPERADMIN_USER_FULLNAME);
Job job = this.jobExecutor.execute(UpgradePlanJob.JOBTYPE, installRequest);
job.join();
return (ExtensionPlan) job.getStatus();
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class DocumentsDeletingListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
Job job = (Job) source;
if (!job.getRequest().isInteractive()) {
logger.warn("XAR Extension Documents Deleting Listener will not check the document in non-interactive mode.");
return;
}
// Check if some pages belong to extensions
Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data;
ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities);
for (EntitySelection entitySelection : concernedEntities.values()) {
if (entitySelection.getEntityReference() instanceof DocumentReference) {
checkIfPageBelongToExtensions(entitySelection, question);
}
}
// Ask a confirmation to the user if some pages belong to extensions
if (!question.getExtensions().isEmpty()) {
// Conservative choice: we let the user enable the pages to delete.
question.unselectAll();
try {
// The user can modify the question so it could disable some EntitySelection.
// We add a timeout because when a refactoring job is running, it prevents others to run.
// 5 minutes is probably enough for the user to decide if the process should go on.
boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES);
if (!ack) {
// Without any confirmation, we must cancel the operation.
String message = "The question has been asked, however no answer has been received.";
this.logger.warn(message);
CancelableEvent cancelableEvent = (CancelableEvent) event;
cancelableEvent.cancel(message);
}
} catch (InterruptedException e) {
this.logger.warn("Confirm question has been interrupted.");
CancelableEvent cancelableEvent = (CancelableEvent) event;
cancelableEvent.cancel("Question has been interrupted.");
}
}
}
use of org.xwiki.job.Job in project xwiki-platform by xwiki.
the class FlavorSearchJob method createNewStatus.
@Override
protected DefaultFlavorSearchStatus createNewStatus(FlavorSearchRequest request) {
Job currentJob = this.jobContext.getCurrentJob();
JobStatus currentJobStatus = currentJob != null ? currentJob.getStatus() : null;
return new DefaultFlavorSearchStatus(request, this.observationManager, this.loggerManager, this.foundFlavors, currentJobStatus);
}
Aggregations