Search in sources :

Example 31 with Job

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;
}
Also used : JobException(org.xwiki.job.JobException) UpgradePlanJob(org.xwiki.extension.job.internal.UpgradePlanJob) UninstallPlanJob(org.xwiki.extension.job.internal.UninstallPlanJob) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) InstallPlanJob(org.xwiki.extension.job.internal.InstallPlanJob) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 32 with 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;
}
Also used : JobException(org.xwiki.job.JobException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) UpgradePlanJob(org.xwiki.extension.job.internal.UpgradePlanJob) UninstallPlanJob(org.xwiki.extension.job.internal.UninstallPlanJob) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) InstallPlanJob(org.xwiki.extension.job.internal.InstallPlanJob) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob)

Example 33 with 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();
}
Also used : ExtensionPlan(org.xwiki.extension.job.plan.ExtensionPlan) InstallRequest(org.xwiki.extension.job.InstallRequest) Job(org.xwiki.job.Job) UpgradePlanJob(org.xwiki.extension.job.internal.UpgradePlanJob)

Example 34 with Job

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.");
        }
    }
}
Also used : EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionBreakingQuestion(org.xwiki.extension.xar.internal.delete.question.ExtensionBreakingQuestion) Job(org.xwiki.job.Job) Map(java.util.Map) CancelableEvent(org.xwiki.observation.event.CancelableEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 35 with Job

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);
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) AbstractInstallPlanJob(org.xwiki.extension.job.internal.AbstractInstallPlanJob) Job(org.xwiki.job.Job)

Aggregations

Job (org.xwiki.job.Job)41 Test (org.junit.Test)11 JobStatus (org.xwiki.job.event.status.JobStatus)10 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)8 InstallJob (org.xwiki.extension.job.internal.InstallJob)8 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)8 JobException (org.xwiki.job.JobException)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 InstallRequest (org.xwiki.extension.job.InstallRequest)7 UpgradePlanJob (org.xwiki.extension.job.internal.UpgradePlanJob)7 InstallPlanJob (org.xwiki.extension.job.internal.InstallPlanJob)6 UninstallPlanJob (org.xwiki.extension.job.internal.UninstallPlanJob)6 XWikiException (com.xpn.xwiki.XWikiException)5 LogEvent (org.xwiki.logging.event.LogEvent)5 InstallException (org.xwiki.extension.InstallException)4 UninstallException (org.xwiki.extension.UninstallException)4 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)4 EntityReference (org.xwiki.model.reference.EntityReference)4 WikiReference (org.xwiki.model.reference.WikiReference)4 IOException (java.io.IOException)3