use of eu.europeana.enrichment.rest.client.exceptions.DereferenceException in project Europeana-Cloud by europeana.
the class EnrichmentBoltTest method sendErrorNotificationWhenTheEnrichmentFails.
@Test
public void sendErrorNotificationWhenTheEnrichmentFails() throws Exception {
Tuple anchorTuple = mock(TupleImpl.class);
byte[] FILE_DATA = Files.readAllBytes(Paths.get("src/test/resources/example1.xml"));
StormTaskTuple tuple = new StormTaskTuple(TASK_ID, TASK_NAME, SOURCE_VERSION_URL, FILE_DATA, prepareStormTaskTupleParameters(), null);
String fileContent = new String(tuple.getFileData());
String errorMessage = "Dereference or Enrichment Exception";
given(enrichmentWorker.process(eq(fileContent))).willThrow(new DereferenceException(errorMessage, new Throwable()));
enrichmentBolt.execute(anchorTuple, tuple);
Mockito.verify(outputCollector, Mockito.times(0)).emit(Mockito.any(List.class));
Mockito.verify(outputCollector, Mockito.times(1)).emit(Mockito.eq(AbstractDpsBolt.NOTIFICATION_STREAM_NAME), any(Tuple.class), captor.capture());
Values capturedValues = captor.getValue();
Map val = (Map) capturedValues.get(1);
Assert.assertTrue(val.get("additionalInfo").toString().contains("emote Enrichment/dereference service caused the problem!. The full error:"));
Assert.assertTrue(val.get("additionalInfo").toString().contains(errorMessage));
}
use of eu.europeana.enrichment.rest.client.exceptions.DereferenceException in project metis-framework by europeana.
the class DereferencerImpl method dereferenceExternalEntity.
private List<EnrichmentBase> dereferenceExternalEntity(String resourceId) throws DereferenceException {
// Check that there is something to do.
if (dereferenceClient == null) {
return Collections.emptyList();
}
// Perform the dereferencing.
EnrichmentResultList result;
try {
LOGGER.debug("== Processing {}", resourceId);
result = retryableExternalRequestForNetworkExceptions(() -> dereferenceClient.dereference(resourceId));
} catch (BadRequest e) {
// We are forgiving for these errors
LOGGER.warn("ResourceId {}, failed", resourceId, e);
result = null;
} catch (Exception e) {
throw new DereferenceException("Exception occurred while trying to perform dereferencing.", e);
}
// Return the result.
return Optional.ofNullable(result).map(EnrichmentResultList::getEnrichmentBaseResultWrapperList).orElseGet(Collections::emptyList).stream().map(EnrichmentResultBaseWrapper::getEnrichmentBaseList).filter(Objects::nonNull).flatMap(List::stream).collect(Collectors.toList());
}
use of eu.europeana.enrichment.rest.client.exceptions.DereferenceException in project metis-sandbox by europeana.
the class EnrichmentServiceImpl method enrich.
@Override
public RecordInfo enrich(Record record) {
requireNonNull(record, "Record must not be null");
List<RecordError> recordErrors = new LinkedList<>();
byte[] result;
try {
result = enrichmentWorker.process(record.getContentInputStream());
} catch (EnrichmentException | DereferenceException | SerializationException e) {
result = record.getContent();
recordErrors.add(new RecordError(new RecordProcessingException(record.getProviderId(), e)));
}
return new RecordInfo(Record.from(record, result), recordErrors);
}
use of eu.europeana.enrichment.rest.client.exceptions.DereferenceException in project metis-sandbox by europeana.
the class EnrichmentServiceImplTest method enrich_withDereferenceException_expectFail.
@Test
void enrich_withDereferenceException_expectFail() throws EnrichmentException, DereferenceException, SerializationException {
var content = "This is the content";
var record = Record.builder().recordId(1L).content(content.getBytes()).language(Language.IT).country(Country.ITALY).datasetName("").datasetId("1").build();
when(enrichmentWorker.process(any(InputStream.class))).thenThrow(new EnrichmentException("Failed", new Exception()));
var recordInfo = service.enrich(record);
assertEquals(1L, recordInfo.getRecord().getRecordId());
assertEquals(1, recordInfo.getErrors().size());
}
use of eu.europeana.enrichment.rest.client.exceptions.DereferenceException in project metis-framework by europeana.
the class DereferencerProvider method create.
/**
* Builds an {@link Dereferencer} according to the parameters that are set.
*
* @return An instance.
* @throws IllegalStateException When both the enrichment and dereference URLs are blank.
* @throws DereferenceException if the enrichment url is wrong and therefore the dereferencer
* was not successfully created
*/
public Dereferencer create() throws DereferenceException {
// Make sure that the worker can do something.
if (StringUtils.isBlank(dereferenceUrl) && StringUtils.isBlank(enrichmentUrl)) {
throw new IllegalStateException("Dereferencing must be enabled.");
}
// Do some logging.
if (dereferenceUrl == null) {
LOGGER.warn("Creating dereferencer for Europeana entities only.");
} else if (enrichmentUrl == null) {
LOGGER.warn("Creating dereferencer for non-Europeana entities only.");
} else {
LOGGER.info("Creating dereferencer for both Europeana and non-Europeana entities.");
}
// Create the dereference client if needed
final DereferenceClient dereferenceClient;
if (StringUtils.isNotBlank(dereferenceUrl)) {
dereferenceClient = new DereferenceClient(createRestTemplate(), dereferenceUrl);
} else {
dereferenceClient = null;
}
// Create the enrichment client if needed
final RemoteEntityResolver remoteEntityResolver;
if (StringUtils.isNotBlank(enrichmentUrl)) {
try {
remoteEntityResolver = new RemoteEntityResolver(new URL(enrichmentUrl), batchSizeEnrichment, createRestTemplate());
} catch (MalformedURLException e) {
LOGGER.debug("There was a problem with the input values");
throw new DereferenceException("Problems while building a new Dereferencer", e);
}
} else {
remoteEntityResolver = null;
}
// Done.
return new DereferencerImpl(new EntityMergeEngine(), remoteEntityResolver, dereferenceClient);
}
Aggregations