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;
}
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;
}
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;
}
Aggregations