use of org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration 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.extension.xar.internal.handler.packager.PackageConfiguration 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.extension.xar.internal.handler.packager.PackageConfiguration in project xwiki-platform by xwiki.
the class DefaultDocumentMergeImporterTest method setUp.
@Before
public void setUp() throws Exception {
this.xwiki = mock(XWiki.class);
when(this.xcontext.getWiki()).thenReturn(this.xwiki);
// documents
this.previousDocument = mock(XWikiDocument.class, "previous");
when(this.previousDocument.isNew()).thenReturn(false);
when(this.previousDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
this.currentDocument = mock(XWikiDocument.class, "current");
when(this.currentDocument.isNew()).thenReturn(false);
when(this.currentDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
when(this.xwiki.getDocument(same(this.documentReference), same(xcontext))).thenReturn(this.currentDocument);
this.nextDocument = mock(XWikiDocument.class, "next");
when(this.nextDocument.isNew()).thenReturn(false);
when(this.nextDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
this.mergedDocument = mock(XWikiDocument.class, "merged");
when(this.mergedDocument.isNew()).thenReturn(false);
when(this.mergedDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
when(this.currentDocument.clone()).thenReturn(this.mergedDocument);
// merge
this.configuration = new PackageConfiguration();
this.mergeResult = new MergeResult();
when(this.mergedDocument.merge(same(this.previousDocument), same(this.nextDocument), any(MergeConfiguration.class), any(XWikiContext.class))).thenReturn(this.mergeResult);
// job status
this.jobStatus = mock(JobStatus.class);
this.configuration.setJobStatus(this.jobStatus);
// execution
this.econtext = new ExecutionContext();
this.execution = this.mocker.getInstance(Execution.class);
when(this.execution.getContext()).thenReturn(this.econtext);
}
use of org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration in project xwiki-platform by xwiki.
the class XarExtensionHandler method createPackageConfiguration.
private PackageConfiguration createPackageConfiguration(LocalExtension extension, Request request, String wiki) {
PackageConfiguration configuration;
// Search job configuration in the context
ExecutionContext context = this.execution.getContext();
if (context != null) {
configuration = (PackageConfiguration) context.getProperty(CONTEXTKEY_PACKAGECONFIGURATION);
} else {
configuration = null;
}
// Create a configuration for this extension
if (configuration != null) {
configuration = configuration.clone();
} else {
configuration = new PackageConfiguration();
DocumentReference userReference = getRequestUserReference(AbstractExtensionValidator.PROPERTY_USERREFERENCE, request);
configuration.setInteractive(request.isInteractive());
configuration.setUser(userReference);
configuration.setVerbose(request.isVerbose());
configuration.setSkipMandatorytDocuments(true);
}
configuration.setWiki(wiki);
// Filter entries to import if there is a plan
if (extension != null && configuration.getXarExtensionPlan() != null) {
Map<String, Map<XarEntry, LocalExtension>> nextXAREntries = configuration.getXarExtensionPlan().nextXAREntries;
Set<String> entriesToImport = new HashSet<>();
Map<XarEntry, LocalExtension> nextXAREntriesOnRoot = nextXAREntries.get(null);
if (nextXAREntriesOnRoot != null) {
for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnRoot.entrySet()) {
if (entry.getValue() == extension) {
entriesToImport.add(entry.getKey().getEntryName());
}
}
}
Map<XarEntry, LocalExtension> nextXAREntriesOnWiki = nextXAREntries.get(wiki);
if (nextXAREntriesOnWiki != null) {
for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnWiki.entrySet()) {
if (entry.getValue() == extension) {
entriesToImport.add(entry.getKey().getEntryName());
}
}
}
configuration.setEntriesToImport(entriesToImport);
}
return configuration;
}
use of org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration in project xwiki-platform by xwiki.
the class XarExtensionHandler method installInternal.
private void installInternal(LocalExtension newLocalExtension, String wiki, Request request) throws InstallException {
try {
initializePagesIndex(request);
initJobPackageConfiguration(request, true);
} catch (Exception e) {
throw new InstallException("Failed to initialize extension plan index", e);
}
// import xar into wiki (add new version when the page already exists)
PackageConfiguration configuration = createPackageConfiguration(newLocalExtension, request, wiki);
try {
this.packager.importXAR("Install extension [" + newLocalExtension + "]", new File(newLocalExtension.getFile().getAbsolutePath()), configuration);
} catch (Exception e) {
throw new InstallException("Failed to import xar for extension [" + newLocalExtension + "]", e);
}
}
Aggregations