Skip to content

Commit

Permalink
small improvements for aggeratesFrom and aggregatedVia fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Jan 29, 2024
1 parent a020817 commit d6eccbd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.RELATED;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.RELATED_MATCH;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;
import eu.europeana.entitymanagement.vocabulary.EntityTypes;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;
import eu.europeana.entitymanagement.vocabulary.EntityTypes;

@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({
Expand Down Expand Up @@ -85,7 +84,7 @@ public Concept(Concept copy) {
if (copy.getCloseMatch() != null) this.closeMatch = new ArrayList<>(copy.getCloseMatch());
if (copy.getInScheme() != null) this.inScheme = new ArrayList<>(copy.getInScheme());
if (copy.getNotation() != null) this.notation = new HashMap<>(copy.getNotation());
if (copy.getSameReferenceLinks() != null) this.exactMatch = (new ArrayList<>(copy.getSameReferenceLinks()));
if (copy.exactMatch != null) this.exactMatch = (new ArrayList<>(copy.exactMatch));
}

@JsonGetter(BROADER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
FOAF_PHONE,
FOAF_MBOX,
HAS_ADDRESS,
IDENTIFIER,
SAME_AS,
AGGREGATES_FROM,
AGGREGATED_VIA
AGGREGATED_VIA,
IDENTIFIER,
SAME_AS
})
public class Organization extends Entity {

Expand Down Expand Up @@ -101,7 +101,7 @@ public Organization(Organization copy) {
this.geographicLevel = new HashMap<>(copy.getGeographicLevel());
this.country = copy.getCountry();
if (copy.getAddress() != null) this.hasAddress = new Address(copy.getAddress());
if (copy.getSameReferenceLinks() != null) this.sameAs = (new ArrayList<>(copy.getSameReferenceLinks()));
if (copy.sameAs != null) this.sameAs = (new ArrayList<>(copy.sameAs));
if (copy.getLanguage() != null) this.language = (new ArrayList<>(copy.getLanguage()));
if (copy.getAggregatesFrom() != null) this.aggregatesFrom = (new ArrayList<>(copy.getAggregatesFrom()));
if (copy.getAggregatedVia() != null) this.aggregatedVia = (new ArrayList<>(copy.getAggregatedVia()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Place(Place copy) {
this.latitude = copy.getLatitude();
this.longitude = copy.getLongitude();
this.altitude = copy.getAltitude();
if (copy.getSameReferenceLinks() != null) this.sameAs = (new ArrayList<>(copy.getSameReferenceLinks()));
if (copy.sameAs != null) this.sameAs = (new ArrayList<>(copy.sameAs));
}

public Place() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
XML_PHONE,
XML_MBOX,
XML_HAS_ADDRESS,
XML_AGGREGATED_VIA,
IS_AGGREGATED_BY,
XML_IDENTIFIER,
XML_SAME_AS,
XML_AGGREGATES_FROM,
XML_AGGREGATED_VIA,
IS_AGGREGATED_BY
XML_AGGREGATES_FROM
})
public class XmlOrganizationImpl extends XmlBaseEntityImpl<Organization> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
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_AGGREGATED_VIA;
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;
import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_SAME_AS;
import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_AGGREGATED_VIA;
import static eu.europeana.entitymanagement.mongo.utils.MorphiaUtils.MULTI_UPDATE_OPTS;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -20,13 +20,11 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import com.mongodb.client.result.UpdateResult;
import dev.morphia.aggregation.experimental.stages.Projection;
import dev.morphia.query.FindOptions;
import dev.morphia.query.Query;
import dev.morphia.query.experimental.filters.Filter;
import dev.morphia.query.experimental.updates.UpdateOperators;
import eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants;
import eu.europeana.entitymanagement.definitions.EntityRecordFields;
import eu.europeana.entitymanagement.definitions.model.EntityIdGenerator;
import eu.europeana.entitymanagement.definitions.model.EntityRecord;
import eu.europeana.entitymanagement.definitions.web.EntityIdDisabledStatus;
Expand Down Expand Up @@ -170,13 +168,14 @@ public List<EntityRecord> findEntitiesByCoreference(
}

public List<String> findAggregatesFrom(String entityId) {
Query<EntityRecord> query =
List<EntityRecord> entityRecords =
getDataStore()
.find(EntityRecord.class)
.disableValidation()
.filter(in(ENTITY_AGGREGATED_VIA, Arrays.asList(entityId)));
.filter(in(ENTITY_AGGREGATED_VIA, Arrays.asList(entityId)))
.iterator(new FindOptions().projection().include(ENTITY_ID))
.toList();

List<EntityRecord> entityRecords = query.iterator(new FindOptions().projection().include(ENTITY_ID)).toList();
return entityRecords.stream().map(entityRecord -> entityRecord.getEntityId()).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ public List<EntityRecord> retrieveMultipleByEntityIds(List<String> entityIds,
//for the organizations, populate the aggregatesFrom field
if(fetchFullRecord && !resp.isEmpty()) {
for(EntityRecord record : resp) {
if(EntityTypes.Organization.getEntityType().equals(record.getEntity().getType())) {
Organization org = (Organization) record.getEntity();
org.setAggregatesFrom(entityRecordRepository.findAggregatesFrom(record.getEntityId()));
}
setAggregatesFromForOrganizations(record.getEntity());
}
}

Expand Down Expand Up @@ -156,14 +153,18 @@ public EntityRecord retrieveEntityRecord(String entityUri, boolean retrieveDisab
}

//for the organizations, populate the aggregatesFrom field
if(EntityTypes.Organization.getEntityType().equals(entityRecord.getEntity().getType())) {
Organization org = (Organization) entityRecord.getEntity();
org.setAggregatesFrom(entityRecordRepository.findAggregatesFrom(entityUri));
}
setAggregatesFromForOrganizations(entityRecord.getEntity());

return entityRecord;
}

private void setAggregatesFromForOrganizations(Entity entity) {
if(EntityTypes.Organization.getEntityType().equals(entity.getType())) {
Organization org = (Organization) entity;
org.setAggregatesFrom(entityRecordRepository.findAggregatesFrom(entity.getEntityId()));
}
}

/**
* Handle the redirection in the case that the requested entity is not found by searching within the corefs
* This method allows redirection for old organization ids (which used the zoho identifier before)
Expand Down

0 comments on commit d6eccbd

Please sign in to comment.