Search in sources :

Example 1 with DereferenceException

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));
}
Also used : StormTaskTuple(eu.europeana.cloud.service.dps.storm.StormTaskTuple) DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException) Values(org.apache.storm.tuple.Values) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(org.apache.storm.tuple.Tuple) StormTaskTuple(eu.europeana.cloud.service.dps.storm.StormTaskTuple) Test(org.junit.Test)

Example 2 with DereferenceException

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());
}
Also used : BadRequest(org.springframework.web.client.HttpClientErrorException.BadRequest) DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException) Objects(java.util.Objects) EnrichmentResultList(eu.europeana.enrichment.api.external.model.EnrichmentResultList) MalformedURLException(java.net.MalformedURLException) DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException)

Example 3 with DereferenceException

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);
}
Also used : DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException) RecordProcessingException(eu.europeana.metis.sandbox.common.exception.RecordProcessingException) SerializationException(eu.europeana.metis.schema.convert.SerializationException) RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) RecordError(eu.europeana.metis.sandbox.domain.RecordError) EnrichmentException(eu.europeana.enrichment.rest.client.exceptions.EnrichmentException) LinkedList(java.util.LinkedList)

Example 4 with DereferenceException

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());
}
Also used : InputStream(java.io.InputStream) EnrichmentException(eu.europeana.enrichment.rest.client.exceptions.EnrichmentException) EnrichmentException(eu.europeana.enrichment.rest.client.exceptions.EnrichmentException) SerializationException(eu.europeana.metis.schema.convert.SerializationException) DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException) Test(org.junit.jupiter.api.Test)

Example 5 with DereferenceException

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);
}
Also used : RemoteEntityResolver(eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver) MalformedURLException(java.net.MalformedURLException) DereferenceException(eu.europeana.enrichment.rest.client.exceptions.DereferenceException) URL(java.net.URL) EntityMergeEngine(eu.europeana.enrichment.utils.EntityMergeEngine)

Aggregations

DereferenceException (eu.europeana.enrichment.rest.client.exceptions.DereferenceException)9 EnrichmentException (eu.europeana.enrichment.rest.client.exceptions.EnrichmentException)6 SerializationException (eu.europeana.metis.schema.convert.SerializationException)3 RDF (eu.europeana.metis.schema.jibx.RDF)3 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.jupiter.api.Test)2 StormTaskTuple (eu.europeana.cloud.service.dps.storm.StormTaskTuple)1 EnrichmentResultList (eu.europeana.enrichment.api.external.model.EnrichmentResultList)1 Mode (eu.europeana.enrichment.rest.client.EnrichmentWorker.Mode)1 EnrichmentWorkerImpl (eu.europeana.enrichment.rest.client.EnrichmentWorkerImpl)1 DereferencerProvider (eu.europeana.enrichment.rest.client.dereference.DereferencerProvider)1 EnricherProvider (eu.europeana.enrichment.rest.client.enrichment.EnricherProvider)1 RemoteEntityResolver (eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver)1 EntityMergeEngine (eu.europeana.enrichment.utils.EntityMergeEngine)1 RecordProcessingException (eu.europeana.metis.sandbox.common.exception.RecordProcessingException)1 RecordError (eu.europeana.metis.sandbox.domain.RecordError)1 RecordInfo (eu.europeana.metis.sandbox.domain.RecordInfo)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1