use of org.xwiki.context.ExecutionContext 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);
}
}
}
}
}
use of org.xwiki.context.ExecutionContext 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.context.ExecutionContext in project xwiki-platform by xwiki.
the class DocumentsModifiedDuringDistributionListener method checkXARHandler.
private void checkXARHandler(Event event, XWikiDocument document, XWikiContext xcontext) {
ExecutionContext context = this.execution.getContext();
if (context != null) {
XarExtensionPlan xarExtensionPlan = (XarExtensionPlan) context.getProperty(XarExtensionPlan.CONTEXTKEY_XARINSTALLPLAN);
if (xarExtensionPlan != null) {
Request request = this.jobContext.getCurrentJob().getRequest();
// It's a job started by the Distribution Wizard
if (StringUtils.equals(request.<String>getProperty("context.action"), "distribution")) {
String distributionWiki = request.getProperty("context.wiki");
if (distributionWiki != null) {
DocumentReference reference = document.getDocumentReferenceWithLocale();
DocumentStatus.Action action = toAction(event);
LocalExtension previousExtension = xarExtensionPlan.getPreviousXarExtension(reference);
LocalExtension nextExtension = xarExtensionPlan.getNextXarExtension(reference);
addDocument(distributionWiki, document, action, previousExtension, nextExtension);
}
}
}
}
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class JavaIntegrationTest method initialize.
@Before
public void initialize() throws Exception {
this.defaultBodyPartFactory = this.componentManager.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class));
this.htmlBodyPartFactory = this.componentManager.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
this.sender = this.componentManager.getInstance(MailSender.class);
// Set the EC
Execution execution = this.componentManager.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
XWikiContext xContext = new XWikiContext();
xContext.setWikiId("wiki");
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
when(execution.getContext()).thenReturn(executionContext);
Copier<ExecutionContext> executionContextCloner = this.componentManager.getInstance(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
// Just return the same execution context
when(executionContextCloner.copy(executionContext)).thenReturn(executionContext);
// Simulate receiving the Application Ready Event to start the mail threads
MailSenderInitializerListener listener = this.componentManager.getInstance(EventListener.class, MailSenderInitializerListener.LISTENER_NAME);
listener.onEvent(new ApplicationReadyEvent(), null, null);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class SendMailRunnable method prepareContext.
private void prepareContext() throws ExecutionContextException {
// Create a single execution context and use it for the send mail thread.
ExecutionContext ec = new ExecutionContext();
this.executionContextManager.initialize(ec);
}
Aggregations