Search in sources :

Example 6 with IndexerRelatedIndexingException

use of eu.europeana.indexing.exception.IndexerRelatedIndexingException in project metis-framework by europeana.

the class FullBeanPublisher method publish.

/**
 * Publishes an RDF.
 *
 * @param rdf RDF to publish.
 * @param recordDate The date that would represent the created/updated date of a record
 * @param datasetIdsToRedirectFrom The dataset ids that their records need to be redirected
 * @param performRedirects flag that indicates if redirect should be performed
 * @throws IndexingException which can be one of:
 * <ul>
 * <li>{@link IndexerRelatedIndexingException} In case an error occurred during publication.</li>
 * <li>{@link SetupRelatedIndexingException} in case an error occurred during indexing setup</li>
 * <li>{@link RecordRelatedIndexingException} in case an error occurred related to record
 * contents</li>
 * </ul>
 */
private void publish(RdfWrapper rdf, Date recordDate, List<String> datasetIdsToRedirectFrom, boolean performRedirects) throws IndexingException {
    // Convert RDF to Full Bean.
    final RdfToFullBeanConverter fullBeanConverter = fullBeanConverterSupplier.get();
    final FullBeanImpl fullBean = fullBeanConverter.convertRdfToFullBean(rdf);
    // Provide the preprocessor: this will set the created and updated timestamps as needed.
    final TriConsumer<FullBeanImpl, FullBeanImpl, Pair<Date, Date>> fullBeanPreprocessor = preserveUpdateAndCreateTimesFromRdf ? EMPTY_PREPROCESSOR : (FullBeanPublisher::setUpdateAndCreateTime);
    // Perform redirection
    final List<Pair<String, Date>> recordsForRedirection;
    try {
        recordsForRedirection = RecordRedirectsUtil.checkAndApplyRedirects(recordRedirectDao, rdf, recordDate, datasetIdsToRedirectFrom, performRedirects, this::getSolrDocuments);
    } catch (RuntimeException e) {
        throw new RecordRelatedIndexingException(REDIRECT_PUBLISH_ERROR, e);
    }
    // Publish to Mongo
    final FullBeanImpl savedFullBean;
    try {
        savedFullBean = new FullBeanUpdater(fullBeanPreprocessor).update(fullBean, recordDate, recordsForRedirection.stream().map(Pair::getValue).min(Comparator.naturalOrder()).orElse(null), edmMongoClient);
    } catch (MongoIncompatibleDriverException | MongoConfigurationException | MongoSecurityException e) {
        throw new SetupRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    } catch (MongoSocketException | MongoClientException | MongoInternalException | MongoInterruptedException e) {
        throw new IndexerRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    } catch (RuntimeException e) {
        throw new RecordRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
    }
    // Publish to Solr
    try {
        retryableExternalRequestForNetworkExceptions(() -> {
            try {
                publishToSolr(rdf, savedFullBean);
            } catch (IndexingException e) {
                throw new RuntimeException(e);
            }
            return null;
        });
    } catch (Exception e) {
        throw new RecordRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    }
}
Also used : MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoClientException(com.mongodb.MongoClientException) MongoInterruptedException(com.mongodb.MongoInterruptedException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoInternalException(com.mongodb.MongoInternalException) MongoClientException(com.mongodb.MongoClientException) MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoSocketException(com.mongodb.MongoSocketException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexingException(eu.europeana.indexing.exception.IndexingException) MongoInterruptedException(com.mongodb.MongoInterruptedException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException) MongoSecurityException(com.mongodb.MongoSecurityException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IndexingException(eu.europeana.indexing.exception.IndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) FullBeanImpl(eu.europeana.corelib.solr.bean.impl.FullBeanImpl) MongoSecurityException(com.mongodb.MongoSecurityException) RdfToFullBeanConverter(eu.europeana.indexing.fullbean.RdfToFullBeanConverter) FullBeanUpdater(eu.europeana.indexing.mongo.FullBeanUpdater) MongoSocketException(com.mongodb.MongoSocketException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) Pair(org.apache.commons.lang3.tuple.Pair) MongoInternalException(com.mongodb.MongoInternalException)

Example 7 with IndexerRelatedIndexingException

use of eu.europeana.indexing.exception.IndexerRelatedIndexingException in project metis-framework by europeana.

the class FullBeanPublisher method publishToSolr.

private void publishToSolr(RdfWrapper rdf, FullBeanImpl fullBean) throws IndexingException {
    // Create Solr document.
    final SolrDocumentPopulator documentPopulator = new SolrDocumentPopulator();
    final SolrInputDocument document = new SolrInputDocument();
    documentPopulator.populateWithProperties(document, fullBean);
    documentPopulator.populateWithFacets(document, rdf);
    // Save Solr document.
    try {
        solrServer.add(document);
    } catch (IOException e) {
        throw new IndexerRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    } catch (SolrServerException | RuntimeException e) {
        throw new RecordRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocumentPopulator(eu.europeana.indexing.solr.SolrDocumentPopulator) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException)

Example 8 with IndexerRelatedIndexingException

use of eu.europeana.indexing.exception.IndexerRelatedIndexingException in project metis-framework by europeana.

the class IndexedRecordAccess method removeDataset.

/**
 * <p>Removes all records that belong to a given dataset. For details on what parts of the record
 * are removed, see the documentation of {@link #removeRecord(String)}.</p>
 * <p><b>NOTE</b> that the rdf:about is
 * used to find the dependencies, rather than the actual references in the records. While this is
 * a reasonably safe way to go for now, eventually a more generic way along the lines of {@link
 * #removeRecord(String)} should be found, in which the exact composition of the rdf:about is
 * taken out of the equation.</p>
 *
 * @param datasetId The ID of the dataset to clear. Is not null.
 * @param maxRecordDate The cutoff date: all records that have a lower timestampUpdated than this
 * date will be removed. If null is provided then all records from that dataset will be removed.
 * @return The number of records that were removed.
 * @throws IndexerRelatedIndexingException In case something went wrong.
 */
public long removeDataset(String datasetId, Date maxRecordDate) throws IndexerRelatedIndexingException {
    final long mongoCount;
    try {
        mongoCount = removeDatasetFromMongo(datasetId, maxRecordDate);
        removeDatasetFromSolr(datasetId, maxRecordDate);
    } catch (SolrServerException | IOException | RuntimeException e) {
        throw new IndexerRelatedIndexingException("Could not remove dataset with ID '" + datasetId + "'.", e);
    }
    return mongoCount;
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IOException(java.io.IOException)

Example 9 with IndexerRelatedIndexingException

use of eu.europeana.indexing.exception.IndexerRelatedIndexingException in project metis-framework by europeana.

the class IndexedRecordAccess method removeRecord.

/**
 * Removes the record with the given rdf:about value. Also removes any associated entities (i.e.
 * those entities that are always part of only one record and the removal of which can not
 * invalidate references from other records):
 * <ul>
 * <li>Aggregation</li>
 * <li>EuropeanaAggregation</li>
 * <li>ProvidedCHO</li>
 * <li>Proxy (both provider and Europeana proxies)</li>
 * </ul>
 * However, entities that are potentially shared (like web resources, places, concepts etc.) are
 * not removed.
 *
 * @param rdfAbout The about value of the record to remove. Is not null.
 * @return Whether or not the record was removed.
 * @throws IndexerRelatedIndexingException In case something went wrong.
 */
public boolean removeRecord(String rdfAbout) throws IndexerRelatedIndexingException {
    try {
        // Remove Solr record
        final String queryValue = ClientUtils.escapeQueryChars(rdfAbout);
        solrServer.deleteByQuery(EdmLabel.EUROPEANA_ID.toString() + ":" + queryValue);
        // Obtain the Mongo record
        final Datastore datastore = mongoServer.getDatastore();
        final FullBeanImpl recordToDelete = datastore.find(FullBeanImpl.class).filter(Filters.eq(ABOUT_FIELD, rdfAbout)).first();
        // Remove mongo record and dependencies
        if (recordToDelete != null) {
            datastore.delete(recordToDelete);
            recordToDelete.getAggregations().forEach(datastore::delete);
            datastore.delete(recordToDelete.getEuropeanaAggregation());
            recordToDelete.getProvidedCHOs().forEach(datastore::delete);
            recordToDelete.getProxies().forEach(datastore::delete);
        }
        // Done
        return recordToDelete != null;
    } catch (SolrServerException | IOException | RuntimeException e) {
        throw new IndexerRelatedIndexingException("Could not remove record '" + rdfAbout + "'.", e);
    }
}
Also used : FullBeanImpl(eu.europeana.corelib.solr.bean.impl.FullBeanImpl) Datastore(dev.morphia.Datastore) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IOException(java.io.IOException)

Example 10 with IndexerRelatedIndexingException

use of eu.europeana.indexing.exception.IndexerRelatedIndexingException in project Europeana-Cloud by europeana.

the class DepublicationServiceTest method shouldTaskFailWhenRemoveMethodThrowsException.

@Test
public void shouldTaskFailWhenRemoveMethodThrowsException() throws IndexingException {
    when(indexer.removeAll(anyString(), nullable(Date.class))).thenThrow(new IndexerRelatedIndexingException("Indexer exception!"));
    service.depublishDataset(parameters);
    assertTaskFailed();
}
Also used : IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) Test(org.junit.Test)

Aggregations

IndexerRelatedIndexingException (eu.europeana.indexing.exception.IndexerRelatedIndexingException)10 IOException (java.io.IOException)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)5 RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)3 Test (org.junit.jupiter.api.Test)3 FullBeanImpl (eu.europeana.corelib.solr.bean.impl.FullBeanImpl)2 IndexingException (eu.europeana.indexing.exception.IndexingException)2 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)2 InputStream (java.io.InputStream)2 MongoClientException (com.mongodb.MongoClientException)1 MongoConfigurationException (com.mongodb.MongoConfigurationException)1 MongoIncompatibleDriverException (com.mongodb.MongoIncompatibleDriverException)1 MongoInternalException (com.mongodb.MongoInternalException)1 MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoSecurityException (com.mongodb.MongoSecurityException)1 MongoSocketException (com.mongodb.MongoSocketException)1 Datastore (dev.morphia.Datastore)1 RdfToFullBeanConverter (eu.europeana.indexing.fullbean.RdfToFullBeanConverter)1 FullBeanUpdater (eu.europeana.indexing.mongo.FullBeanUpdater)1 SolrDocumentPopulator (eu.europeana.indexing.solr.SolrDocumentPopulator)1