Skip to content

Commit

Permalink
europeanaRole field added to organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Feb 2, 2024
1 parent 8fe1082 commit f95d62c
Show file tree
Hide file tree
Showing 32 changed files with 529 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.context.annotation.PropertySources;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.europeana.entitymanagement.definitions.model.CountryMapping;
import eu.europeana.entitymanagement.definitions.model.ZohoLabelUriMapping;

/**
* Container for all settings that we load from the entitymanagement.properties file and optionally
Expand Down Expand Up @@ -167,8 +167,12 @@ public class EntityManagementConfiguration implements InitializingBean {

@Value("${zoho.country.mapping:null}")
private String zohoCountryMappingFilename;

Map<String, CountryMapping> countryMappings = new HashMap<>();

@Value("${zoho.role.mapping:null}")
private String zohoRoleMappingFilename;

Map<String, ZohoLabelUriMapping> countryMappings = new HashMap<>();
Map<String, String> roleMappings = new HashMap<>();

@Autowired
@Qualifier(BEAN_JSON_MAPPER)
Expand All @@ -186,6 +190,8 @@ public void afterPropertiesSet() throws Exception {
}
//initialize country mapping
initCountryMappings();
//initialize role mapping
initRoleMappings();
}

/** verify properties */
Expand Down Expand Up @@ -222,14 +228,27 @@ private void initCountryMappings() throws IOException {
assert inputStream != null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String contents = reader.lines().collect(Collectors.joining(System.lineSeparator()));
List<CountryMapping> countryMappingList = emJsonMapper.readValue(contents, new TypeReference<List<CountryMapping>>(){});
for (CountryMapping countryMapping : countryMappingList) {
List<ZohoLabelUriMapping> countryMappingList = emJsonMapper.readValue(contents, new TypeReference<List<ZohoLabelUriMapping>>(){});
for (ZohoLabelUriMapping countryMapping : countryMappingList) {
countryMappings.put(countryMapping.getZohoLabel(), countryMapping);
}
}
}
}

private void initRoleMappings() throws IOException {
try (InputStream inputStream = getClass().getResourceAsStream(getZohoRoleMappingFilename())) {
assert inputStream != null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String contents = reader.lines().collect(Collectors.joining(System.lineSeparator()));
List<ZohoLabelUriMapping> roleMappingList = emJsonMapper.readValue(contents, new TypeReference<List<ZohoLabelUriMapping>>(){});
for (ZohoLabelUriMapping roleMapping : roleMappingList) {
roleMappings.put(roleMapping.getZohoLabel(), roleMapping.getEntityUri());
}
}
}
}

public String getPrSolrUrl() {
return prSolrUrl;
}
Expand Down Expand Up @@ -406,7 +425,15 @@ public String getZohoCountryMappingFilename() {
return zohoCountryMappingFilename;
}

