use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class DocumentSolrMetadataExtractorTest method getDocumentThrowingException.
@Test
public void getDocumentThrowingException() throws Exception {
XWikiException thrown = new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_DOC, "Unreadable document");
when(this.xcontext.getWiki().getDocument(this.documentReference, this.xcontext)).thenThrow(thrown);
try {
this.mocker.getComponentUnderTest().getSolrDocument(this.frenchDocumentReference);
fail("An exception was expected.");
} catch (SolrIndexerException ex) {
assertEquals("Failed to get input Solr document for entity '" + this.frenchDocumentReference + "'", ex.getMessage());
assertSame(thrown, ex.getCause());
}
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class WikiSolrReferenceResolver method getReferences.
@Override
public List<EntityReference> getReferences(EntityReference wikiReference) throws SolrIndexerException {
List<EntityReference> result = new ArrayList<EntityReference>();
// Ignore the wiki reference because it is not indexable.
List<String> localSpaceRefs = null;
// Make sure the list of spaces is from the requested wiki.
try {
localSpaceRefs = this.queryManager.getNamedQuery("getSpaces").setWiki(wikiReference.getName()).execute();
} catch (QueryException e) {
throw new SolrIndexerException("Failed to query wiki [" + wikiReference.getName() + "] spaces", e);
}
// Visit each space
for (String localSpaceRef : localSpaceRefs) {
EntityReference spaceReference = this.explicitEntityReferenceResolver.resolve(localSpaceRef, EntityType.SPACE, wikiReference);
try {
Iterables.addAll(result, this.spaceResolverProvider.get().getReferences(spaceReference));
} catch (Exception e) {
this.logger.error("Failed to resolve references for space [" + spaceReference + "]", e);
}
}
return result;
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class AbstractSolrMetadataExtractor method getTranslatedDocument.
/**
* Fetch translated document.
*
* @param documentReference reference to the document to be translated.
* @return translated document.
* @throws SolrIndexerException if problems occur.
*/
protected XWikiDocument getTranslatedDocument(DocumentReference documentReference) throws SolrIndexerException {
try {
XWikiDocument originalDocument = getDocument(documentReference);
Locale locale = documentReference.getLocale();
if (locale == null || locale.equals(Locale.ROOT)) {
return originalDocument;
}
XWikiDocument translatedDocument = originalDocument.getTranslatedDocument(locale, this.xcontextProvider.get());
// XWikiDocument#getTranslatedDocument returns the default document when the locale does not exist
if (translatedDocument.getRealLocale().equals(locale)) {
return translatedDocument;
}
} catch (Exception e) {
throw new SolrIndexerException(String.format("Failed to get translated document for '%s'", documentReference), e);
}
return null;
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class AbstractSolrMetadataExtractor method getLocale.
/**
* @param documentReference reference to the document.
* @return the locale code of the referenced document.
* @throws SolrIndexerException if problems occur.
*/
protected Locale getLocale(DocumentReference documentReference) throws SolrIndexerException {
Locale locale = null;
try {
if (documentReference.getLocale() != null && !documentReference.getLocale().equals(Locale.ROOT)) {
locale = documentReference.getLocale();
} else {
XWikiContext xcontext = this.xcontextProvider.get();
locale = xcontext.getWiki().getDocument(documentReference, xcontext).getRealLocale();
}
} catch (Exception e) {
throw new SolrIndexerException(String.format("Exception while fetching the locale of the document '%s'", documentReference), e);
}
return locale;
}
use of org.xwiki.search.solr.internal.api.SolrIndexerException in project xwiki-platform by xwiki.
the class DefaultSolrReferenceResolver method getResover.
/**
* @param reference the reference
* @return the resolver associated to the reference type
* @throws SolrIndexerException when failed to find a resolve associated to the passed reference
*/
private SolrReferenceResolver getResover(EntityReference reference) throws SolrIndexerException {
EntityType type = reference.getType();
SolrReferenceResolver resolver;
try {
resolver = this.componentManager.getInstance(SolrReferenceResolver.class, type.getLowerCase());
} catch (ComponentLookupException e) {
throw new SolrIndexerException("Failed to get SolrDocumentReferenceResolver corresponding to entity type [" + type + "]", e);
}
return resolver;
}
Aggregations