Search in sources :

Example 1 with JobContext

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

the class XarExtensionHandler method initJobPackageConfiguration.

private void initJobPackageConfiguration(Request request, boolean defaultConflict) throws InterruptedException {
    ExecutionContext context = this.execution.getContext();
    if (context != null && context.getProperty(CONTEXTKEY_PACKAGECONFIGURATION) == null) {
        Job currentJob = null;
        try {
            currentJob = this.componentManager.<JobContext>getInstance(JobContext.class).getCurrentJob();
        } catch (Exception e) {
            this.logger.error("Failed to lookup JobContext, it will be impossible to do interactive install");
        }
        if (currentJob != null) {
            PackageConfiguration configuration = new PackageConfiguration();
            context.setProperty(CONTEXTKEY_PACKAGECONFIGURATION, configuration);
            DocumentReference userReference = getRequestUserReference(AbstractExtensionValidator.PROPERTY_USERREFERENCE, request);
            configuration.setInteractive(request.isInteractive());
            configuration.setUser(userReference);
            configuration.setVerbose(request.isVerbose());
            configuration.setSkipMandatorytDocuments(true);
            configuration.setXarExtensionPlan(getXARExtensionPlan());
            configuration.setJobStatus(currentJob.getStatus());
            // Non blocker conflicts
            configuration.setConflictAction(ConflictType.CURRENT_DELETED, request.getProperty(ConflictQuestion.REQUEST_CONFLICT_DEFAULTANSWER_CURRENT_DELETED), GlobalAction.CURRENT);
            configuration.setConflictAction(ConflictType.MERGE_SUCCESS, request.getProperty(ConflictQuestion.REQUEST_CONFLICT_DEFAULTANSWER_MERGE_SUCCESS), GlobalAction.MERGED);
            // Blocker conflicts
            configuration.setConflictAction(ConflictType.CURRENT_EXIST, request.getProperty(ConflictQuestion.REQUEST_CONFLICT_DEFAULTANSWER_CURRENT_EXIST), configuration.isInteractive() ? GlobalAction.ASK : GlobalAction.NEXT);
            configuration.setConflictAction(ConflictType.MERGE_FAILURE, request.getProperty(ConflictQuestion.REQUEST_CONFLICT_DEFAULTANSWER_MERGE_FAILURE), configuration.isInteractive() ? GlobalAction.ASK : GlobalAction.MERGED);
            // If user asked to be asked about conflict behavior
            if (defaultConflict && currentJob.getStatus().getRequest().isInteractive()) {
                XWikiContext xcontext = xcontextProvider.get();
                // Make sure the context has the right user
                xcontext.setUserReference(userReference);
                int extensionConflictSetup = NumberUtils.toInt(xcontext.getWiki().getUserPreference("extensionConflictSetup", xcontext), 0);
                if (extensionConflictSetup == 1) {
                    DefaultConflictActionQuestion question = new DefaultConflictActionQuestion(configuration);
                    currentJob.getStatus().ask(question, 1, TimeUnit.HOURS);
                }
            }
        }
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) DefaultConflictActionQuestion(org.xwiki.extension.xar.question.DefaultConflictActionQuestion) XWikiContext(com.xpn.xwiki.XWikiContext) JobContext(org.xwiki.job.JobContext) Job(org.xwiki.job.Job) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionException(org.xwiki.extension.ExtensionException) IOException(java.io.IOException) UninstallException(org.xwiki.extension.UninstallException) InstallException(org.xwiki.extension.InstallException) XarException(org.xwiki.xar.XarException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with JobContext

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

the class XarExtensionHandler method uninstall.

@Override
public void uninstall(InstalledExtension installedExtension, String namespace, Request request) throws UninstallException {
    try {
        initializePagesIndex(request);
        initJobPackageConfiguration(request, false);
    } catch (Exception e) {
        throw new UninstallException("Failed to initialize extension plan index", e);
    }
    // probably not be in an expected state)
    if (!request.isRemote()) {
        Job currentJob;
        try {
            currentJob = this.componentManager.<JobContext>getInstance(JobContext.class).getCurrentJob();
        } catch (ComponentLookupException e) {
            currentJob = null;
        }
        if (currentJob == null) {
            String wiki;
            try {
                wiki = XarHandlerUtils.getWikiFromNamespace(namespace);
            } catch (UnsupportedNamespaceException e) {
                throw new UninstallException("Failed to extract wiki id from namespace", e);
            }
            PackageConfiguration configuration = createPackageConfiguration(null, request, wiki);
            try {
                XarInstalledExtension xarLocalExtension = (XarInstalledExtension) this.xarRepository.resolve(installedExtension.getId());
                Collection<XarEntry> pages = xarLocalExtension.getXarPackage().getEntries();
                this.packager.unimportPages(pages, configuration);
            } catch (Exception e) {
                // Not supposed to be possible
                throw new UninstallException("Failed to get xar extension [" + installedExtension.getId() + "] from xar repository", e);
            }
        } else {
        // The actual delete of pages is done in XarExtensionJobFinishedListener
        }
    }
}
Also used : XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarEntry(org.xwiki.xar.XarEntry) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) JobContext(org.xwiki.job.JobContext) Job(org.xwiki.job.Job) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionException(org.xwiki.extension.ExtensionException) IOException(java.io.IOException) UninstallException(org.xwiki.extension.UninstallException) InstallException(org.xwiki.extension.InstallException) XarException(org.xwiki.xar.XarException) UninstallException(org.xwiki.extension.UninstallException)

Example 3 with JobContext

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

the class EntityJobTest method initialize.

private void initialize(NoopEntityJob job, EntityRequest request) {
    ReflectionUtils.setFieldValue(job, "jobContext", mock(JobContext.class));
    ReflectionUtils.setFieldValue(job, "progressManager", mock(JobProgressManager.class));
    ReflectionUtils.setFieldValue(job, "authorization", this.authorization);
    ReflectionUtils.setFieldValue(job, "modelBridge", this.modelBridge);
    EntityReferenceProvider defaultEntityReferenceProvider = mock(EntityReferenceProvider.class);
    ReflectionUtils.setFieldValue(job, "defaultEntityReferenceProvider", defaultEntityReferenceProvider);
    when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("WebHome", EntityType.DOCUMENT, null));
    job.initialize(request);
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) EntityReference(org.xwiki.model.reference.EntityReference) JobContext(org.xwiki.job.JobContext) JobProgressManager(org.xwiki.job.event.status.JobProgressManager)

