Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal uris moved to properties #237

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public class EntityManagementConfiguration {
@Value("${zoho.sync.batch.size: 100}")
private int zohoSyncBatchSize;

@Value("${entitymanagement.base.data.europeana.uri}")
private String baseDataEuropeanaUri;

public EntityManagementConfiguration() {
LOG.info("Initializing EntityManagementConfiguration bean as: configuration");
}
Expand Down Expand Up @@ -253,4 +256,8 @@ public String getZohoSyncOwnerFilter() {
public int getZohoSyncBatchSize() {
return zohoSyncBatchSize;
}

public String getBaseDataEuropeanaUri() {
return baseDataEuropeanaUri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_EXACT_MATCH;
import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_SAME_AS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.BASE_DATA_EUROPEANA_URI;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;

import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down Expand Up @@ -107,9 +106,9 @@ public Date getModified() {
return this.modified;
}

public EntityProxy getEuropeanaProxy() {
public EntityProxy getEuropeanaProxy(String baseDataEuropeanaUri) {
return proxies.stream()
.filter(s -> s.getProxyId().startsWith(BASE_DATA_EUROPEANA_URI))
.filter(s -> s.getProxyId().startsWith(baseDataEuropeanaUri))
.findFirst()
.orElse(null);
}
Expand All @@ -132,15 +131,15 @@ EntityProxy getProxyByHost(String host_name) {
.orElse(null);
}

public List<EntityProxy> getExternalProxies() {
public List<EntityProxy> getExternalProxies(String baseDataEuropeanaUri) {
return proxies.stream()
.filter(s -> !s.getProxyId().startsWith(BASE_DATA_EUROPEANA_URI))
.filter(s -> !s.getProxyId().startsWith(baseDataEuropeanaUri))
.collect(Collectors.toList());
}

public List<String> getExternalProxyIds() {
public List<String> getExternalProxyIds(String baseDataEuropeanaUri) {
return proxies.stream()
.filter(s -> !s.getProxyId().startsWith(BASE_DATA_EUROPEANA_URI))
.filter(s -> !s.getProxyId().startsWith(baseDataEuropeanaUri))
.map(EntityProxy::getProxyId)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package eu.europeana.entitymanagement.normalization;

import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.*;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.BASE_DATA_EUROPEANA_URI;
import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.FIELD_TYPE_DATE;
import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.FIELD_TYPE_TEXT;
import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.FIELD_TYPE_TEXT_OR_URI;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.BEGIN;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DATE_OF_BIRTH;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DATE_OF_DEATH;
Expand Down Expand Up @@ -71,7 +72,7 @@ public EntityFieldsCleaner(LanguageCodes emLanguageCodes, String thumbnailBaseUr
}

@SuppressWarnings("unchecked")
public void cleanAndNormalize(Entity entity) {
public void cleanAndNormalize(Entity entity, String baseDataEuropeanaUri) {
List<Field> entityFields = EntityUtils.getAllFields(entity.getClass());

try {
Expand Down Expand Up @@ -112,7 +113,8 @@ public void cleanAndNormalize(Entity entity) {
Map normalized = normalizeMapField(field, (Map) fieldValue);
entity.setFieldValue(field, normalized);
} else if (WebResource.class.isAssignableFrom(fieldType)) {
entity.setFieldValue(field, normalizeWebResource((WebResource) fieldValue));
entity.setFieldValue(
field, normalizeWebResource((WebResource) fieldValue, baseDataEuropeanaUri));
}
}
} catch (IllegalArgumentException
Expand All @@ -126,13 +128,14 @@ public void cleanAndNormalize(Entity entity) {
}
}

private WebResource normalizeWebResource(WebResource existingFieldValue) {
private WebResource normalizeWebResource(
WebResource existingFieldValue, String baseDataEuropeanaUri) {
WebResource webResource = new WebResource(existingFieldValue);

// generate missing thumbnail for Europeana resources
if (StringUtils.isEmpty(webResource.getThumbnail())
&& StringUtils.isNotBlank(webResource.getSource())
&& webResource.getSource().startsWith(BASE_DATA_EUROPEANA_URI)) {
&& webResource.getSource().startsWith(baseDataEuropeanaUri)) {
webResource.setThumbnail(
thumbnailBaseUrl + URLEncoder.encode(webResource.getId(), StandardCharsets.UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.europeana.entitymanagement.utils;

import eu.europeana.entitymanagement.vocabulary.EntityTypes;
import eu.europeana.entitymanagement.vocabulary.WebEntityFields;
import org.apache.commons.lang3.StringUtils;

public class EntityRecordUtils {
Expand All @@ -10,22 +9,24 @@ private EntityRecordUtils() {
// private constructor to prevent instantiation
}

public static String buildEntityIdUri(EntityTypes type, String identifier) {
return buildEntityIdUri(type.getEntityType(), identifier);
public static String buildEntityIdUri(
EntityTypes type, String identifier, String baseDataEuropeanaUri) {
return buildEntityIdUri(type.getEntityType(), identifier, baseDataEuropeanaUri);
}

public static String buildEntityIdUri(String type, String identifier) {
public static String buildEntityIdUri(
String type, String identifier, String baseDataEuropeanaUri) {
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append(WebEntityFields.BASE_DATA_EUROPEANA_URI);
stringBuilder.append(baseDataEuropeanaUri);
if (StringUtils.isNotEmpty(type)) stringBuilder.append(type.toLowerCase()).append("/");
if (StringUtils.isNotEmpty(identifier)) stringBuilder.append(identifier);

return stringBuilder.toString();
}

public static String extractIdentifierFromEntityId(String entityId) {
return entityId.replace(WebEntityFields.BASE_DATA_EUROPEANA_URI, "");
public static String extractIdentifierFromEntityId(String entityId, String baseDataEuropeanaUri) {
return entityId.replace(baseDataEuropeanaUri, "");
}

public static String getEuropeanaAggregationId(String entityId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface WebEntityFields {
public static final String ENTITY_CONTEXT =
"http://www.europeana.eu/schemas/context/entity.jsonld";
public static final String LANGUAGE_EN = "en";
public static final String BASE_DATA_EUROPEANA_URI = "http://data.europeana.eu/";
// public static final String BASE_DATA_EUROPEANA_URI = "http://data.europeana.eu/";
public static final String WIKIDATA_HOST = "www.wikidata.org";
public static final String ZOHO_CRM_HOST = "crm.zoho.com";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.europeana.entitymanagement.batch.service.EntityUpdateService;
import eu.europeana.entitymanagement.common.config.AppConfigConstants;
import eu.europeana.entitymanagement.common.config.DataSource;
import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration;
import eu.europeana.entitymanagement.config.DataSources;
import eu.europeana.entitymanagement.definitions.model.Entity;
import eu.europeana.entitymanagement.definitions.model.EntityRecord;
Expand Down Expand Up @@ -75,6 +76,8 @@ public abstract class AbstractIntegrationTest {

@Autowired protected EntityRecordService entityRecordService;

@Autowired protected EntityManagementConfiguration emConfiguration;

@BeforeAll
public static void setupAll() throws IOException {
mockMetis = new MockWebServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void changeProvenanceShouldBeSuccessful() throws Exception {
europeanaMetadata, metisResponse, IntegrationTestUtils.AGENT_JAN_VERMEER_VIAF_URI);

// assert content of default External proxy
EntityProxy externalProxy = savedRecord.getExternalProxies().get(0);
EntityProxy externalProxy =
savedRecord.getExternalProxies(emConfiguration.getBaseDataEuropeanaUri()).get(0);

Assertions.assertEquals(
IntegrationTestUtils.AGENT_JAN_VERMEER_VIAF_URI, externalProxy.getProxyId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public void registerZohoOrganizationGFMShouldBeSuccessful() throws Exception {
String expectedId =
EntityRecordUtils.buildEntityIdUri(
"organization",
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_GFM_URI_ZOHO));
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_GFM_URI_ZOHO),
emConfiguration.getBaseDataEuropeanaUri());

ResultActions response =
mockMvc.perform(
Expand Down Expand Up @@ -282,7 +283,8 @@ public void registerZohoOrganizationBergerShouldBeSuccessful() throws Exception
EntityRecordUtils.buildEntityIdUri(
"organization",
EntityRecordUtils.getIdFromUrl(
IntegrationTestUtils.ORGANIZATION_BERGER_MUSEUM_URI_ZOHO));
IntegrationTestUtils.ORGANIZATION_BERGER_MUSEUM_URI_ZOHO),
emConfiguration.getBaseDataEuropeanaUri());

ResultActions response =
mockMvc.perform(
Expand Down Expand Up @@ -325,7 +327,8 @@ void registerZohoOrganizationWithoutWikidataSameAsShouldBeSuccessful() throws Ex
String expectedId =
EntityRecordUtils.buildEntityIdUri(
"organization",
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_PCCE_URI_ZOHO));
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_PCCE_URI_ZOHO),
emConfiguration.getBaseDataEuropeanaUri());

ResultActions response =
mockMvc.perform(
Expand Down Expand Up @@ -357,7 +360,8 @@ void registerZohoOrganizationWithoutWikidataSameAsShouldBeSuccessful() throws Ex
void registerZohoOrganizationBnfWithNewFieldsShouldBeSuccessful() throws Exception {
EntityRecordUtils.buildEntityIdUri(
"organization",
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_BNF_URI_ZOHO));
EntityRecordUtils.getIdFromUrl(IntegrationTestUtils.ORGANIZATION_BNF_URI_ZOHO),
emConfiguration.getBaseDataEuropeanaUri());

ResultActions response =
mockMvc.perform(
Expand All @@ -381,7 +385,10 @@ public void registrationForExistingCoreferenceShouldReturn301() throws Exception
createEntity(europeanaMetadata, metisResponse, IntegrationTestUtils.CONCEPT_BATHTUB_URI)
.getEntityId();
String redirectUrl =
String.format("/entity/%s", EntityRecordUtils.extractIdentifierFromEntityId(entityId));
String.format(
"/entity/%s",
EntityRecordUtils.extractIdentifierFromEntityId(
entityId, emConfiguration.getBaseDataEuropeanaUri()));

mockMvc
.perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,30 @@ void updateConceptShouldBeSuccessful() throws Exception {
Assertions.assertTrue(entityRecordUpdated.isPresent());
Assertions.assertEquals(
nodeReference.path("depiction").path("id").asText(),
entityRecordUpdated.get().getEuropeanaProxy().getEntity().getDepiction().getId());
entityRecordUpdated
.get()
.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri())
.getEntity()
.getDepiction()
.getId());
Assertions.assertEquals(
nodeReference.path("note").path("en").path(0).asText(),
entityRecordUpdated.get().getEuropeanaProxy().getEntity().getNote().get("en").get(0));
entityRecordUpdated
.get()
.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri())
.getEntity()
.getNote()
.get("en")
.get(0));
// acquire the reader for the right type
ObjectReader reader = mapper.readerFor(new TypeReference<Map<String, String>>() {});
Map<String, String> prefLabelToCheck = reader.readValue(nodeReference.path("prefLabel"));
Map<String, String> prefLabelUpdated =
entityRecordUpdated.get().getEuropeanaProxy().getEntity().getPrefLabel();
entityRecordUpdated
.get()
.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri())
.getEntity()
.getPrefLabel();
for (Map.Entry<String, String> prefLabelEntry : prefLabelToCheck.entrySet()) {
Assertions.assertTrue(prefLabelUpdated.containsKey(prefLabelEntry.getKey()));
Assertions.assertTrue(prefLabelUpdated.containsValue(prefLabelEntry.getValue()));
Expand All @@ -171,7 +186,8 @@ void updatePUTShouldReplaceEuropeanaProxy() throws Exception {
EntityRecord savedRecord = createConcept();

// assert content of Europeana proxy
Entity europeanaProxyEntity = savedRecord.getEuropeanaProxy().getEntity();
Entity europeanaProxyEntity =
savedRecord.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri()).getEntity();

// values match labels in json file
Assertions.assertNotNull(europeanaProxyEntity.getPrefLabel().get("en"));
Expand All @@ -191,7 +207,11 @@ void updatePUTShouldReplaceEuropeanaProxy() throws Exception {
// check that update removed fields from Europeana proxy in original request
Optional<EntityRecord> updatedRecord = retrieveEntity(savedRecord.getEntityId());
Assertions.assertTrue(updatedRecord.isPresent());
europeanaProxyEntity = updatedRecord.get().getEuropeanaProxy().getEntity();
europeanaProxyEntity =
updatedRecord
.get()
.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri())
.getEntity();

Assertions.assertNull(europeanaProxyEntity.getPrefLabel());
Assertions.assertNull(europeanaProxyEntity.getAltLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.europeana.api.commons.error.EuropeanaApiException;
import eu.europeana.entitymanagement.common.config.DataSource;
import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration;
import eu.europeana.entitymanagement.config.DataSources;
import eu.europeana.entitymanagement.definitions.model.Entity;
import eu.europeana.entitymanagement.definitions.model.EntityProxy;
Expand Down Expand Up @@ -34,22 +35,26 @@ public class EntityConsolidationProcessor implements ItemProcessor<EntityRecord,

private final EntityFieldsCleaner emEntityFieldCleaner;
private final DataSources datasources;
private final EntityManagementConfiguration emConfiguration;

public EntityConsolidationProcessor(
EntityRecordService entityRecordService,
ValidatorFactory emValidatorFactory,
EntityFieldsCleaner emEntityFieldCleaner,
DataSources datasources) {
DataSources datasources,
EntityManagementConfiguration emConfiguration) {
this.entityRecordService = entityRecordService;
this.emValidatorFactory = emValidatorFactory;
this.emEntityFieldCleaner = emEntityFieldCleaner;
this.datasources = datasources;
this.emConfiguration = emConfiguration;
}

@Override
public EntityRecord process(@NonNull EntityRecord entityRecord) throws EuropeanaApiException {

List<EntityProxy> externalProxies = entityRecord.getExternalProxies();
List<EntityProxy> externalProxies =
entityRecord.getExternalProxies(emConfiguration.getBaseDataEuropeanaUri());

Entity externalProxyEntity = externalProxies.get(0).getEntity();
String proxyId = externalProxies.get(0).getProxyId();
Expand All @@ -73,7 +78,8 @@ public EntityRecord process(@NonNull EntityRecord entityRecord) throws Europeana
}
}

Entity europeanaProxyEntity = entityRecord.getEuropeanaProxy().getEntity();
Entity europeanaProxyEntity =
entityRecord.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri()).getEntity();

Entity consolidatedEntity = null;
if (isStaticDataSource) {
Expand All @@ -88,7 +94,8 @@ public EntityRecord process(@NonNull EntityRecord entityRecord) throws Europeana
consolidatedEntity,
externalProxies.stream().map(EntityProxy::getProxyId).collect(Collectors.toList()));

emEntityFieldCleaner.cleanAndNormalize(consolidatedEntity);
emEntityFieldCleaner.cleanAndNormalize(
consolidatedEntity, emConfiguration.getBaseDataEuropeanaUri());
entityRecordService.performReferentialIntegrity(consolidatedEntity);
validateCompleteValidationConstraints(consolidatedEntity);
entityRecordService.updateConsolidatedVersion(entityRecord, consolidatedEntity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.europeana.entitymanagement.batch.processor;

import eu.europeana.entitymanagement.common.config.DataSource;
import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration;
import eu.europeana.entitymanagement.config.DataSources;
import eu.europeana.entitymanagement.definitions.model.Entity;
import eu.europeana.entitymanagement.definitions.model.EntityProxy;
Expand Down Expand Up @@ -36,25 +37,31 @@ public class EntityDereferenceProcessor implements ItemProcessor<EntityRecord, E
private final DereferenceServiceLocator dereferenceServiceLocator;
private final DataSources datasources;
private final EntityRecordService entityRecordService;
private final EntityManagementConfiguration emConfiguration;

@Autowired
public EntityDereferenceProcessor(
DereferenceServiceLocator dereferenceServiceLocator,
DataSources datasources,
EntityRecordService entityRecordService) {
EntityRecordService entityRecordService,
EntityManagementConfiguration emConfiguration) {
this.dereferenceServiceLocator = dereferenceServiceLocator;
this.datasources = datasources;
this.entityRecordService = entityRecordService;
this.emConfiguration = emConfiguration;
}

@Override
public EntityRecord process(@NonNull EntityRecord entityRecord) throws Exception {

// might be multiple wikidata IDs in case of redirections
TreeSet<String> wikidataEntityIds = new TreeSet<>();
collectWikidataEntityIds(entityRecord.getEuropeanaProxy().getEntity(), wikidataEntityIds);
collectWikidataEntityIds(
entityRecord.getEuropeanaProxy(emConfiguration.getBaseDataEuropeanaUri()).getEntity(),
wikidataEntityIds);

for (EntityProxy externalProxy : entityRecord.getExternalProxies()) {
for (EntityProxy externalProxy :
entityRecord.getExternalProxies(emConfiguration.getBaseDataEuropeanaUri())) {
Optional<DataSource> dataSource = datasources.getDatasource(externalProxy.getProxyId());
if (dataSource.isPresent() && dataSource.get().isStatic()) {
// do not update external proxy for static data sources
Expand Down
Loading