Search in sources :

Example 66 with ComponentLookupException

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

the class AbstractDistributionJob method createNewStatus.

@Override
protected DistributionJobStatus createNewStatus(R request) {
    List<DistributionStep> steps = createSteps();
    if (getRequest().isInteractive()) {
        // Add Welcome step
        try {
            DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WelcomeDistributionStep.ID);
            welcomeStep.setState(State.COMPLETED);
            steps.add(0, welcomeStep);
        } catch (ComponentLookupException e1) {
            this.logger.error("Failed to get step instance for id [{}]", WelcomeDistributionStep.ID);
        }
        // Add Report step
        try {
            DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, ReportDistributionStep.ID);
            welcomeStep.setState(State.COMPLETED);
            steps.add(welcomeStep);
        } catch (ComponentLookupException e1) {
            this.logger.error("Failed to get step instance for id [{}]", ReportDistributionStep.ID);
        }
    }
    // Create status
    DistributionJobStatus status = createNewDistributionStatus(request, steps);
    if (this.distributionManager.getDistributionExtension() != null) {
        DistributionJobStatus previousStatus = getPreviousStatus();
        if (previousStatus != null && previousStatus.getDistributionExtension() != null && !Objects.equals(previousStatus.getDistributionExtension(), this.distributionManager.getDistributionExtension().getId())) {
            status.setPreviousDistributionExtension(previousStatus.getDistributionExtension());
            status.setPreviousDistributionExtensionUI(previousStatus.getDistributionExtensionUI());
        }
        status.setDistributionExtension(this.distributionManager.getDistributionExtension().getId());
        status.setDistributionExtensionUI(getUIExtensionId());
    }
    return status;
}
Also used : WelcomeDistributionStep(org.xwiki.extension.distribution.internal.job.step.WelcomeDistributionStep) DistributionStep(org.xwiki.extension.distribution.internal.job.step.DistributionStep) ReportDistributionStep(org.xwiki.extension.distribution.internal.job.step.ReportDistributionStep) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 67 with ComponentLookupException

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

the class JGroupsNetworkAdapter method createChannel.

/**
 * Create a new channel.
 *
 * @param channelId the identifier of the channel to create
 * @return the new channel
 * @throws Exception failed to create new channel
 */
private JChannel createChannel(String channelId) throws Exception {
    // load configuration
    ProtocolStackConfigurator channelConf = loadChannelConfiguration(channelId);
    // get Receiver
    JGroupsReceiver channelReceiver;
    try {
        channelReceiver = this.componentManager.getInstance(JGroupsReceiver.class, channelId);
    } catch (ComponentLookupException e) {
        channelReceiver = this.componentManager.getInstance(JGroupsReceiver.class);
    }
    // create channel
    JChannel channel = new JChannel(channelConf);
    channel.setReceiver(channelReceiver);
    channel.setDiscardOwnMessages(true);
    return channel;
}
Also used : JChannel(org.jgroups.JChannel) ProtocolStackConfigurator(org.jgroups.conf.ProtocolStackConfigurator) JGroupsReceiver(org.xwiki.observation.remote.jgroups.JGroupsReceiver) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 68 with ComponentLookupException

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

the class DefaultNotificationPreferenceManager method savePreferences.

@Override
public void savePreferences(List<NotificationPreference> preferences) throws NotificationException {
    // We construct a map where each key is a provider hint and each value is a list of associated providers
    // this allows calling each provider only once
    Map<String, List<NotificationPreference>> preferencesMapping = new HashMap<>();
    for (NotificationPreference notificationPreference : preferences) {
        // Try to get the corresponding provider, if no provider can be found, discard the save of the preference
        String providerHint = notificationPreference.getProviderHint();
        if (componentManager.hasComponent(NotificationPreferenceProvider.class, providerHint)) {
            if (!preferencesMapping.containsKey(providerHint)) {
                preferencesMapping.put(providerHint, new ArrayList<>());
            }
            preferencesMapping.get(providerHint).add(notificationPreference);
        }
    }
    // Once we have created the mapping, save all the preferences using their correct providers
    for (String providerHint : preferencesMapping.keySet()) {
        try {
            NotificationPreferenceProvider provider = componentManager.getInstance(NotificationPreferenceProvider.class, providerHint);
            provider.savePreferences(preferencesMapping.get(providerHint));
        } catch (ComponentLookupException e) {
            logger.error("Unable to retrieve the notification preference provide for hint {}: {}", providerHint, e);
        }
    }
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NotificationPreferenceProvider(org.xwiki.notifications.preferences.NotificationPreferenceProvider)

Example 69 with ComponentLookupException

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

the class DefaultNotificationPreferenceManager method getProviders.

private List<NotificationPreferenceProvider> getProviders() throws NotificationException {
    try {
        // Get every registered notification provider
        List<NotificationPreferenceProvider> providers = componentManager.getInstanceList(NotificationPreferenceProvider.class);
        // We handle conflicts between similar preferences by sorting the providers by order. Since
        // notificationPreferences is a set, only the first occurrence of a preference is stored.
        Collections.sort(providers, (o1, o2) -> o2.getProviderPriority() - o1.getProviderPriority());
        return providers;
    } catch (ComponentLookupException e) {
        throw new NotificationException("Unable to fetch the notifications preferences providers from the component manager", e);
    }
}
Also used : NotificationException(org.xwiki.notifications.NotificationException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NotificationPreferenceProvider(org.xwiki.notifications.preferences.NotificationPreferenceProvider)

Example 70 with ComponentLookupException

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

the class InternalTemplateManager method render.

private void render(XDOM xdom, Writer writer) {
    WikiPrinter printer = new WriterWikiPrinter(writer);
    BlockRenderer blockRenderer;
    try {
        blockRenderer = this.componentManagerProvider.get().getInstance(BlockRenderer.class, getTargetSyntax().toIdString());
    } catch (ComponentLookupException e) {
        blockRenderer = this.plainRenderer;
    }
    blockRenderer.render(xdom, printer);
}
Also used : WriterWikiPrinter(org.xwiki.rendering.renderer.printer.WriterWikiPrinter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) WriterWikiPrinter(org.xwiki.rendering.renderer.printer.WriterWikiPrinter) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer)

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