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