Search in sources :

Example 1 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException 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 WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException 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 WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException 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 WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class DefaultRecordableEventDescriptorManager method getRecordableEventDescriptors.

@Override
public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException {
    try {
        // We use an hashSet to be sure we won't store the same descriptor twice (in case the same application
        // is installed on several wikis).
        Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>();
        // Load the component from the context component manager (root + wiki + user component managers, etc...)
        recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class));
        // Maybe add components of the other wikis too
        if (allWikis) {
            for (String wikiId : wikiDescriptorManager.getAllIds()) {
                recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId));
            }
        }
        return new ArrayList<>(recordableEventDescriptors);
    } catch (WikiManagerException | ComponentLookupException e) {
        throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e);
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) ArrayList(java.util.ArrayList) EventStreamException(org.xwiki.eventstream.EventStreamException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) HashSet(java.util.HashSet)

Example 5 with WikiManagerException

use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method getMembers.

@Override
public Collection<String> getMembers(String wikiId) throws WikiUserManagerException {
    List<String> members = new ArrayList<>();
    try {
        // Get the descriptor
        WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
        // Add the wiki owner
        members.add(descriptor.getOwnerId());
    } catch (WikiManagerException e) {
        throw new WikiUserManagerException(String.format("Failed to get the descriptor for [%s]", wikiId), e);
    }
    // Get the other members from the wiki AllGroup
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
    if (memberObjects != null) {
        for (BaseObject object : memberObjects) {
            if (object == null) {
                continue;
            }
            String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
            if (!member.isEmpty() && !members.contains(member)) {
                members.add(member);
            }
        }
    }
    return members;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)40 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)17 Test (org.junit.Test)13 XWikiContext (com.xpn.xwiki.XWikiContext)12 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)11 XWiki (com.xpn.xwiki.XWiki)7 XWikiException (com.xpn.xwiki.XWikiException)7 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)4 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)4 ExtensionId (org.xwiki.extension.ExtensionId)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Query (org.xwiki.query.Query)3 QueryException (org.xwiki.query.QueryException)3 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)3