Search in sources :

Example 1 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException 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
        }
    }
}
Also used : XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarEntry(org.xwiki.xar.XarEntry) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) JobContext(org.xwiki.job.JobContext) Job(org.xwiki.job.Job) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionException(org.xwiki.extension.ExtensionException) IOException(java.io.IOException) UninstallException(org.xwiki.extension.UninstallException) InstallException(org.xwiki.extension.InstallException) XarException(org.xwiki.xar.XarException) UninstallException(org.xwiki.extension.UninstallException)

Example 2 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class UntypedEventListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    try {
        // Get every UntypedEventDescriptor registered in the ComponentManager
        List<UntypedRecordableEventDescriptor> descriptors = this.componentManagerProvider.get().getInstanceList(UntypedRecordableEventDescriptor.class);
        // Filter the event descriptors concerned by the event, then create the concerned events
        for (UntypedRecordableEventDescriptor descriptor : descriptors) {
            // If the event is expected by our descriptor
            if (eventMatchesDescriptor(event, source, descriptor)) {
                Set<String> target = getTarget(event, source, descriptor.getAuthorReference(), descriptor.getTargetExpression());
                observationManager.notify(new DefaultUntypedRecordableEvent(descriptor.getEventType(), target), EVENT_STREAM_MODULE, source);
            }
        }
    } catch (ComponentLookupException e) {
        logger.error("Unable to retrieve a list of registered UntypedRecordableEventDescriptor " + "from the ComponentManager.", e);
    }
}
Also used : UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 3 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultDistributionJob method createSteps.

@Override
protected List<DistributionStep> createSteps() {
    List<DistributionStep> steps = new ArrayList<>();
    boolean isMainWiki = isMainWiki();
    // Create admin user if needed
    if (isMainWiki) {
        try {
            steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, FirstAdminUserStep.ID));
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to get first admin step instance", e);
        }
    }
    // Install/upgrade main wiki UI
    addDefaultUIStep(steps, isMainWiki);
    // Upgrade other wikis
    if (isMainWiki) {
        ExtensionId wikiUI = this.distributionManager.getWikiUIExtensionId();
        if (wikiUI != null && StringUtils.isNotBlank(wikiUI.getId())) {
            // ... but only if the wiki extension ID is defined
            try {
                steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WikisDefaultUIDistributionStep.ID));
            } catch (ComponentLookupException e) {
                this.logger.error("Failed to get all in one default UI step instance", e);
            }
        } else {
        // TODO: Display the wikis flavor step
        }
    }
    // Upgrade outdated extensions
    try {
        steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, OutdatedExtensionsDistributionStep.ID));
    } catch (ComponentLookupException e) {
        this.logger.error("Failed to get outdated extensions step instance", e);
    }
    return steps;
}
Also used : DistributionStep(org.xwiki.extension.distribution.internal.job.step.DistributionStep) WikisDefaultUIDistributionStep(org.xwiki.extension.distribution.internal.job.step.WikisDefaultUIDistributionStep) DefaultUIDistributionStep(org.xwiki.extension.distribution.internal.job.step.DefaultUIDistributionStep) FlavorDistributionStep(org.xwiki.extension.distribution.internal.job.step.FlavorDistributionStep) OutdatedExtensionsDistributionStep(org.xwiki.extension.distribution.internal.job.step.OutdatedExtensionsDistributionStep) ArrayList(java.util.ArrayList) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionId(org.xwiki.extension.ExtensionId)

Example 4 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException 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 ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class AbstractMailScriptService method checkPermissions.

/**
 * Check authorization to send mail.
 *
 * @throws MessagingException when not authorized to send mail
 */
private void checkPermissions() throws MessagingException {
    // Load the configured permission checker
    ScriptServicePermissionChecker checker;
    String hint = this.senderConfiguration.getScriptServicePermissionCheckerHint();
    try {
        checker = this.componentManagerProvider.get().getInstance(ScriptServicePermissionChecker.class, hint);
    } catch (ComponentLookupException e) {
        // authorized to send emails!
        throw new MessagingException(String.format("Failed to locate Permission Checker [%s]. " + "The mail has not been sent.", hint), e);
    }
    try {
        checker.check();
    } catch (MessagingException e) {
        throw new MessagingException(String.format("Not authorized by the Permission Checker [%s] to send mail! " + "No mail has been sent.", hint), e);
    }
}
Also used : MessagingException(javax.mail.MessagingException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4