Search in sources :

Example 1 with DefaultConflictActionQuestion

use of org.xwiki.extension.xar.question.DefaultConflictActionQuestion 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)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 IOException (java.io.IOException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ExtensionException (org.xwiki.extension.ExtensionException)1 InstallException (org.xwiki.extension.InstallException)1 UninstallException (org.xwiki.extension.UninstallException)1 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)1 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)1 DefaultConflictActionQuestion (org.xwiki.extension.xar.question.DefaultConflictActionQuestion)1 Job (org.xwiki.job.Job)1 JobContext (org.xwiki.job.JobContext)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 XarException (org.xwiki.xar.XarException)1