use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class WikisDefaultUIDistributionStep method prepare.
@Override
public void prepare() {
if (getState() == null) {
setState(State.COMPLETED);
WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
Collection<String> wikiIds;
try {
wikiIds = wikiDescriptorManager.getAllIds();
} catch (WikiManagerException e) {
this.logger.error("Failed to get the list of wikis", e);
setState(null);
return;
}
ExtensionId wikiExtensionUI = this.distributionManager.getWikiUIExtensionId();
if (wikiExtensionUI != null) {
for (String wikiId : wikiIds) {
if (!wikiDescriptorManager.getMainWikiId().equals(wikiId)) {
String namespace = "wiki:" + wikiId;
// Only if the UI is not already installed
InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(wikiExtensionUI.getId(), namespace);
if (installedExtension == null || !installedExtension.getId().getVersion().equals(wikiExtensionUI.getVersion())) {
setState(null);
return;
}
}
}
}
}
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class WikisDefaultUIDistributionStep method executeNonInteractive.
@Override
public void executeNonInteractive() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
Collection<String> wikiIds;
try {
wikiIds = wikiDescriptorManager.getAllIds();
} catch (WikiManagerException e) {
this.logger.error("Failed to get the list of wikis", e);
setState(null);
return;
}
ExtensionId wikiExtensionUI = this.distributionManager.getWikiUIExtensionId();
for (String wikiId : wikiIds) {
if (!wikiDescriptorManager.getMainWikiId().equals(wikiId)) {
String namespace = new Namespace("wiki", wikiId).toString();
// Only if the UI is not already installed
if (wikiExtensionUI != null) {
InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(wikiExtensionUI.getId(), namespace);
if (installedExtension == null || !installedExtension.getId().getVersion().equals(wikiExtensionUI.getVersion())) {
install(wikiExtensionUI, namespace, false);
}
}
}
}
// Complete task
setState(State.COMPLETED);
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class WikisFlavorDistributionStep method prepare.
@Override
public void prepare() {
if (getState() == null) {
setState(State.COMPLETED);
if (!isMainWiki()) {
return;
}
WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
Collection<String> wikiIds;
try {
wikiIds = wikiDescriptorManager.getAllIds();
} catch (WikiManagerException e) {
this.logger.error("Failed to get the list of wikis", e);
setState(null);
return;
}
String mainWiki = wikiDescriptorManager.getMainWikiId();
// Enable if any of the wikis has no valid top level flavor extension
for (String wikiId : wikiIds) {
if (mainWiki.equals(wikiId)) {
continue;
}
String namespace = "wiki:" + wikiId;
ExtensionId flavor = flavorManager.getFlavorOfWiki(getWiki());
if (flavor == null || !installedRepository.getInstalledExtension(flavor).isValid(namespace)) {
setState(null);
return;
}
}
}
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenNoSendMailConfigClassXObject.
@Test
public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception {
Cache<Object> cache = mock(Cache.class);
CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
XWikiDocument document = mock(XWikiDocument.class);
when(document.getXObject(classReference)).thenReturn(null);
DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
XWiki xwiki = mock(XWiki.class);
when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontext.getWiki()).thenReturn(xwiki);
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(xcontext);
assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenSendMailConfigClassXObjectExists.
@Test
public void getPropertyWhenSendMailConfigClassXObjectExists() throws Exception {
ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
when(converterManager.convert(String.class, "value")).thenReturn("value");
Cache<Object> cache = mock(Cache.class);
CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
BaseProperty property = mock(BaseProperty.class);
when(property.toText()).thenReturn("value");
BaseObject object = mock(BaseObject.class);
when(object.getField("key")).thenReturn(property);
XWikiDocument document = mock(XWikiDocument.class);
when(document.getXObject(classReference)).thenReturn(object);
DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
XWiki xwiki = mock(XWiki.class);
when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontext.getWiki()).thenReturn(xwiki);
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(xcontext);
assertEquals("value", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Aggregations