Skip to content

Commit

Permalink
Merge pull request #314 from europeana/EA-3643-zoho-country-improve
Browse files Browse the repository at this point in the history
1) Merge branch 'develop' into EA-3643-zoho-country-improve; 2) improved
  • Loading branch information
gsergiu authored Mar 8, 2024
2 parents 3a72143 + b250355 commit aa7dae6
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 192 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eu.europeana.entitymanagement.web.xml.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import eu.europeana.entitymanagement.definitions.model.Place;

/**
* XML Serialization of the country organization field.
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlEdmCountryWrapper {

@XmlElement(namespace = XmlConstants.NAMESPACE_EDM, name = XmlConstants.XML_PLACE)
private XmlPlaceImpl place;

public XmlEdmCountryWrapper(Place place) {
this.place=new XmlPlaceImpl(place);
}

public XmlEdmCountryWrapper() {
}

public XmlPlaceImpl getPlace() {
return place;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package eu.europeana.entitymanagement.web.xml.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import eu.europeana.entitymanagement.definitions.model.Vocabulary;

/**
* XML Serialization of the europeanaRole organization field.
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlEdmEuropeanaRoleWrapper {

@XmlElement(namespace = XmlConstants.NAMESPACE_SKOS, name = XmlConstants.XML_CONCEPT)
private XmlConceptImpl concept;

public XmlEdmEuropeanaRoleWrapper(Vocabulary vocab) {
this.concept=new XmlConceptImpl();
this.concept.setAbout(vocab.getId());
this.concept.setPrefLabel(RdfXmlUtils.convertMapToXmlMultilingualString(vocab.getPrefLabel()));
this.concept.setInScheme(RdfXmlUtils.convertToRdfResource(vocab.getInScheme()));
}

public XmlEdmEuropeanaRoleWrapper() {
}

public XmlConceptImpl getConcept() {
return concept;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public class XmlOrganizationImpl extends XmlBaseEntityImpl<Organization> {
private XmlWebResourceWrapper logo;

@XmlElement(namespace = NAMESPACE_EDM, name = XML_EUROPEANA_ROLE)
private List<XmlEdmEuropeanaRole> europeanaRole = new ArrayList<>();
private List<XmlEdmEuropeanaRoleWrapper> europeanaRole = new ArrayList<>();

@XmlElement(namespace = NAMESPACE_EDM, name = XML_COUNTRY)
private XmlEdmCountry country;
private XmlEdmCountryWrapper country;

@XmlElement(namespace = NAMESPACE_FOAF, name = XML_HOMEPAGE)
private LabelledResource homepage;
Expand Down Expand Up @@ -110,16 +110,16 @@ public XmlOrganizationImpl(Organization organization) {
//set the europeanaRole
List<Vocabulary> orgRole=organization.getEuropeanaRole();
if(orgRole!=null && !orgRole.isEmpty()) {
List<XmlEdmEuropeanaRole> orgXmlRole= new ArrayList<>(orgRole.size());
List<XmlEdmEuropeanaRoleWrapper> orgXmlRole= new ArrayList<>(orgRole.size());
for(Vocabulary vocab : orgRole) {
XmlEdmEuropeanaRole xmlRole = new XmlEdmEuropeanaRole(vocab);
XmlEdmEuropeanaRoleWrapper xmlRole = new XmlEdmEuropeanaRoleWrapper(vocab);
orgXmlRole.add(xmlRole);
}
this.europeanaRole=orgXmlRole;
}

if(organization.getCountry() != null) {
this.country=new XmlEdmCountry(organization.getCountry());
this.country=new XmlEdmCountryWrapper(organization.getCountry());
}

if (organization.getHomepage() != null) {
Expand Down Expand Up @@ -150,13 +150,13 @@ public Organization toEntityModel() throws EntityModelCreationException {
entity.setLogo(XmlWebResourceWrapper.toWebResource(getLogo()));
//set europeanaRole id (external dereferencers deliver only the ids, not transitive data)
if(getEuropeanaRole()!=null && !getEuropeanaRole().isEmpty()) {
List<String> roleIds = getEuropeanaRole().stream().map(e -> e.getResource()).toList();
List<String> roleIds = getEuropeanaRole().stream().map(e -> e.getConcept().getAbout()).toList();
entity.setEuropeanaRoleIds(roleIds);
}

//set country id (external dereferencers deliver only the ids, not transitive data)
if(getCountry() != null) {
entity.setCountryId(getCountry().getResource());
entity.setCountryId(getCountry().getPlace().getAbout());
}

if (getHomepage() != null) {
Expand Down Expand Up @@ -190,11 +190,11 @@ public XmlWebResourceWrapper getLogo() {
return logo;
}

public List<XmlEdmEuropeanaRole> getEuropeanaRole() {
public List<XmlEdmEuropeanaRoleWrapper> getEuropeanaRole() {
return europeanaRole;
}

public XmlEdmCountry getCountry() {
public XmlEdmCountryWrapper getCountry() {
return country;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ public List<EntityRecord> findByEntityIds(
if (excludeDisabled) {
filters.add(eq(DISABLED, null));
}

FindOptions findOptions = new FindOptions();
List<String> fields=new ArrayList<>();
// if fetchFullRecord is set to false, we only care about the entityId and disabled flag for
// this query
if (!fetchFullRecord) {
findOptions.projection().include(ENTITY_ID).projection().include(DISABLED);
fields=new ArrayList<>();
fields.add(ENTITY_ID);
fields.add(DISABLED);
}
return getDataStore()
.find(EntityRecord.class)
.filter(filters.toArray(Filter[]::new))
.iterator(findOptions)
.toList();

return findEntityRecords(filters.toArray(Filter[]::new), false, fields.toArray(String[]::new));

}

/**
Expand All @@ -91,24 +91,38 @@ public List<EntityRecord> findByEntityIds(
* @param fields
* @return
*/
public EntityRecord findEntityRecord(String entityId, String... fields) {
Query<EntityRecord> query = getDataStore()
.find(EntityRecord.class);

public EntityRecord findByEntityId(String entityId, String[] fields) {
List<Filter> filters = new ArrayList<>();
filters.add(eq(ENTITY_ID, entityId));
query = query.filter(filters.toArray(Filter[]::new));

FindOptions findOptions = null;
List<EntityRecord> recordList=findEntityRecords(filters.toArray(Filter[]::new), false, fields);
if(recordList.isEmpty()) {
return null;
}
else {
return recordList.get(0);
}
}

protected List<EntityRecord> findEntityRecords(Filter[] filters, boolean disableValidation, String[] fields) {
Query<EntityRecord> query = getDataStore().find(EntityRecord.class);

if(disableValidation) {
query.disableValidation();
}

if(filters!=null && filters.length>0) {
query.filter(filters);
}

FindOptions findOptions = new FindOptions();
//array must not be empty, invocation of this method with only one parameter uses and empty array
if(fields != null && fields.length > 0) {
findOptions = new FindOptions();
findOptions.projection().include(fields);

return query.first(findOptions);
} else {
return query.first();
}

return query.iterator(findOptions).toList();

}

public List<EntityIdDisabledStatus> getEntityIds(
Expand Down Expand Up @@ -164,22 +178,17 @@ public void dropCollection() {
public List<EntityRecord> findEntitiesByCoreference(
List<String> uris, String entityId, boolean excludeDisabled) {

Query<EntityRecord> query =
getDataStore()
.find(EntityRecord.class)
.disableValidation()
.filter(or(in(ENTITY_SAME_AS, uris), in(ENTITY_EXACT_MATCH, uris)));

List<Filter> filters = new ArrayList<>();
filters.add(or(in(ENTITY_SAME_AS, uris), in(ENTITY_EXACT_MATCH, uris)));
if (StringUtils.isNotBlank(entityId)) {
query.filter(ne(ENTITY_ID, entityId));
filters.add(ne(ENTITY_ID, entityId));
}

if(excludeDisabled) {
query.filter(eq(DISABLED, null));
filters.add(eq(DISABLED, null));
}

//query the database
return query.iterator().toList();
return findEntityRecords(filters.toArray(Filter[]::new), true, null);
}

public List<EntityRecord> findByEntityIdsOrCoreference(List<String> uris) {
Expand All @@ -189,11 +198,7 @@ public List<EntityRecord> findByEntityIdsOrCoreference(List<String> 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();
return findEntityRecords(filters.toArray(Filter[]::new), true, null);
}


Expand All @@ -209,17 +214,15 @@ public List<EntityRecord> saveBulk(List<EntityRecord> entityRecords) {
* @param filters Query filters
* @return List with results
*/
public List<EntityRecord> findWithFilters(int start, int count, Filter[] filters) {
return getDataStore()
.find(EntityRecord.class)
public List<EntityRecord> findWithCount(int start, int count, Filter[] filters) {
return getDataStore().find(EntityRecord.class)
.filter(filters)
.iterator(new FindOptions().skip(start).sort(ascending(ENTITY_MODIFIED)).limit(count))
.toList();
}

public List<EntityRecord> findAll(int start, int count) {
return getDataStore()
.find(EntityRecord.class)
return getDataStore().find(EntityRecord.class)
.iterator(new FindOptions().skip(start).sort(ascending(ENTITY_MODIFIED)).limit(count))
.toList();
}
Expand Down
Loading

0 comments on commit aa7dae6

Please sign in to comment.