public Map<String, CountryMapping> getCountryMappings() {
public Map<String, ZohoLabelUriMapping> getCountryMappings() {
return countryMappings;
}

public String getZohoRoleMappingFilename() {
return zohoRoleMappingFilename;
}

public Map<String, String> getRoleMappings() {
return roleMappings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AppConfigConstants {
public static final String BEAN_MESSAGE_SOURCE = "messageSource";

public static final String BEAN_ENTITY_RECORD_REPO = "emEntityRecordRepo";
public static final String BEAN_VOCABULARY_REPO = "emVocabularyRepo";
public static final String BEAN_CONCEPT_SCHEME_REPO = "emConceptSchemeRepo";
public static final String BEAN_ZOHO_SYNC_REPO = "emZohoSyncRepo";
public static final String BEAN_ENTITY_RECORD_SERVICE = "emEntityRecordService";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eu.europeana.entitymanagement.definitions;

// Collection field names
public class VocabularyFields {

private VocabularyFields() {
// private constructor to prevent instantiation
}

public static final String VOCABULARY_URI = "vocabularyUri";

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ public class Organization extends Entity {
private String homepage;
private List<String> phone;
private List<String> mbox;
private Map<String, List<String>> europeanaRole;

@Reference(lazy = true)
private EntityRecord countryRef;
private String countryId;
@Transient
private Place country;

private List<String> europeanaRoleIds;
@Reference(lazy = true)
private List<Vocabulary> europeanaRoleRefs;
@Transient
private List<Vocabulary> europeanaRole;

private Address hasAddress;
private List<String> sameAs;
private List<String> language;
Expand All @@ -89,9 +94,11 @@ public Organization(Organization copy) {
this.homepage = copy.getHomepage();
if (copy.getPhone() != null) this.phone = new ArrayList<>(copy.getPhone());
if (copy.getMbox() != null) this.mbox = new ArrayList<>(copy.getMbox());
if (copy.getEuropeanaRole() != null)
this.europeanaRole = new HashMap<>(copy.getEuropeanaRole());
//because the countryRef is a reference to the object we keep it the same
//because the europeanaRoleRef is a reference to the object we keep it the same (therefore also for europeanaRole)
this.europeanaRole = copy.getEuropeanaRole();
this.europeanaRoleRefs = copy.getEuropeanaRoleRefs();
if(copy.getEuropeanaRoleIds()!=null) this.europeanaRoleIds=new ArrayList<>(copy.getEuropeanaRoleIds());
//because the countryRef is a reference to the object we keep it the same (therefore also for country)
this.countryRef=copy.getCountryRef();
this.countryId = copy.getCountryId();
this.country = copy.getCountry();
Expand Down Expand Up @@ -121,16 +128,6 @@ public void setAcronym(Map<String, List<String>> acronym) {
this.acronym = acronym;
}

@JsonGetter(EUROPEANA_ROLE)
public Map<String, List<String>> getEuropeanaRole() {
return europeanaRole;
}

@JsonSetter(EUROPEANA_ROLE)
public void setEuropeanaRole(Map<String, List<String>> europeanaRole) {
this.europeanaRole = europeanaRole;
}

@JsonGetter(FOAF_PHONE)
public List<String> getPhone() {
return phone;
Expand Down Expand Up @@ -250,5 +247,41 @@ public String getCountryId() {
public void setCountryId(String countryId) {
this.countryId = countryId;
}

@JsonIgnore
public List<String> getEuropeanaRoleIds() {
return europeanaRoleIds;
}

public void setEuropeanaRoleIds(List<String> europeanaRoleIds) {
this.europeanaRoleIds = europeanaRoleIds;
}

@JsonIgnore
public List<Vocabulary> getEuropeanaRoleRefs() {
return europeanaRoleRefs;
}

public void setEuropeanaRoleRefs(List<Vocabulary> europeanaRoleRefs) {
this.europeanaRoleRefs = europeanaRoleRefs;
}

@JsonGetter(EUROPEANA_ROLE)
public List<Vocabulary> getEuropeanaRole() {
if(europeanaRole==null && europeanaRoleIds!=null && !europeanaRoleIds.isEmpty()) {
europeanaRole=new ArrayList<>();
for(String roleId : europeanaRoleIds) {
Vocabulary vocab = new Vocabulary();
vocab.setVocabularyUri(roleId);
europeanaRole.add(vocab);
}
}
return europeanaRole;
}

@JsonSetter(EUROPEANA_ROLE)
public void setEuropeanaRole(List<Vocabulary> europeanaRole) {
this.europeanaRole = europeanaRole;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package eu.europeana.entitymanagement.definitions.model;

import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.IN_SCHEME;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.PREF_LABEL;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.bson.types.ObjectId;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSetter;
import dev.morphia.annotations.EntityListeners;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.IndexOptions;
import dev.morphia.annotations.Indexed;
import eu.europeana.entitymanagement.utils.VocabularyWatcher;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@dev.morphia.annotations.Entity("Vocabulary")
@EntityListeners(VocabularyWatcher.class)
public class Vocabulary {

private String type = "Vocabulary";

@Id @JsonIgnore private ObjectId dbId;

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

protected List<String> inScheme;

protected Map<String, String> prefLabel;

@JsonIgnore
private Date created;

@JsonIgnore
private Date modified;

public Vocabulary() {
}

public void setDbId(ObjectId dbId_param) {
this.dbId = dbId_param;
}

public ObjectId getDbId() {
return dbId;
}

public void setCreated(Date created) {
this.created = created;
}

public Date getCreated() {
return this.created;
}

public void setModified(Date modified) {
this.modified = modified;
}

public Date getModified() {
return this.modified;
}

@Override
public String toString() {
return String.format("Vocabulary.vocabularyUri: %s", getVocabularyUri());
}

@JsonGetter
public String getVocabularyUri() {
return vocabularyUri;
}

@JsonSetter
public void setVocabularyUri(String vocabularyUri) {
this.vocabularyUri = vocabularyUri;
}

@JsonGetter(IN_SCHEME)
public List<String> getInScheme() {
return inScheme;
}

@JsonSetter(IN_SCHEME)
public void setInScheme(List<String> inScheme) {
this.inScheme = inScheme;
}

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

@JsonSetter(PREF_LABEL)
public void setPrefLabel(Map<String, String> prefLabel) {
this.prefLabel = prefLabel;
}

public String getType() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ENTITY_URI,
WIKIDATA_URI
})
public class CountryMapping {
public class ZohoLabelUriMapping {

private String zohoLabel;
private String entityUri;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package eu.europeana.entitymanagement.normalization;

import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.*;
import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.FIELD_TYPE_DATE;
import static eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes.FIELD_TYPE_KEYWORD;
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.BASE_DATA_EUROPEANA_URI;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.BEGIN;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DATE_OF_BIRTH;
Expand All @@ -9,14 +12,6 @@
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.DATE_OF_TERMINATION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.END;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.GENDER;

import eu.europeana.entitymanagement.definitions.LanguageCodes;
import eu.europeana.entitymanagement.definitions.exceptions.EntityManagementRuntimeException;
import eu.europeana.entitymanagement.definitions.model.ConsolidatedAgent;
import eu.europeana.entitymanagement.definitions.model.Entity;
import eu.europeana.entitymanagement.definitions.model.WebResource;
import eu.europeana.entitymanagement.utils.EntityUtils;
import eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
Expand All @@ -35,6 +30,13 @@
import org.apache.commons.lang3.reflect.ConstructorUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import eu.europeana.entitymanagement.definitions.LanguageCodes;
import eu.europeana.entitymanagement.definitions.exceptions.EntityManagementRuntimeException;
import eu.europeana.entitymanagement.definitions.model.ConsolidatedAgent;
import eu.europeana.entitymanagement.definitions.model.Entity;
import eu.europeana.entitymanagement.definitions.model.WebResource;
import eu.europeana.entitymanagement.utils.EntityUtils;
import eu.europeana.entitymanagement.vocabulary.EntityFieldsTypes;

public class EntityFieldsCleaner {

Expand Down Expand Up @@ -89,13 +91,15 @@ public void cleanAndNormalize(Entity entity) {
String[] normalized = normalizedList.toArray(new String[0]);
entity.setFieldValue(field, normalized);
} else if (fieldType.isAssignableFrom(List.class)) {
List<String> fieldValueList = (List<String>) fieldValue;
if (fieldValueList.isEmpty()) {
List<?> fieldValueList = (List<?>) fieldValue;
if(fieldValueList.isEmpty() || !(fieldValueList.get(0) instanceof String)) {
continue;
}

List<String> fieldValueListString = (List<String>) fieldValue;

// remove spaces from the List<String> fields
List<String> normalizedList = normalizeValues(field.getName(), fieldValueList);
List<String> normalizedList = normalizeValues(field.getName(), fieldValueListString);

// if Entity field is supposed to contain a single element, remove all elements
// except the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.europeana.entitymanagement.utils;

import java.util.Date;
import dev.morphia.annotations.PrePersist;
import eu.europeana.entitymanagement.definitions.model.Vocabulary;

/** Watches for Database operations on the Vocabulary collection */
public class VocabularyWatcher {

/**
* Invoked by Morphia when creating / updating a Vocabulary. Sets the created/modified time.
* @param record Vocabulary
*/
@PrePersist
void prePersist(Vocabulary vocab) {
Date now = new Date();
if (vocab.getCreated() == null) {
vocab.setCreated(now);
}
vocab.setModified(now);
}
}
Loading

0 comments on commit f95d62c

Please sign in to comment.