Search in sources :

Example 6 with SolrIndexerException

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());
    }
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiException(com.xpn.xwiki.XWikiException) Test(org.junit.Test)

Example 7 with SolrIndexerException

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;
}
Also used : SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) QueryException(org.xwiki.query.QueryException) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) QueryException(org.xwiki.query.QueryException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 8 with SolrIndexerException

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;
}
Also used : Locale(java.util.Locale) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 9 with SolrIndexerException

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;
}
Also used : Locale(java.util.Locale) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException)

Example 10 with SolrIndexerException

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;
}
Also used : EntityType(org.xwiki.model.EntityType) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Aggregations

SolrIndexerException (org.xwiki.search.solr.internal.api.SolrIndexerException)12 XWikiException (com.xpn.xwiki.XWikiException)7 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 ArrayList (java.util.ArrayList)4 Locale (java.util.Locale)4 EntityReference (org.xwiki.model.reference.EntityReference)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 QueryException (org.xwiki.query.QueryException)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 InputStream (java.io.InputStream)1 Metadata (org.apache.tika.metadata.Metadata)1 Test (org.junit.Test)1 EntityType (org.xwiki.model.EntityType)1 ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)1 IndexerRequest (org.xwiki.search.solr.internal.job.IndexerRequest)1