Search in sources :

Example 1 with RdfToFullBeanConverter

use of eu.europeana.indexing.fullbean.RdfToFullBeanConverter 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)

Aggregations

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 FullBeanImpl (eu.europeana.corelib.solr.bean.impl.FullBeanImpl)1 IndexerRelatedIndexingException (eu.europeana.indexing.exception.IndexerRelatedIndexingException)1 IndexingException (eu.europeana.indexing.exception.IndexingException)1 RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)1 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)1 RdfToFullBeanConverter (eu.europeana.indexing.fullbean.RdfToFullBeanConverter)1 FullBeanUpdater (eu.europeana.indexing.mongo.FullBeanUpdater)1 IOException (java.io.IOException)1 Pair (org.apache.commons.lang3.tuple.Pair)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1