Search in sources :

Example 86 with ComponentLookupException

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

the class HqlQueryExecutor method addEscapeLikeParametersFilter.

private void addEscapeLikeParametersFilter(Query query) {
    if (!hasQueryParametersType(query)) {
        return;
    }
    // Find the component class for the "escapeLikeParameters" filter
    QueryFilter escapeFilter;
    try {
        escapeFilter = this.componentManagerProvider.get().getInstance(QueryFilter.class, ESCAPE_LIKE_PARAMETERS_FILTER);
    } catch (ComponentLookupException e) {
        // Shouldn't happen!
        throw new RuntimeException(String.format("Failed to locate [%s] Query Filter", ESCAPE_LIKE_PARAMETERS_FILTER), e);
    }
    boolean found = false;
    for (QueryFilter filter : query.getFilters()) {
        if (escapeFilter.getClass().getName().equals(filter.getClass().getName())) {
            found = true;
            break;
        }
    }
    if (!found) {
        query.addFilter(escapeFilter);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 87 with ComponentLookupException

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

the class ConfiguredRatingsManagerProvider method get.

/**
 * Retrieve an instance of the desired RatingsManager (default/separate). - default: save the rating information in
 * the same page - separate: save the rating information in a specified space
 *
 * @param documentRef the document to which the ratings are associated to
 * @return the ratings manager selected by looking at the current configuration settings
 */
@Override
public RatingsManager get(DocumentReference documentRef) {
    String defaultHint = "default";
    String ratingsHint = getXWiki().Param(RatingsManager.RATINGS_CONFIG_PARAM_PREFIX + RatingsManager.RATINGS_CONFIG_FIELDNAME_MANAGER_HINT, defaultHint);
    try {
        XWikiDocument configurationDocument = ratingsConfiguration.getConfigurationDocument(documentRef);
        if (!configurationDocument.isNew() && configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE) != null) {
            BaseProperty prop = (BaseProperty) configurationDocument.getXObject(RatingsManager.RATINGS_CONFIG_CLASSREFERENCE).get(RatingsManager.RATINGS_CONFIG_CLASS_FIELDNAME_MANAGER_HINT);
            String hint = (prop == null) ? null : (String) prop.getValue();
            ratingsHint = (hint == null) ? ratingsHint : hint;
        }
    } catch (Exception e) {
        logger.error("Cannot read ratings config", e);
    }
    try {
        return componentManager.getInstance(RatingsManager.class, ratingsHint);
    } catch (ComponentLookupException e) {
        // TODO Auto-generated catch block
        logger.error("Error loading ratings manager component for hint " + ratingsHint, e);
        try {
            return componentManager.getInstance(RatingsManager.class, defaultHint);
        } catch (ComponentLookupException e1) {
            return null;
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) BaseProperty(com.xpn.xwiki.objects.BaseProperty) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 88 with ComponentLookupException

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

the class DefaultClassPropertyValuesProviderTest method getValuesWithMissingProvider.

@Test
public void getValuesWithMissingProvider() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenThrow(new ComponentLookupException("Component not found."));
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one");
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("There's no value provider registered for the [DBList] property type.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 89 with ComponentLookupException

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

the class UIExtensionScriptServiceTest method verifyExtensionsAreSortedAlphabeticallyById.

@Test
public void verifyExtensionsAreSortedAlphabeticallyById() throws Exception {
    // The UIX are voluntarily added in a wrong order.
    UIExtension uix3 = mock(UIExtension.class, "uix3");
    when(uix3.getId()).thenReturn("id3");
    when(uix3.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix3);
    UIExtension uix1 = mock(UIExtension.class, "uix1");
    when(uix1.getId()).thenReturn("id1");
    when(uix1.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix1);
    UIExtension uix2 = mock(UIExtension.class, "uix2");
    when(uix2.getId()).thenReturn("id2");
    when(uix2.getExtensionPointId()).thenReturn("epId");
    epExtensions.add(uix2);
    when(contextComponentManager.getInstance(UIExtensionManager.class, "epId")).thenThrow(new ComponentLookupException("No specific manager for extension point epId"));
    when(uiExtensionManager.get("epId")).thenReturn(epExtensions);
    when(contextComponentManager.getInstance(UIExtensionFilter.class, "sortById")).thenReturn(new SortByIdFilter());
    HashMap<String, String> filters = new HashMap<String, String>();
    filters.put("sortById", "");
    UIExtensionScriptService service = (UIExtensionScriptService) componentManager.getComponentUnderTest();
    List<UIExtension> extensions = service.getExtensions("epId", filters);
    Assert.assertEquals("id1", extensions.get(0).getId());
    Assert.assertEquals("id2", extensions.get(1).getId());
    Assert.assertEquals("id3", extensions.get(2).getId());
}
Also used : UIExtension(org.xwiki.uiextension.UIExtension) HashMap(java.util.HashMap) SortByIdFilter(org.xwiki.uiextension.internal.filter.SortByIdFilter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Example 90 with ComponentLookupException

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

the class AbstractResourceReferenceResolver method findResourceResolver.

/**
 * Find the right Resolver for the passed Resource type and call it.
 */
protected ResourceReferenceResolver<ExtendedURL> findResourceResolver(String hintPrefix, ResourceType type) throws UnsupportedResourceReferenceException {
    ResourceReferenceResolver<ExtendedURL> resolver;
    Type roleType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
    String roleHint = computeResolverHint(hintPrefix, type.getId());
    // Step 1: Look for a Resolver specific to the scheme and specific to the Resource Type
    if (this.componentManager.hasComponent(roleType, roleHint)) {
        try {
            resolver = this.componentManager.getInstance(roleType, roleHint);
        } catch (ComponentLookupException cle) {
            // There's no Resolver registered for the passed Resource Type
            throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for hint [%s]", roleHint), cle);
        }
    } else {
        // schemes
        try {
            resolver = this.componentManager.getInstance(roleType, type.getId());
        } catch (ComponentLookupException cle) {
            // There's no Resolver registered for the passed Resource Type
            throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for type [%s]", type), cle);
        }
    }
    return resolver;
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) ResourceType(org.xwiki.resource.ResourceType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

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