Search in sources :

Example 1 with DistributionJob

use of org.xwiki.extension.distribution.internal.job.DistributionJob in project xwiki-platform by xwiki.

the class DefaultDistributionManager method startWikiJob.

@Override
public DistributionJob startWikiJob(String wiki) {
    try {
        DistributionJob wikiJob = this.componentManager.getInstance(Job.class, DefaultDistributionJob.HINT);
        this.wikiDistributionJobs.put(wiki, wikiJob);
        final DistributionRequest request = new DistributionRequest();
        request.setId(getWikiJobId(wiki));
        request.setWiki(wiki);
        request.setUserReference(this.xcontextProvider.get().getUserReference());
        request.setInteractive(this.configuration.getProperty("distribution.job.interactive.wiki", true));
        Thread distributionJobThread = new Thread(new Runnable() {

            @Override
            public void run() {
                // Create a clean Execution Context
                ExecutionContext context = new ExecutionContext();
                try {
                    executionContextManager.initialize(context);
                } catch (ExecutionContextException e) {
                    throw new RuntimeException("Failed to initialize wiki distribution job execution context", e);
                }
                DistributionJob job = wikiDistributionJobs.get(request.getWiki());
                job.initialize(request);
                job.run();
            }
        });
        distributionJobThread.setDaemon(true);
        distributionJobThread.setName("Distribution initialization of wiki [" + wiki + "]");
        distributionJobThread.start();
        // Wait until the job is ready (or finished)
        wikiJob.awaitReady();
        return wikiJob;
    } catch (Exception e) {
        this.logger.error("Failed to create distribution job for wiki [" + wiki + "]", e);
    }
    return null;
}
Also used : DistributionRequest(org.xwiki.extension.distribution.internal.job.DistributionRequest) ExecutionContext(org.xwiki.context.ExecutionContext) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) DefaultDistributionJob(org.xwiki.extension.distribution.internal.job.DefaultDistributionJob) ExecutionContextException(org.xwiki.context.ExecutionContextException) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 2 with DistributionJob

use of org.xwiki.extension.distribution.internal.job.DistributionJob in project xwiki-platform by xwiki.

the class DefaultDistributionManager method canDisplayDistributionWizard.

@Override
public boolean canDisplayDistributionWizard() {
    XWikiContext xcontext = this.xcontextProvider.get();
    DocumentReference currentUser = xcontext.getUserReference();
    // Check if its the user that started the DW (this avoid loosing all access to the DW during an install/upgrade)
    DistributionJob job = getCurrentDistributionJob();
    if (job != null && Objects.equal(currentUser, job.getRequest().getUserReference())) {
        this.logger.debug("The user [{}] started the DW so he can access it", currentUser);
        return true;
    }
    // If not guest make sure the user has admin right
    if (currentUser != null) {
        return this.authorizationManager.hasAccess(Right.ADMIN, currentUser, new WikiReference(xcontext.getWikiId()));
    }
    // Give guess access if there is no other user already registered
    if (xcontext.isMainWiki()) {
        // If there is no user on main wiki let guest access distribution wizard
        try {
            return RightsManager.getInstance().countAllGlobalUsersOrGroups(true, null, xcontext) == 0;
        } catch (XWikiException e) {
            this.logger.error("Failed to count global users", e);
        }
    }
    return false;
}
Also used : DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) DefaultDistributionJob(org.xwiki.extension.distribution.internal.job.DefaultDistributionJob) XWikiContext(com.xpn.xwiki.XWikiContext) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with DistributionJob

use of org.xwiki.extension.distribution.internal.job.DistributionJob in project xwiki-platform by xwiki.

the class DistributionInternalScriptService method renderCurrentStepToXHTML.

public String renderCurrentStepToXHTML(String transformationId) {
    DistributionJob job = this.distributionManager.getCurrentDistributionJob();
    if (job != null) {
        JobStatus jobStatus = job.getStatus();
        if (jobStatus != null) {
            State jobState = jobStatus.getState();
            if (jobState == State.RUNNING || jobState == State.WAITING) {
                Block block = job.getCurrentStep().executeInteractive();
                WikiPrinter printer = new DefaultWikiPrinter();
                this.xhtmlRenderer.render(block, printer);
                return printer.toString();
            }
        }
    }
    return null;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) DistributionJobStatus(org.xwiki.extension.distribution.internal.job.DistributionJobStatus) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) DistributionState(org.xwiki.extension.distribution.internal.DistributionManager.DistributionState) State(org.xwiki.job.event.status.JobStatus.State) Block(org.xwiki.rendering.block.Block) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Aggregations

DistributionJob (org.xwiki.extension.distribution.internal.job.DistributionJob)3 XWikiException (com.xpn.xwiki.XWikiException)2 DefaultDistributionJob (org.xwiki.extension.distribution.internal.job.DefaultDistributionJob)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 InitializationException (org.xwiki.component.phase.InitializationException)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ExecutionContextException (org.xwiki.context.ExecutionContextException)1 DistributionState (org.xwiki.extension.distribution.internal.DistributionManager.DistributionState)1 DistributionJobStatus (org.xwiki.extension.distribution.internal.job.DistributionJobStatus)1 DistributionRequest (org.xwiki.extension.distribution.internal.job.DistributionRequest)1 JobStatus (org.xwiki.job.event.status.JobStatus)1 State (org.xwiki.job.event.status.JobStatus.State)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 Block (org.xwiki.rendering.block.Block)1 DefaultWikiPrinter (org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1