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);
}
}
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;
}
}
}
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());
}
}
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());
}
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;
}
Aggregations