From 9e5dec64699642088bcb40bd88883ea883f398bf Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Mon, 4 Mar 2024 15:08:31 +0100 Subject: [PATCH 1/3] 1) org country improved to contain only id, type, and prefLabel; 2) multiple retrieval improved to handle old org ids --- .../definitions/EntityRecordFields.java | 2 + .../web/xml/model/XmlEdmCountry.java | 56 +++++++++++++++++++ .../web/xml/model/XmlOrganizationImpl.java | 6 +- .../repository/EntityRecordRepository.java | 48 +++++++--------- .../mongo/EntityRecordRepositoryIT.java | 17 +++--- .../web/EntityMultipleRetrievalIT.java | 28 +++++++++- .../web/EntityRetrievalIT.java | 4 +- .../organization_register_zoho_gfm.json | 5 +- .../entitymanagement/web/EMController.java | 11 ++-- .../web/service/BaseEntityRecordService.java | 2 +- .../web/service/EntityRecordService.java | 16 ++++-- 11 files changed, 139 insertions(+), 56 deletions(-) create mode 100644 entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java index 46edc52d1..6d4cc1368 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java @@ -16,4 +16,6 @@ private EntityRecordFields() { public static final String ENTITY_SAME_AS = "entity.sameAs"; public static final String ENTITY_EXACT_MATCH = "entity.exactMatch"; public static final String ENTITY_TYPE = "entity.type"; + public static final String ENTITY_ENTITY_ID = "entity.entityId"; + public static final String ENTITY_PREF_LABEL = "entity.prefLabel"; } diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java new file mode 100644 index 000000000..4ed2ffe37 --- /dev/null +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java @@ -0,0 +1,56 @@ +package eu.europeana.entitymanagement.web.xml.model; + +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.ABOUT; +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_EDM; +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_RDF; +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.PREF_LABEL; +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PLACE; +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import eu.europeana.entitymanagement.definitions.model.Place; + +@XmlRootElement(namespace = NAMESPACE_EDM, name = XML_PLACE) +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType( + propOrder = { + ABOUT, + PREF_LABEL + }) +public class XmlEdmCountry { + + @XmlAttribute(namespace = NAMESPACE_RDF, name = XmlConstants.RESOURCE) + private String about; + + @XmlElement(namespace = XmlConstants.NAMESPACE_SKOS, name = PREF_LABEL) + private List prefLabel = new ArrayList<>(); + + public XmlEdmCountry(Place place) { + this.about=place.getAbout(); + this.prefLabel= RdfXmlUtils.convertMapToXmlMultilingualString(place.getPrefLabel()); + } + + public XmlEdmCountry() { + } + + public String getAbout() { + return this.about; + } + + public void setAbout(String about) { + this.about = about; + } + + public List getPrefLabel() { + return this.prefLabel; + } + + public void setPrefLabel(List prefLabel) { + this.prefLabel=prefLabel; + } +} diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java index fd7114c88..5a3e67a99 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java @@ -79,7 +79,7 @@ public class XmlOrganizationImpl extends XmlBaseEntityImpl { private List europeanaRole = new ArrayList<>(); @XmlElement(namespace = NAMESPACE_EDM, name = XML_COUNTRY) - private XmlPlaceImpl country; + private XmlEdmCountry country; @XmlElement(namespace = NAMESPACE_FOAF, name = XML_HOMEPAGE) private LabelledResource homepage; @@ -122,7 +122,7 @@ public XmlOrganizationImpl(Organization organization) { } if(organization.getCountry() != null) { - this.country = new XmlPlaceImpl(organization.getCountry()); + this.country = new XmlEdmCountry(organization.getCountry()); } if (organization.getHomepage() != null) { @@ -198,7 +198,7 @@ public List getEuropeanaRole() { return europeanaRole; } - public XmlPlaceImpl getCountry() { + public XmlEdmCountry getCountry() { return country; } diff --git a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java index 372358858..fc2260d7b 100644 --- a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java +++ b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java @@ -6,7 +6,6 @@ import static dev.morphia.query.experimental.filters.Filters.ne; import static dev.morphia.query.experimental.filters.Filters.or; import static eu.europeana.entitymanagement.definitions.EntityRecordFields.DISABLED; -import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY; import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_EXACT_MATCH; import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_ID; import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_MODIFIED; @@ -87,34 +86,12 @@ public List findByEntityIds( } /** - * Find and return EntityRecord that matches the given parameters - * - * @param entityId ID of the dataset - * @return EntityRecord the database record - */ - public EntityRecord findByEntityId(String entityId) { - return findEntityRecord(entityId); - } - - /** - * Find and return EntityRecord that matches the given parameters - * - * @param entityId ID of the dataset - * @param consolidatedOnly if set to true, the retrieved record will only include the consolidated entity - * @return EntityRecord the database record - */ - public EntityRecord findByEntityId(String entityId, boolean consolidatedOnly) { - return consolidatedOnly ? findEntityRecord(entityId, ENTITY) : findEntityRecord(entityId); - } - - /** - * Find and return EntityRecord that matches the given parameters - * - * @param entityId ID of the dataset - * @param consolidatedOnly if set to true, the retrieved record will only include the consolidated entity - * @return EntityRecord the database record + * Find entity record with id, and pick only the given fields from the record + * @param entityId + * @param fields + * @return */ - protected EntityRecord findEntityRecord(String entityId, String... fields) { + public EntityRecord findEntityRecord(String entityId, String... fields) { Query query = getDataStore() .find(EntityRecord.class); @@ -205,6 +182,21 @@ public List findEntitiesByCoreference( return query.iterator().toList(); } + public List findByEntityIdsOrCoreference(List uris) { + // Get all EntityRecords that have the given uris as their entityId or in the sameAs/exactMatch field + List filters = new ArrayList<>(); + filters.add(or(in(ENTITY_ID, uris), in(ENTITY_SAME_AS, uris), in(ENTITY_EXACT_MATCH, uris))); + // Only fetch active records. Disabled records have a date value + filters.add(eq(DISABLED, null)); + + return getDataStore() + .find(EntityRecord.class) + .filter(filters.toArray(Filter[]::new)) + .iterator() + .toList(); + } + + public List saveBulk(List entityRecords) { return getDataStore().save(entityRecords); } diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/mongo/EntityRecordRepositoryIT.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/mongo/EntityRecordRepositoryIT.java index 9e9c3a456..3eda02277 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/mongo/EntityRecordRepositoryIT.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/mongo/EntityRecordRepositoryIT.java @@ -3,13 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; - -import eu.europeana.entitymanagement.AbstractIntegrationTest; -import eu.europeana.entitymanagement.definitions.model.Aggregation; -import eu.europeana.entitymanagement.definitions.model.EntityProxy; -import eu.europeana.entitymanagement.definitions.model.EntityRecord; -import eu.europeana.entitymanagement.definitions.model.TimeSpan; -import eu.europeana.entitymanagement.definitions.model.WebResource; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -19,6 +12,12 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import eu.europeana.entitymanagement.AbstractIntegrationTest; +import eu.europeana.entitymanagement.definitions.model.Aggregation; +import eu.europeana.entitymanagement.definitions.model.EntityProxy; +import eu.europeana.entitymanagement.definitions.model.EntityRecord; +import eu.europeana.entitymanagement.definitions.model.TimeSpan; +import eu.europeana.entitymanagement.definitions.model.WebResource; @SpringBootTest @AutoConfigureMockMvc @@ -32,7 +31,7 @@ public void setup() { @Test public void shouldCorrectlyInsertAndRetrieve() { EntityRecord savedRecord = createEntityRecord(); - EntityRecord retrievedRecord = entityRecordRepository.findByEntityId(savedRecord.getEntityId()); + EntityRecord retrievedRecord = entityRecordRepository.findEntityRecord(savedRecord.getEntityId()); assertEquals(retrievedRecord.getEntityId(), savedRecord.getEntityId()); @@ -45,7 +44,7 @@ void shouldDisableEntities() { EntityRecord savedRecord = createEntityRecord(); entityRecordRepository.disableBulk(List.of(savedRecord.getEntityId())); - EntityRecord retrievedRecord = entityRecordRepository.findByEntityId(savedRecord.getEntityId()); + EntityRecord retrievedRecord = entityRecordRepository.findEntityRecord(savedRecord.getEntityId()); assertTrue(retrievedRecord.isDisabled()); } diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityMultipleRetrievalIT.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityMultipleRetrievalIT.java index 339f2ec53..ce428e410 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityMultipleRetrievalIT.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityMultipleRetrievalIT.java @@ -5,14 +5,15 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import eu.europeana.entitymanagement.testutils.IntegrationTestUtils; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import com.zoho.crm.api.record.Record; +import eu.europeana.entitymanagement.testutils.IntegrationTestUtils; @SpringBootTest @AutoConfigureMockMvc @@ -69,6 +70,29 @@ void multipleEntitiesRetrievedSuccessfully() throws Exception { .andExpect(jsonPath("$.items.*.id", is(List.of(entityId3, entityId1, entityId2)))); } + @Test + void multipleEntitiesRetrieveOldOrganizationIds() throws Exception { + //register zoho GFM org with old id in sameAs + String europeanaMetadata = loadFile(IntegrationTestUtils.ORGANIZATION_REGISTER_GFM_ZOHO_JSON); + Optional zohoRecord = + IntegrationTestUtils.getZohoOrganizationRecord( + IntegrationTestUtils.ORGANIZATION_GFM_URI_ZOHO); + assert zohoRecord.isPresent() : "Mocked Zoho response not loaded"; + String entityId = createOrganization(europeanaMetadata, zohoRecord.get()).getEntityId(); + + //please check that this id is also in the sameAs of the org json file (IntegrationTestUtils.ORGANIZATION_REGISTER_GFM_ZOHO_JSON) + String oldId="http://data.europeana.eu/organization/486281000000940433"; + + mockMvc + .perform( + post(IntegrationTestUtils.BASE_SERVICE_URL + "/retrieve") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(List.of(oldId)))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.items.*.id", is(List.of(entityId)))); + + } + @Test void multipleEntitiesRetrievedNotFound() throws Exception { mockMvc diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRetrievalIT.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRetrievalIT.java index 7d2de0a7d..803f82b55 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRetrievalIT.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRetrievalIT.java @@ -524,6 +524,7 @@ public void retrieveOrganizationJsonExternalWithCountryAndRoleDereference() thro .andExpect(jsonPath("$.type", is(EntityTypes.Organization.getEntityType()))) .andExpect(jsonPath("$.sameAs").isNotEmpty()) .andExpect(jsonPath("$.country.prefLabel.en", is("Sweden"))) + .andExpect(jsonPath("$.country.latitude").doesNotExist()) //only the country prefLabel, id, and type should be present .andExpect(jsonPath("$.europeanaRole[0].prefLabel.en", is("Providing Institution"))); } @@ -603,7 +604,8 @@ public void retrieveOrganizationXmlExternalShouldBeSuccessful() throws Exception .andExpect(xpath(entityBaseXpath + "/@rdf:about", xmlNamespaces).string(entityId)) .andExpect( xpath(entityBaseXpath + "/skos:prefLabel", xmlNamespaces).nodeCount(greaterThan(0))) - .andExpect(xpath(entityBaseXpath + "/edm:countryPlace", xmlNamespaces).doesNotExist()); + .andExpect(xpath(entityBaseXpath + "/edm:country/@rdf:resource", xmlNamespaces).exists()) + .andExpect(xpath(entityBaseXpath + "/edm:country/skos:prefLabel", xmlNamespaces).doesNotExist()); } @Test diff --git a/entity-management-tests/src/integration-test/resources/content/organization_register_zoho_gfm.json b/entity-management-tests/src/integration-test/resources/content/organization_register_zoho_gfm.json index ba5e846a1..95c0990aa 100644 --- a/entity-management-tests/src/integration-test/resources/content/organization_register_zoho_gfm.json +++ b/entity-management-tests/src/integration-test/resources/content/organization_register_zoho_gfm.json @@ -1,4 +1,7 @@ { "type": "Organization", - "id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000000940433" + "id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000000940433", + "sameAs": [ + "http://data.europeana.eu/organization/486281000000940433" + ] } \ No newline at end of file diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java index 51d3f670a..cc7150bdb 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java @@ -638,7 +638,7 @@ private ResponseEntity createResponseForRetrieve(EntityTypes type, Strin private ResponseEntity createResponseMultipleEntities(List entityIds, HttpServletRequest request) throws EuropeanaApiException { List entityRecords = - entityRecordService.retrieveMultipleByEntityIds(entityIds, true, true); + entityRecordService.retrieveMultipleByEntityIdsOrCoreference(entityIds); if (entityRecords.isEmpty()) { throw new EntityNotFoundException(entityIds.toString()); } @@ -647,11 +647,10 @@ private ResponseEntity createResponseMultipleEntities(List entit // improves sort performance significantly Map sortedEntityRecordMap = new LinkedHashMap<>(entityIds.size()); for (String id : entityIds) { - sortedEntityRecordMap.put(id, null); - } - - for (EntityRecord entityRecord : entityRecords) { - sortedEntityRecordMap.replace(entityRecord.getEntityId(), entityRecord); + Optional recordIdMatched= entityRecords.stream().filter(er -> id.equals(er.getEntityId()) || er.getEntity().getSameReferenceLinks().contains(id)).findFirst(); + if(recordIdMatched.isPresent()) { + sortedEntityRecordMap.put(id, recordIdMatched.get()); + } } // create response headers diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/BaseEntityRecordService.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/BaseEntityRecordService.java index cb6c7dbf3..c4e924b80 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/BaseEntityRecordService.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/BaseEntityRecordService.java @@ -586,7 +586,7 @@ protected void processCountryReference(Organization org) { // replace wikidata country ids org.setCountryId(europeanaCountryId); // search reference - EntityRecord orgCountry = entityRecordRepository.findByEntityId(europeanaCountryId); + EntityRecord orgCountry = entityRecordRepository.findEntityRecord(europeanaCountryId); if (orgCountry != null) { org.setCountryRef(orgCountry); } else if (logger.isWarnEnabled()) { diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java index c2758bd94..77f873ec7 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java @@ -4,7 +4,6 @@ import static eu.europeana.entitymanagement.utils.EntityRecordUtils.getDatasourceAggregationId; import static eu.europeana.entitymanagement.utils.EntityRecordUtils.getEuropeanaAggregationId; import static java.time.Instant.now; -import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; @@ -24,6 +23,7 @@ import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration; import eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants; import eu.europeana.entitymanagement.config.DataSources; +import eu.europeana.entitymanagement.definitions.EntityRecordFields; import eu.europeana.entitymanagement.definitions.exceptions.EntityModelCreationException; import eu.europeana.entitymanagement.definitions.exceptions.UnsupportedEntityTypeException; import eu.europeana.entitymanagement.definitions.model.Agent; @@ -79,7 +79,7 @@ public boolean existsByEntityId(String entityId) { } public Optional retrieveByEntityId(String entityId) { - return Optional.ofNullable(entityRecordRepository.findByEntityId(entityId)); + return Optional.ofNullable(entityRecordRepository.findEntityRecord(entityId)); } /** @@ -94,6 +94,10 @@ public List retrieveMultipleByEntityIds(List entityIds, boolean excludeDisabled, boolean fetchFullRecord) { return entityRecordRepository.findByEntityIds(entityIds, excludeDisabled, fetchFullRecord); } + + public List retrieveMultipleByEntityIdsOrCoreference(List entityIds) { + return entityRecordRepository.findByEntityIdsOrCoreference(entityIds); + } public EntityRecord retrieveEntityRecord(EntityTypes type, String identifier, String profiles, boolean retrieveDisabled) throws EuropeanaApiException { @@ -132,10 +136,12 @@ void dereferenceLinkedEntities(EntityRecord entityRecord) { private void dereferenceLinkedEntities(Organization org) { // dereference country if (org.getCountryId() != null) { - EntityRecord countryRecord = entityRecordRepository.findByEntityId(org.getCountryId(), true); + EntityRecord countryRecord = entityRecordRepository.findEntityRecord(org.getCountryId(), EntityRecordFields.ENTITY); if (countryRecord != null) { - // fill in the country file with the retrieved entity - Place country = (Place) countryRecord.getEntity(); + // fill in only the chosen fields + Place country = new Place(); + country.setEntityId(countryRecord.getEntity().getEntityId()); + country.setPrefLabel(countryRecord.getEntity().getPrefLabel()); org.setCountry(country); } } From 57a7c58a3ce09e2b17a02846d0bc5e5c8ca3bbb5 Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Tue, 5 Mar 2024 16:43:39 +0100 Subject: [PATCH 2/3] some code refactorings --- .../definitions/EntityRecordFields.java | 2 -- .../web/xml/model/XmlEdmCountry.java | 24 +++++++++---------- .../web/xml/model/XmlOrganizationImpl.java | 2 +- .../repository/EntityRecordRepository.java | 2 +- .../entitymanagement/web/EMController.java | 15 +----------- .../web/service/EntityRecordService.java | 12 ++++++++-- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java index 6d4cc1368..46edc52d1 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/EntityRecordFields.java @@ -16,6 +16,4 @@ private EntityRecordFields() { public static final String ENTITY_SAME_AS = "entity.sameAs"; public static final String ENTITY_EXACT_MATCH = "entity.exactMatch"; public static final String ENTITY_TYPE = "entity.type"; - public static final String ENTITY_ENTITY_ID = "entity.entityId"; - public static final String ENTITY_PREF_LABEL = "entity.prefLabel"; } diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java index 4ed2ffe37..5bf2d7170 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlEdmCountry.java @@ -1,9 +1,9 @@ package eu.europeana.entitymanagement.web.xml.model; -import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.ABOUT; import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_EDM; import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_RDF; import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.PREF_LABEL; +import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.RESOURCE; import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PLACE; import java.util.ArrayList; import java.util.List; @@ -19,33 +19,25 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlType( propOrder = { - ABOUT, + RESOURCE, PREF_LABEL }) public class XmlEdmCountry { @XmlAttribute(namespace = NAMESPACE_RDF, name = XmlConstants.RESOURCE) - private String about; + private String resource; @XmlElement(namespace = XmlConstants.NAMESPACE_SKOS, name = PREF_LABEL) private List prefLabel = new ArrayList<>(); public XmlEdmCountry(Place place) { - this.about=place.getAbout(); + this.resource=place.getAbout(); this.prefLabel= RdfXmlUtils.convertMapToXmlMultilingualString(place.getPrefLabel()); } public XmlEdmCountry() { } - public String getAbout() { - return this.about; - } - - public void setAbout(String about) { - this.about = about; - } - public List getPrefLabel() { return this.prefLabel; } @@ -53,4 +45,12 @@ public List getPrefLabel() { public void setPrefLabel(List prefLabel) { this.prefLabel=prefLabel; } + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } } diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java index 5a3e67a99..1fac4b4d3 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/web/xml/model/XmlOrganizationImpl.java @@ -160,7 +160,7 @@ public Organization toEntityModel() throws EntityModelCreationException { //set country id (external dereferencers deliver only the ids, not transitive data) if(getCountry() != null) { //we need to extract the countryID as well (xml about holds the entityId) - entity.setCountryId(getCountry().getAbout()); + entity.setCountryId(getCountry().getResource()); } if (getHomepage() != null) { diff --git a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java index fc2260d7b..0bb32e5aa 100644 --- a/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java +++ b/entity-management-mongo/src/main/java/eu/europeana/entitymanagement/mongo/repository/EntityRecordRepository.java @@ -110,7 +110,7 @@ public EntityRecord findEntityRecord(String entityId, String... fields) { return query.first(); } } - + public List getEntityIds( List entityIds, boolean excludeDisabled) { List entityRecords = findByEntityIds(entityIds, excludeDisabled, false); diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java index cc7150bdb..bd062c3f1 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/EMController.java @@ -643,25 +643,12 @@ private ResponseEntity createResponseMultipleEntities(List entit throw new EntityNotFoundException(entityIds.toString()); } - // LinkedHashMap iterates keys() and values() in order of insertion. Using a map - // improves sort performance significantly - Map sortedEntityRecordMap = new LinkedHashMap<>(entityIds.size()); - for (String id : entityIds) { - Optional recordIdMatched= entityRecords.stream().filter(er -> id.equals(er.getEntityId()) || er.getEntity().getSameReferenceLinks().contains(id)).findFirst(); - if(recordIdMatched.isPresent()) { - sortedEntityRecordMap.put(id, recordIdMatched.get()); - } - } - // create response headers String contentType = HttpHeaders.CONTENT_TYPE_JSONLD_UTF8; org.springframework.http.HttpHeaders headers = createAllowHeader(request); headers.add(HttpHeaders.CONTENT_TYPE, contentType); - // remove null values in response - List responseBody = sortedEntityRecordMap.values().stream() - .filter(Objects::nonNull).collect(Collectors.toList()); - String body = serialize(responseBody); + String body = serialize(entityRecords); return ResponseEntity.status(HttpStatus.OK).headers(headers).body(body); } diff --git a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java index 77f873ec7..29c00c59e 100644 --- a/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java +++ b/entity-management-web/src/main/java/eu/europeana/entitymanagement/web/service/EntityRecordService.java @@ -96,7 +96,16 @@ public List retrieveMultipleByEntityIds(List entityIds, } public List retrieveMultipleByEntityIdsOrCoreference(List entityIds) { - return entityRecordRepository.findByEntityIdsOrCoreference(entityIds); + List records=entityRecordRepository.findByEntityIdsOrCoreference(entityIds); + //sorting the list in order of the input ids + List recordsSorted=new ArrayList<>(); + for (String id : entityIds) { + Optional recordIdMatched= records.stream().filter(er -> id.equals(er.getEntityId()) || er.getEntity().getSameReferenceLinks().contains(id)).findFirst(); + if(recordIdMatched.isPresent()) { + recordsSorted.add(recordIdMatched.get()); + } + } + return recordsSorted; } public EntityRecord retrieveEntityRecord(EntityTypes type, String identifier, String profiles, @@ -138,7 +147,6 @@ private void dereferenceLinkedEntities(Organization org) { if (org.getCountryId() != null) { EntityRecord countryRecord = entityRecordRepository.findEntityRecord(org.getCountryId(), EntityRecordFields.ENTITY); if (countryRecord != null) { - // fill in only the chosen fields Place country = new Place(); country.setEntityId(countryRecord.getEntity().getEntityId()); country.setPrefLabel(countryRecord.getEntity().getPrefLabel()); From bdc614b949ba8f8fd5b65ff796a7e86f670e8df4 Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Wed, 6 Mar 2024 12:06:30 +0100 Subject: [PATCH 3/3] europeana role fields order --- .../definitions/model/Vocabulary.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Vocabulary.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Vocabulary.java index 73e61fff9..6977edd8f 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Vocabulary.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Vocabulary.java @@ -1,7 +1,9 @@ package eu.europeana.entitymanagement.definitions.model; +import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID; import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IN_SCHEME; import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PREF_LABEL; +import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE; import java.util.Date; import java.util.List; import java.util.Map; @@ -10,6 +12,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonSetter; import dev.morphia.annotations.EntityListeners; import dev.morphia.annotations.Id; @@ -25,6 +28,12 @@ /** * class used for storing static vocabularies (e.g. europeana roles) */ +@JsonPropertyOrder({ + ID, + TYPE, + PREF_LABEL, + IN_SCHEME +}) public class Vocabulary { @Transient @@ -80,12 +89,12 @@ public String toString() { return String.format("Vocabulary.id: %s", getId()); } - @JsonGetter + @JsonGetter(ID) public String getId() { return id; } - @JsonSetter + @JsonSetter(ID) public void setId(String id) { this.id = id; } @@ -110,6 +119,7 @@ public void setPrefLabel(Map prefLabel) { this.prefLabel = prefLabel; } + @JsonGetter(TYPE) public String getType() { return type; }