Search in sources :

Example 1 with RemoteEntityResolver

use of eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver in project metis-framework by europeana.

the class DereferencerImplTest method testDereferencerNullFlow.

@Test
void testDereferencerNullFlow() throws DereferenceException {
    // Create mocks of the dependencies
    final RemoteEntityResolver remoteEntityResolver = mock(RemoteEntityResolver.class);
    final DereferenceClient dereferenceClient = mock(DereferenceClient.class);
    final EntityMergeEngine entityMergeEngine = mock(EntityMergeEngine.class);
    // Create dereferencer.
    final Dereferencer dereferencer = spy(new DereferencerImpl(entityMergeEngine, remoteEntityResolver, dereferenceClient));
    doReturn(Arrays.stream(new String[0]).collect(Collectors.toSet())).when(dereferencer).extractReferencesForDereferencing(any());
    final RDF inputRdf = new RDF();
    dereferencer.dereference(inputRdf);
    verifyDereferenceNullFlow(dereferenceClient, dereferencer, inputRdf);
    verifyMergeNullFlow(entityMergeEngine);
}
Also used : RemoteEntityResolver(eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver) RDF(eu.europeana.metis.schema.jibx.RDF) EntityMergeEngine(eu.europeana.enrichment.utils.EntityMergeEngine) Test(org.junit.jupiter.api.Test)

Example 2 with RemoteEntityResolver

use of eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver 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)

Example 3 with RemoteEntityResolver

use of eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver in project metis-framework by europeana.

the class DereferencerImplTest method testDereferencerHappyFlow.

@Test
void testDereferencerHappyFlow() throws DereferenceException {
    // Create mocks of the dependencies
    final RemoteEntityResolver remoteEntityResolver = mock(RemoteEntityResolver.class);
    doReturn(ENRICHMENT_RESULT).when(remoteEntityResolver).resolveByText(anySet());
    final DereferenceClient dereferenceClient = mock(DereferenceClient.class);
    doReturn(DEREFERENCE_RESULT.get(0), DEREFERENCE_RESULT.subList(1, DEREFERENCE_RESULT.size()).toArray()).when(dereferenceClient).dereference(any());
    final EntityMergeEngine entityMergeEngine = mock(EntityMergeEngine.class);
    final Dereferencer dereferencer = spy(new DereferencerImpl(entityMergeEngine, remoteEntityResolver, dereferenceClient));
    doReturn(Arrays.stream(DEREFERENCE_EXTRACT_RESULT).collect(Collectors.toSet())).when(dereferencer).extractReferencesForDereferencing(any());
    final RDF inputRdf = new RDF();
    dereferencer.dereference(inputRdf);
    verifyDereferenceHappyFlow(dereferenceClient, dereferencer, inputRdf);
    verifyMergeHappyFlow(entityMergeEngine);
}
Also used : RemoteEntityResolver(eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver) RDF(eu.europeana.metis.schema.jibx.RDF) EntityMergeEngine(eu.europeana.enrichment.utils.EntityMergeEngine) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteEntityResolver (eu.europeana.enrichment.rest.client.enrichment.RemoteEntityResolver)3 EntityMergeEngine (eu.europeana.enrichment.utils.EntityMergeEngine)3 RDF (eu.europeana.metis.schema.jibx.RDF)2 Test (org.junit.jupiter.api.Test)2 DereferenceException (eu.europeana.enrichment.rest.client.exceptions.DereferenceException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1