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