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