Search in sources :

Example 11 with JobException

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

the class ExtensionManagerScriptService method uninstall.

/**
 * Adds a new job to the job queue to perform the given uninstall request.
 * <p>
 * This method requires programming rights.
 *
 * @param uninstallRequest the uninstall request to perform
 * @return the {@link Job} object which can be used to monitor the progress of the uninstall process, or
 *         {@code null} in case of failure
 */
public Job uninstall(UninstallRequest uninstallRequest) {
    setError(null);
    // Force proper id
    String extensionId = uninstallRequest.getExtensions().iterator().next().getId();
    String namespace = uninstallRequest.getNamespaces() == null ? null : uninstallRequest.getNamespaces().iterator().next();
    uninstallRequest.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(uninstallRequest);
    }
    // Start job
    Job job = null;
    try {
        job = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest);
    } 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)

Example 12 with JobException

use of org.xwiki.job.JobException 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 13 with JobException

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

Aggregations

JobException (org.xwiki.job.JobException)13 Job (org.xwiki.job.Job)8 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)5 InstallJob (org.xwiki.extension.job.internal.InstallJob)5 InstallPlanJob (org.xwiki.extension.job.internal.InstallPlanJob)5 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)5 UninstallPlanJob (org.xwiki.extension.job.internal.UninstallPlanJob)5 UpgradePlanJob (org.xwiki.extension.job.internal.UpgradePlanJob)5 XWikiException (com.xpn.xwiki.XWikiException)2 Test (org.junit.Test)2 JobExecutor (org.xwiki.job.JobExecutor)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 RefactoringScriptService (org.xwiki.refactoring.script.RefactoringScriptService)2 ScriptService (org.xwiki.script.service.ScriptService)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ExtensionId (org.xwiki.extension.ExtensionId)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)1