Example 4 with JobContext

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

the class WikiCreationJobTest method setUp.

@Before
public void setUp() throws Exception {
    observationManager = mocker.getInstance(ObservationManager.class);
    loggerManager = mocker.getInstance(LoggerManager.class);
    store = mocker.getInstance(JobStatusStore.class);
    executionProvider = mock(Provider.class);
    mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, Execution.class), executionProvider);
    when(executionProvider.get()).thenReturn(execution);
    executionContextManagerProvider = mock(Provider.class);
    mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, ExecutionContextManager.class), executionContextManagerProvider);
    executionContextManager = mock(ExecutionContextManager.class);
    when(executionContextManagerProvider.get()).thenReturn(executionContextManager);
    jobContext = mocker.getInstance(JobContext.class);
    progressManager = mocker.getInstance(JobProgressManager.class);
    execution.pushContext(new ExecutionContext());
}
Also used : Execution(org.xwiki.context.Execution) DefaultExecution(org.xwiki.context.internal.DefaultExecution) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) LoggerManager(org.xwiki.logging.LoggerManager) ObservationManager(org.xwiki.observation.ObservationManager) JobContext(org.xwiki.job.JobContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) JobProgressManager(org.xwiki.job.event.status.JobProgressManager) JobStatusStore(org.xwiki.job.JobStatusStore) Provider(javax.inject.Provider) Before(org.junit.Before)

Aggregations

JobContext (org.xwiki.job.JobContext)4 IOException (java.io.IOException)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 ExtensionException (org.xwiki.extension.ExtensionException)2 InstallException (org.xwiki.extension.InstallException)2 UninstallException (org.xwiki.extension.UninstallException)2 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)2 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)2 Job (org.xwiki.job.Job)2 JobProgressManager (org.xwiki.job.event.status.JobProgressManager)2 XarException (org.xwiki.xar.XarException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 Provider (javax.inject.Provider)1 Before (org.junit.Before)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 Execution (org.xwiki.context.Execution)1 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)1 DefaultExecution (org.xwiki.context.internal.DefaultExecution)1 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)1