Search in sources :

Example 1 with Namespace

use of org.xwiki.component.namespace.Namespace in project xwiki-platform by xwiki.

the class AbstractExtensionValidator method checkAccess.

protected void checkAccess(Right entityRight, String namespaceString, Request request) throws AccessDeniedException {
    Namespace namespace = NamespaceUtils.toNamespace(namespaceString);
    // Root namespace
    if (namespace == null) {
        checkRootRight(entityRight, request);
        return;
    }
    if (namespace.getType() != null) {
        // User
        if (namespace.getType().equals("user")) {
            EntityReference reference = this.resolver.resolve(namespace.getValue(), EntityType.DOCUMENT);
            checkUserRight(reference, request);
            return;
        }
        // Entity
        EntityType entityType = EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase());
        if (entityType != null) {
            EntityReference reference = this.resolver.resolve(namespace.getValue(), entityType);
            checkAccess(reference, entityRight, request);
            return;
        }
    }
    // Unknown namespace
    checkNamespaceRight(namespace, Right.PROGRAM, request);
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference) Namespace(org.xwiki.component.namespace.Namespace)

Example 2 with Namespace

use of org.xwiki.component.namespace.Namespace in project xwiki-platform by xwiki.

the class OutdatedExtensionsDistributionStep method prepare.

@Override
public void prepare() {
    if (getState() == null) {
        setState(State.COMPLETED);
        if (isMainWiki()) {
            Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions();
            // Upgrade outdated extensions only when there is invalid extensions
            for (InstalledExtension extension : installedExtensions) {
                Collection<String> installedNamespaces = extension.getNamespaces();
                if (installedNamespaces == null) {
                    if (!extension.isValid(null)) {
                        this.logger.debug("Enabling outdate extension step on main wiki " + "because extension [{}] is invalid on root namespace", extension.getId());
                        setState(null);
                        break;
                    }
                } else {
                    for (String installedNamespace : installedNamespaces) {
                        if (!extension.isValid(installedNamespace)) {
                            this.logger.debug("Enabling outdate extension step on main wiki " + "because extension [{}] is invalid on namespace [{}]", extension.getId(), installedNamespace);
                            setState(null);
                            break;
                        }
                    }
                }
            }
        } else {
            Namespace currentNamespace = getNamespace();
            Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(currentNamespace.toString());
            // Upgrade outdated extensions only when there is invalid extensions
            for (InstalledExtension extension : installedExtensions) {
                if (!extension.isValid(currentNamespace.toString())) {
                    this.logger.debug("Enabling outdate extension step on wiki [{}]" + "because extension [{}] is invalid", getWiki(), extension.getId());
                    setState(null);
                    break;
                }
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Namespace(org.xwiki.component.namespace.Namespace)

Example 3 with Namespace

use of org.xwiki.component.namespace.Namespace 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 4 with Namespace

use of org.xwiki.component.namespace.Namespace in project xwiki-platform by xwiki.

the class DefaultUIDistributionStep method prepare.

@Override
public void prepare() {
    if (getState() == null) {
        setState(State.COMPLETED);
        Namespace namespace = getNamespace();
        ExtensionId extensionUI = this.distributionJob.getStatus().getDistributionExtensionUI();
        // Only if the UI is not already installed
        if (extensionUI != null) {
            InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(extensionUI.getId(), namespace.toString());
            if (installedExtension == null || !installedExtension.getId().getVersion().equals(extensionUI.getVersion())) {
                setState(null);
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionId(org.xwiki.extension.ExtensionId) Namespace(org.xwiki.component.namespace.Namespace)

Example 5 with Namespace

use of org.xwiki.component.namespace.Namespace in project xwiki-platform by xwiki.

the class DefaultRecordableEventDescriptorManager method getDescriptorsFromWiki.

private List<RecordableEventDescriptor> getDescriptorsFromWiki(String wikiId) throws ComponentLookupException {
    Namespace namespace = new WikiNamespace(wikiId);
    ComponentManager wikiComponentManager = componentManagerManager.getComponentManager(namespace.serialize(), false);
    if (wikiComponentManager == null) {
        return Collections.emptyList();
    }
    List<RecordableEventDescriptor> descriptors = new ArrayList<>();
    descriptors.addAll(wikiComponentManager.getInstanceList(RecordableEventDescriptor.class));
    descriptors.addAll(wikiComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class));
    return descriptors;
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) WikiNamespace(org.xwiki.model.namespace.WikiNamespace) ComponentManager(org.xwiki.component.manager.ComponentManager) ArrayList(java.util.ArrayList) WikiNamespace(org.xwiki.model.namespace.WikiNamespace) Namespace(org.xwiki.component.namespace.Namespace)

Aggregations

Namespace (org.xwiki.component.namespace.Namespace)7 InstalledExtension (org.xwiki.extension.InstalledExtension)4 ExtensionId (org.xwiki.extension.ExtensionId)2 EntityType (org.xwiki.model.EntityType)2 ArrayList (java.util.ArrayList)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 RecordableEventDescriptor (org.xwiki.eventstream.RecordableEventDescriptor)1 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)1 WikiNamespace (org.xwiki.model.namespace.WikiNamespace)1 EntityReference (org.xwiki.model.reference.EntityReference)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1