use of eu.europeana.indexing.exception.SetupRelatedIndexingException 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);
}
}
use of eu.europeana.indexing.exception.SetupRelatedIndexingException in project metis-framework by europeana.
the class IndexerImpl method indexRecords.
private void indexRecords(List<RDF> records, IndexingProperties properties) throws IndexingException {
if (properties.isPerformRedirects() && connectionProvider.getRecordRedirectDao() == null) {
throw new SetupRelatedIndexingException("Record redirect dao has not been initialized and performing redirects is requested");
}
LOGGER.info("Processing {} records...", records.size());
final FullBeanPublisher publisher = connectionProvider.getFullBeanPublisher(properties.isPreserveUpdateAndCreateTimesFromRdf());
for (RDF record : records) {
preprocessRecord(record, properties.isPerformTierCalculation());
if (properties.isPerformRedirects()) {
publisher.publishWithRedirects(new RdfWrapper(record), properties.getRecordDate(), properties.getDatasetIdsForRedirection());
} else {
publisher.publish(new RdfWrapper(record), properties.getRecordDate(), properties.getDatasetIdsForRedirection());
}
}
LOGGER.info("Successfully processed {} records.", records.size());
}
use of eu.europeana.indexing.exception.SetupRelatedIndexingException in project metis-framework by europeana.
the class RdfTierUtils method setTierInternal.
private static void setTierInternal(RDF rdf, Tier tier) throws IndexingException {
// Get the right instance of RdfTier.
final RdfTier rdfTier = tiersByValue.get(tier);
if (rdfTier == null) {
throw new SetupRelatedIndexingException("Cannot find settings for tier value " + tier.getClass());
}
// Determine if there is something to reference and somewhere to add the reference.
final RdfWrapper rdfWrapper = new RdfWrapper(rdf);
final Set<String> aggregationAbouts = rdfWrapper.getAggregations().stream().filter(Objects::nonNull).map(Aggregation::getAbout).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
if (aggregationAbouts.isEmpty()) {
throw new RecordRelatedIndexingException("Cannot find provider aggregation in record.");
}
final EuropeanaAggregationType europeanaAggregation = rdfWrapper.getEuropeanaAggregation().orElseThrow(() -> new RecordRelatedIndexingException("Cannot find Europeana aggregation in record."));
final String choAbout = Optional.ofNullable(europeanaAggregation.getAggregatedCHO()).map(AggregatedCHO::getResource).orElseThrow(() -> new RecordRelatedIndexingException("Cannot find aggregated CHO in Europeana aggregation."));
final String annotationAboutBase = "/item" + choAbout;
// Create the annotation
final QualityAnnotation annotation = new QualityAnnotation();
final Created created = new Created();
created.setString(Instant.now().toString());
annotation.setCreated(created);
annotation.setHasTargetList(aggregationAbouts.stream().map(about -> {
final HasTarget hasTarget = new HasTarget();
hasTarget.setResource(about);
return hasTarget;
}).collect(Collectors.toList()));
final HasBody hasBody = new HasBody();
hasBody.setResource(rdfTier.getUri());
annotation.setHasBody(hasBody);
annotation.setAbout(annotationAboutBase + rdfTier.getAboutSuffix());
// Add the annotation (remove all annotations with the same about)
final Stream<QualityAnnotation> existingAnnotations = rdfWrapper.getQualityAnnotations().stream().filter(existingAnnotation -> !annotation.getAbout().equals(existingAnnotation.getAbout()));
rdf.setQualityAnnotationList(Stream.concat(existingAnnotations, Stream.of(annotation)).collect(Collectors.toList()));
// Add the link to the annotation to the europeana aggregation.
final HasQualityAnnotation link = new HasQualityAnnotation();
link.setResource(annotation.getAbout());
final Stream<HasQualityAnnotation> existingLinks = Optional.ofNullable(europeanaAggregation.getHasQualityAnnotationList()).stream().flatMap(Collection::stream).filter(existingLink -> !link.getResource().equals(existingLink.getResource()));
europeanaAggregation.setHasQualityAnnotationList(Stream.concat(existingLinks, Stream.of(link)).collect(Collectors.toList()));
}
Aggregations