Search in sources :

Example 6 with JobException

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

the class DefaultWikiCreatorTest method createWikiWithException.

@Test
public void createWikiWithException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    // Mock
    JobException jobException = new JobException("Error in JobException");
    when(jobExecutor.execute("wikicreationjob", request)).thenThrow(jobException);
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().createWiki(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
}
Also used : JobException(org.xwiki.job.JobException) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Test(org.junit.Test)

Example 7 with JobException

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

the class XarExtensionScriptService method repairInstalledExtension.

/**
 * Make sure the provided XAR extension properly is registered in the installed extensions index.
 * <p>
 * Start an asynchronous Job.
 *
 * @param id the extension identifier
 * @param version the extension version
 * @param wiki the wiki where the extension is installed
 * @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 repairInstalledExtension(String id, String version, String wiki) {
    setError(null);
    if (!this.authorization.hasAccess(Right.PROGRAM)) {
        setError(new JobException("Need programming right to repair a XAR"));
        return null;
    }
    String namespace = getWikiNamespace(wiki);
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
    DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
    if (currentUserReference != null) {
        installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
        // 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(PROPERTY_USER_REFERENCE, currentUserReference.toString());
    }
    installRequest.addExtension(new ExtensionId(id, version));
    if (StringUtils.isNotBlank(namespace)) {
        installRequest.addNamespace(namespace);
    }
    Job job = null;
    try {
        job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
    } catch (Exception e) {
        setError(e);
    }
    return job;
}
Also used : JobException(org.xwiki.job.JobException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DiffXarJob(org.xwiki.extension.xar.internal.job.DiffXarJob) Job(org.xwiki.job.Job) RepairXarJob(org.xwiki.extension.xar.internal.job.RepairXarJob) DocumentReference(org.xwiki.model.reference.DocumentReference) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 8 with JobException

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

the class ExtensionHistoryScriptService method replay.

/**
 * Replay the given list of extension history records.
 *
 * @param records the history records to replay
 * @return the {@link Job} object that can be used to monitor the progress of the replay process, or {@code null} in
 *         case of failure
 */
public Job replay(List<ExtensionJobHistoryRecord> records) {
    setError(null);
    ReplayRequest request = createReplayRequest(createReplayPlan(records, true, null));
    try {
        return this.jobExecutor.execute(ReplayJob.JOB_TYPE, request);
    } catch (JobException e) {
        setError(e);
        return null;
    }
}
Also used : JobException(org.xwiki.job.JobException) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest)

Example 9 with JobException

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

the class ExtensionManagerScriptService method createUninstallPlan.

/**
 * Adds a new job to the job queue to perform the given uninstall plan request.
 * <p>
 * This method requires programming rights.
 *
 * @param uninstallRequest the uninstall plan request to perform
 * @return the {@link Job} object which can be used to monitor the progress of the uninstall plan process, or
 *         {@code null} in case of failure
 */
private Job createUninstallPlan(UninstallRequest uninstallRequest) {
    setError(null);
    if (!this.authorization.hasAccess(Right.PROGRAM)) {
        // Make sure only PR user can remove the right checking or change the users
        setRightsProperties(uninstallRequest);
    }
    Job job = null;
    try {
        job = this.jobExecutor.execute(UninstallPlanJob.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 10 with JobException

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

the class ExtensionManagerScriptService method createInstallPlan.

/**
 * Start the asynchronous installation plan creation process for an extension.
 *
 * @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 createInstallPlan(InstallRequest installRequest) {
    setError(null);
    if (!this.authorization.hasAccess(Right.PROGRAM)) {
        // Make sure only PR user can remove the right checking or change the users
        setRightsProperties(installRequest);
    }
    Job job = null;
    try {
        job = this.jobExecutor.execute(InstallPlanJob.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)

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