Skip to content

Commit

Permalink
Merge pull request #289 from europeana/EA-3641-zoho-fields-updates
Browse files Browse the repository at this point in the history
update organization fields (unmap from zoho or permanently remove)
  • Loading branch information
gsergiu authored Feb 6, 2024
2 parents 3c66f5f + deba06c commit 9d286cf
Show file tree
Hide file tree
Showing 97 changed files with 2,332 additions and 969 deletions.
1 change: 1 addition & 0 deletions development_tips.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ public ZohoDereferenceService(ZohoAccessConfiguration zohoAccessConfiguration,
}

The printed response can then be saved to a file in test/resources. Also make sure to adjust the fields to be either string or list type (no map).

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class DataSource {
public static final String FREQ_STATIC = "static";
public static final String EUROPEANA_ID = "europeana";
public static final String ZOHO_ID = "zoho-crm";
public static final String ZOHO_HOST = "crm.zoho.com";

@JacksonXmlProperty(isAttribute = true)
private String url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package eu.europeana.entitymanagement.common.config;

import static eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants.BEAN_JSON_MAPPER;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.core.io.ClassPathResource;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
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 @@ -152,10 +167,109 @@ public class EntityManagementConfiguration implements InitializingBean {
@Value("${spring.profiles.active:}")
private String activeProfileString;

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

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

@Value("${europeana.role.vocabulary:role_vocabulary.xml}")
private String roleVocabularyFilename;

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

@Autowired
@Qualifier(BEAN_JSON_MAPPER)
private ObjectMapper emJsonMapper;


public EntityManagementConfiguration() {
LOG.info("Initializing EntityManagementConfiguration bean as: configuration");
}

@Override
public void afterPropertiesSet() throws Exception {
if (isNotTestProfile(activeProfileString)) {
verifyRequiredProperties();
}
//initialize country mapping
initCountryMappings();
//initialize role mapping
initRoleMappings();
}

/** verify properties */
private void verifyRequiredProperties() {
List<String> missingProps = new ArrayList<>();

// search api prefix is mandatory
if (StringUtils.isBlank(getSearchApiUrlPrefix())) {
missingProps.add("europeana.searchapi.urlPrefix");
}

// one of zookeeperUrl or solr indexing url are
if (StringUtils.isBlank(getIndexingSolrZookeeperUrl())
&& StringUtils.isBlank(getIndexingSolrUrl())) {
missingProps.add(
"entitymanagement.solr.indexing.url/entitymanagement.solr.indexing.zookeeper.url");
}

// collection name is mandatory when using zookeeper url
if (StringUtils.isNotBlank(getIndexingSolrZookeeperUrl())
&& StringUtils.isBlank(getIndexingSolrCollection())) {
missingProps.add("entitymanagement.solr.indexing.collection");
}

if (!missingProps.isEmpty()) {
throw new IllegalStateException(
String.format(
"The following config properties are not set: %s", String.join("\n", missingProps)));
}
}

private void initCountryMappings() throws IOException {
ClassPathResource resource = new ClassPathResource(getZohoCountryMappingFilename());

try (InputStream inputStream = resource.getInputStream()) {
assert inputStream != null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String contents = reader.lines().collect(Collectors.joining(System.lineSeparator()));
List<ZohoLabelUriMapping> countryMappingList = emJsonMapper.readValue(contents, new TypeReference<List<ZohoLabelUriMapping>>(){});
for (ZohoLabelUriMapping countryMapping : countryMappingList) {
countryMappings.put(countryMapping.getZohoLabel(), countryMapping);
}
}
}
}

private void initRoleMappings() throws IOException {

ClassPathResource resource = new ClassPathResource(getZohoRoleMappingFilename());

try (InputStream inputStream = resource.getInputStream()) {
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 loadRoleVocabulary() throws IOException {
ClassPathResource resource = new ClassPathResource(getRoleVocabularyFilename());

try (InputStream inputStream = resource.getInputStream()) {
assert inputStream != null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
}

public String getPrSolrUrl() {
return prSolrUrl;
}
Expand Down Expand Up @@ -308,46 +422,10 @@ public String getItemDataEndpoint() {
return itemDataEndpoint;
}

@Override
public void afterPropertiesSet() throws Exception {
if (isNotTestProfile(activeProfileString)) {
verifyRequiredProperties();
}
}

public static boolean isNotTestProfile(String activeProfileString) {
return Arrays.stream(activeProfileString.split(",")).noneMatch(ACTIVE_TEST_PROFILE::equals);
}

/** verify properties */
private void verifyRequiredProperties() {
List<String> missingProps = new ArrayList<>();

// search api prefix is mandatory
if (StringUtils.isBlank(getSearchApiUrlPrefix())) {
missingProps.add("europeana.searchapi.urlPrefix");
}

// one of zookeeperUrl or solr indexing url are
if (StringUtils.isBlank(getIndexingSolrZookeeperUrl())
&& StringUtils.isBlank(getIndexingSolrUrl())) {
missingProps.add(
"entitymanagement.solr.indexing.url/entitymanagement.solr.indexing.zookeeper.url");
}

// collection name is mandatory when using zookeeper url
if (StringUtils.isNotBlank(getIndexingSolrZookeeperUrl())
&& StringUtils.isBlank(getIndexingSolrCollection())) {
missingProps.add("entitymanagement.solr.indexing.collection");
}

if (!missingProps.isEmpty()) {
throw new IllegalStateException(
String.format(
"The following config properties are not set: %s", String.join("\n", missingProps)));
}
}

public String getSchemeDataEndpoint() {
return schemeDataEndpoint;
}
Expand All @@ -359,9 +437,28 @@ public void setSchemeDataEndpoint(String schemeDataEndpoint) {
public boolean isGenerateOrganizationEuropeanaId() {
return generateOrganizationEuropeanaId;
}

public boolean isRegisterDeprecated() {
return registerDeprecated;
}

public String getZohoCountryMappingFilename() {
return zohoCountryMappingFilename;
}

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

public String getZohoRoleMappingFilename() {
return zohoRoleMappingFilename;
}

public Map<String, String> getRoleMappings() {
return roleMappings;
}

public String getRoleVocabularyFilename() {
return roleVocabularyFilename;
}
}
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 Expand Up @@ -56,7 +57,7 @@ public class AppConfigConstants {

public static final String BEAN_SOLR_ENTITY_SUGGESTER_FILTER = "solrEntityFilter";

public static final String BEAN_ZOHO_ACCESS_CONFIGURATION = "zohoAccessConfiguration";
public static final String BEAN_ZOHO_CONFIGURATION = "zohoConfiguration";
public static final String BEAN_WIKIDATA_ACCESS_SERVICE = "wikidataAccessService";
public static final String BEAN_WIKIDATA_ACCESS_DAO = "wikidataAccessDao";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ private EntityRecordFields() {
}

public static final String CLASS = "objectClass";
public static final String ENTITY = "entity";
public static final String ENTITY_ID = "entityId";
public static final String ENTITY_MODIFIED = "modified";
public static final String DISABLED = "disabled";
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 URI = "uri";

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

import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.*;

import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.CONTEXT;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.COUNTRY_NAME;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.HAS_GEO;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.ID;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.LOCALITY;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.POSTAL_CODE;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.POST_OFFICE_BOX;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.REGION;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.STREET_ADDRESS;
import static eu.europeana.entitymanagement.vocabulary.WebEntityFields.TYPE;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
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 dev.morphia.annotations.Embedded;
import org.apache.commons.lang3.StringUtils;

@Embedded
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
Expand Down Expand Up @@ -127,4 +136,32 @@ public boolean hasMetadataProperties() {
|| StringUtils.isNotEmpty(countryName)
|| StringUtils.isNotEmpty(hasGeo);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Address that = (Address) o;

if (Objects.equals(about, that.getAbout()) &&
Objects.equals(streetAddress, that.getVcardStreetAddress()) &&
Objects.equals(postalCode, that.getVcardPostalCode()) &&
Objects.equals(postBox, that.getVcardPostOfficeBox()) &&
Objects.equals(locality, that.getVcardLocality()) &&
Objects.equals(countryName, that.getVcardCountryName()) &&
Objects.equals(hasGeo, that.getVcardHasGeo())) {
return true;
}
else {
return false;
}
}

public int hashCode() {
return ((streetAddress == null) ? 0 : streetAddress.hashCode()) +
((locality == null) ? 0 : locality.hashCode()) +
((hasGeo == null) ? 0 : hasGeo.hashCode());
}

}
Loading

0 comments on commit 9d286cf

Please sign in to comment.