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