Search in sources :

Example 1 with WikiDescriptorManager

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;
                    }
                }
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId)

Example 2 with WikiDescriptorManager

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);
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) Namespace(org.xwiki.component.namespace.Namespace)

Example 3 with WikiDescriptorManager

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;
            }
        }
    }
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId)

Example 4 with WikiDescriptorManager

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"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) CacheManager(org.xwiki.cache.CacheManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 5 with WikiDescriptorManager

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"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ConverterManager(org.xwiki.properties.ConverterManager) CacheManager(org.xwiki.cache.CacheManager) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Aggregations

WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)40 Test (org.junit.Test)17 DocumentReference (org.xwiki.model.reference.DocumentReference)14 Before (org.junit.Before)13 XWikiContext (com.xpn.xwiki.XWikiContext)11 Execution (org.xwiki.context.Execution)9 ExecutionContext (org.xwiki.context.ExecutionContext)9 XWiki (com.xpn.xwiki.XWiki)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 ExtensionId (org.xwiki.extension.ExtensionId)6 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)6 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)5 InstalledExtension (org.xwiki.extension.InstalledExtension)4 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)4 Query (org.xwiki.query.Query)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3