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

fixes for consolidation of aggregators with wikidata references, fix for #337

Merged
merged 11 commits into from
Feb 19, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ID,
TYPE,
DEPICTION,
IS_SHOWN_BY,
PREF_LABEL,
ACRONYM,
ALT_LABEL,
Expand All @@ -24,21 +25,21 @@
EUROPEANA_ROLE,
COUNTRY,
LANGUAGE,
GEOGRAPHIC_SCOPE,
HERITAGE_DOMAIN,
FOAF_HOMEPAGE,
FOAF_PHONE,
FOAF_MBOX,
HAS_ADDRESS,
PROVIDES_SUPPORT_FOR_MEDIA_TYPE,
PROVIDES_SUPPORT_FOR_DATA_ACTIVITY,
PROVIDES_SUPPORT_FOR_CAPACITY_BUILDING_ACTIVITY,
PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY,
AGGREGATES_FROM,
AGGREGATED_VIA,
IDENTIFIER,
SAME_AS,
IS_AGGREGATED_BY,
GEOGRAPHIC_SCOPE,
HERITAGE_DOMAIN,
PROVIDES_SUPPORT_FOR_MEDIA_TYPE,
PROVIDES_SUPPORT_FOR_DATA_ACTIVITY,
PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY,
PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY
IS_AGGREGATED_BY
})
/**
* Class implementing aggregator extension for organizations
Expand Down Expand Up @@ -152,12 +153,12 @@ public void setProvidesSupportForDataActivity(List<String> providesSupportForDat
this.providesSupportForDataActivity = providesSupportForDataActivity;
}

@JsonGetter(PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY)
@JsonGetter(PROVIDES_SUPPORT_FOR_CAPACITY_BUILDING_ACTIVITY)
public List<String> getProvidesCapacityBuildingActivity() {
return providesCapacityBuildingActivity;
}

@JsonSetter(PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY)
@JsonSetter(PROVIDES_SUPPORT_FOR_CAPACITY_BUILDING_ACTIVITY)
public void setProvidesCapacityBuildingActivity(List<String> providesCapacityBuildingActivity) {
this.providesCapacityBuildingActivity = providesCapacityBuildingActivity;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package eu.europeana.entitymanagement.definitions.model;

import static eu.europeana.entitymanagement.vocabulary.WebEntityConstants.ENTITY_CONTEXT;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ALT_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.CONTEXT;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HAS_PART;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HIDDEN_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IDENTIFIER;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IN_SCHEME;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_AGGREGATED_BY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_PART_OF;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_RELATED_TO;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_SHOWN_BY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.NOTE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand All @@ -37,7 +27,6 @@
import eu.europeana.entitymanagement.normalization.EntityFieldsEuropeanaProxyValidationGroup;
import eu.europeana.entitymanagement.normalization.EntityFieldsEuropeanaProxyValidationInterface;
import eu.europeana.entitymanagement.vocabulary.ValidationObject;
import eu.europeana.entitymanagement.vocabulary.WebEntityFields;

@dev.morphia.annotations.Embedded
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -58,6 +47,8 @@
groups = {EntityFieldsDataSourceProxyValidationGroup.class})
public abstract class Entity implements ValidationObject {

private static final Logger LOG = LogManager.getLogger(Entity.class);

@Transient
protected String context = ENTITY_CONTEXT;
protected String entityId;
Expand Down Expand Up @@ -116,12 +107,12 @@ public void setInScheme(List<String> inScheme) {
this.inScheme = inScheme;
}

@JsonGetter(WebEntityFields.PREF_LABEL)
@JsonGetter(PREF_LABEL)
public Map<String, String> getPrefLabel() {
return prefLabel;
}

@JsonSetter(WebEntityFields.PREF_LABEL)
@JsonSetter(PREF_LABEL)
public void setPrefLabel(Map<String, String> prefLabel) {
this.prefLabel = prefLabel;
}
Expand Down Expand Up @@ -218,17 +209,17 @@ public void setIsPartOfArray(List<String> isPartOf) {
this.isPartOf = isPartOf;
}

@JsonGetter(WebEntityFields.DEPICTION)
@JsonGetter(DEPICTION)
public WebResource getDepiction() {
return depiction;
}

@JsonSetter(WebEntityFields.DEPICTION)
@JsonSetter(DEPICTION)
public void setDepiction(WebResource depiction) {
this.depiction = depiction;
}

@JsonGetter(WebEntityFields.IS_SHOWN_BY)
@JsonGetter(IS_SHOWN_BY)
public WebResource getIsShownBy() {
return isShownBy;
}
Expand All @@ -242,7 +233,14 @@ public Object getFieldValue(Field field) throws IllegalAccessException {
if(!field.canAccess(this)) {
field.setAccessible(true);
}
return field.get(this);
try {
return field.get(this);
}catch (RuntimeException e) {
if(LOG.isTraceEnabled()) {
LOG.trace("Cannot retrieve field {} for Organization with id:{}", field.getName(), this.getEntityId(), e);
}
return null;
}
}

public void setFieldValue(Field field, Object value)
Expand All @@ -259,6 +257,11 @@ public Aggregation getIsAggregatedBy() {
return isAggregatedBy;
}

@JsonSetter(IS_AGGREGATED_BY)
public void setIsAggregatedBy(Aggregation isAggregatedBy) {
this.isAggregatedBy = isAggregatedBy;
}

/** Not included in XML responses */
@JsonGetter(CONTEXT)
public String getContext() {
Expand All @@ -270,11 +273,6 @@ public void setContext(String context) {
}


@JsonSetter(IS_AGGREGATED_BY)
public void setIsAggregatedBy(Aggregation isAggregatedBy) {
this.isAggregatedBy = isAggregatedBy;
}

@JsonIgnore
public String getPayload() {
return payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_SAME_AS;
import static eu.europeana.entitymanagement.definitions.EntityRecordFields.ENTITY_TYPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.BASE_DATA_EUROPEANA_URI;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ENTITY_ID;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;
import java.util.ArrayList;
import java.util.Date;
Expand All @@ -21,14 +22,14 @@
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Index;
import dev.morphia.annotations.IndexOptions;
import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.Indexes;
import eu.europeana.entitymanagement.utils.EntityRecordWatcher;
import eu.europeana.entitymanagement.vocabulary.WebEntityFields;

@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@dev.morphia.annotations.Entity("EntityRecord")
@Indexes({
@Index(fields = {@Field(ENTITY_ID)}, options = @IndexOptions(unique = true)),
@Index(fields = {@Field(ENTITY_TYPE)}),
@Index(fields = {@Field(ENTITY_EXACT_MATCH)}),
@Index(fields = {@Field(ENTITY_SAME_AS)}),
Expand All @@ -39,7 +40,6 @@ public class EntityRecord {

@Id @JsonIgnore private ObjectId dbId;

@Indexed(options = @IndexOptions(unique = true))
private String entityId;

private Entity entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
package eu.europeana.entitymanagement.definitions.model;

import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ACRONYM;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.AGGREGATED_VIA;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.AGGREGATES_FROM;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ALT_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.CONTEXT;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.COUNTRY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DEPICTION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DESCRIPTION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.EUROPEANA_ROLE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_HOMEPAGE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_LOGO;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.FOAF_PHONE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HAS_ADDRESS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HIDDEN_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IDENTIFIER;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IS_AGGREGATED_BY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.LANGUAGE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PREF_LABEL;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.SAME_AS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -42,6 +22,7 @@
ID,
TYPE,
DEPICTION,
IS_SHOWN_BY,
PREF_LABEL,
ACRONYM,
ALT_LABEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class EntityFieldsCleaner {

private static final Set<String> ISO_LANGUAGES = Set.of(Locale.getISOLanguages());

private static final Logger logger = LogManager.getLogger(EntityFieldsCleaner.class);
private static final Logger LOG = LogManager.getLogger(EntityFieldsCleaner.class);

private final LanguageCodes emLanguageCodes;

Expand Down Expand Up @@ -156,8 +156,8 @@ private Map normalizeMapField(Field field, Map fieldValue)
} else if (isMultipleValueStringMap(field)) {
return normalizeMultipleValueMap(field.getName(), (Map<String, List<String>>) fieldValue);
} else {
if (logger.isTraceEnabled()) {
logger.trace("normalization not supported for maps of type: {}", field.getGenericType());
if (LOG.isTraceEnabled()) {
LOG.trace("normalization not supported for maps of type: {}", field.getGenericType());
}
return fieldValue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package eu.europeana.entitymanagement.utils;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import eu.europeana.entitymanagement.definitions.model.Aggregation;
import eu.europeana.entitymanagement.definitions.model.EntityRecord;
import eu.europeana.entitymanagement.vocabulary.EntityTypes;
import eu.europeana.entitymanagement.vocabulary.WebEntityFields;
Expand Down Expand Up @@ -63,6 +65,21 @@ public static String getEuropeanaProxyId(String entityId) {
return entityId + "#proxy_europeana";
}

/**
* Instantiates a new Aggregation and fills the mandatory fields
* @param entityId the entity ID
* @param timestamp creation timestamp
* @return the Aggregation object
*/
public static Aggregation createNewAggregation(String entityId, Date timestamp) {
Aggregation isAggregatedBy = new Aggregation();
isAggregatedBy.setId(getIsAggregatedById(entityId));
isAggregatedBy.setCreated(timestamp);
isAggregatedBy.setModified(timestamp);
return isAggregatedBy;
}


/**
* extract the identifier part from the URL
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package eu.europeana.entitymanagement.utils;

import eu.europeana.entitymanagement.vocabulary.WebEntityConstants;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import eu.europeana.entitymanagement.vocabulary.WebEntityConstants;

public class EntityUtils {

Expand Down Expand Up @@ -60,7 +61,10 @@ public static List<Field> getAllFields(Class<?> type) {
}

private static void getAllFieldsRecursively(List<Field> fields, Class<?> type) {
fields.addAll(Arrays.asList(type.getDeclaredFields()));
//filter out static fields
fields.addAll(
Arrays.asList(type.getDeclaredFields()).stream().filter(
f -> !Modifier.isStatic(f.getModifiers())).toList());
if (type.getSuperclass() != null) {
getAllFieldsRecursively(fields, type.getSuperclass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public abstract class WebEntityFields {
public static final String HERITAGE_DOMAIN = "heritageDomain";
public static final String PROVIDES_SUPPORT_FOR_MEDIA_TYPE = "providesSupportForMediaType";
public static final String PROVIDES_SUPPORT_FOR_DATA_ACTIVITY = "providesSupportForDataActivity";
public static final String PROVIDES_SUPPORT_FOR_BUILDING_ACTIVITY = "providesCapacityBuildingActivity";
public static final String PROVIDES_SUPPORT_FOR_CAPACITY_BUILDING_ACTIVITY = "providesCapacityBuildingActivity";
public static final String PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY = "providesAudienceEngagementActivity";

// Address Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
package eu.europeana.entitymanagement.web.xml.model;

import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_EDM;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.NAMESPACE_FOAF;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_AGGREGATOR;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_GEOGRAPHIC_SCOPE;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_HERITAGE_DOMAIN;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_MBOX;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PROVIDES_CAPACITY_BUILDING_ACTIVITY;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PROVIDES_SUPPORT_FOR_DATA_ACTIVITY;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.XML_PROVIDES_SUPPORT_FOR_MEDIA_TYPE;
import static eu.europeana.entitymanagement.web.xml.model.XmlConstants.*;
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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import eu.europeana.entitymanagement.definitions.exceptions.EntityModelCreationException;
import eu.europeana.entitymanagement.definitions.model.Aggregator;
import eu.europeana.entitymanagement.vocabulary.EntityTypes;

@XmlRootElement(namespace = NAMESPACE_EDM, name = XML_AGGREGATOR)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType( propOrder = {
ABOUT,
DEPICTION,
IS_SHOWN_BY,
PREF_LABEL,
XML_ACRONYM,
ALT_LABEL,
HIDDEN_LABEL,
XML_DESCRIPTION,
XML_LOGO,
XML_EUROPEANA_ROLE,
XML_COUNTRY,
XML_LANGUAGE,
XML_GEOGRAPHIC_SCOPE,
XML_HERITAGE_DOMAIN,
XML_HOMEPAGE,
XML_PHONE,
XML_MBOX,
XML_HAS_ADDRESS,
XML_PROVIDES_SUPPORT_FOR_MEDIA_TYPE,
XML_PROVIDES_SUPPORT_FOR_DATA_ACTIVITY,
XML_PROVIDES_CAPACITY_BUILDING_ACTIVITY,
XML_PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY,
XML_AGGREGATED_VIA,
XML_AGGREGATES_FROM,
XML_IDENTIFIER,
XML_SAME_AS,
IS_AGGREGATED_BY
})

@SuppressWarnings("java:S2384")
/**
* class for xml serialization of Aggregators
*/
@SuppressWarnings("java:S2384")
public class XmlAggregatorImpl extends XmlOrganizationImpl {
public class XmlAggregatorImpl extends XmlBaseOrganizationImpl {

@XmlElement(namespace = NAMESPACE_FOAF, name = XML_MBOX)
private String mbox;
Expand Down
Loading