From 43e67ced3e00078c5a389a8a15b062851333ba9e Mon Sep 17 00:00:00 2001 From: Camelia Dumitru <62257307+Camelia-Orcid@users.noreply.github.com> Date: Thu, 13 Feb 2025 16:05:05 +0000 Subject: [PATCH] Fixes for the check of existing entity and region (#7214) * Fixes for the check of existing entity and region * Fixed the null pointer in unit tests --------- Co-authored-by: Angel Montenegro --- .../jpa/entities/OrgDisambiguatedEntity.java | 4 +- .../loader/source/ror/RorOrgLoadSource.java | 41 +++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/OrgDisambiguatedEntity.java b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/OrgDisambiguatedEntity.java index 9379cd2db44..b61b63b5666 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/OrgDisambiguatedEntity.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/OrgDisambiguatedEntity.java @@ -129,10 +129,12 @@ public void setCity(String city) { this.city = city; } + @Column(name = "region") public String getRegion() { return region; } - + + @Column(name = "region") public void setRegion(String region) { this.region = region; } diff --git a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/source/ror/RorOrgLoadSource.java b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/source/ror/RorOrgLoadSource.java index ea845e177ae..129d4dec34a 100644 --- a/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/source/ror/RorOrgLoadSource.java +++ b/orcid-scheduler-web/src/main/java/org/orcid/scheduler/loader/source/ror/RorOrgLoadSource.java @@ -206,17 +206,19 @@ private boolean loadData() { if (locationsNode != null) { for (JsonNode locationJson : locationsNode) { JsonNode geoDetailsNode = locationJson.get("geonames_details").isNull() ? null : (JsonNode) locationJson.get("geonames_details"); - if (geoDetailsNode != null) { String countryCode = geoDetailsNode.get("country_code").isNull() ? null : geoDetailsNode.get("country_code").asText(); country = StringUtils.isBlank(countryCode) ? null : Iso3166Country.fromValue(countryCode); // for now storing just the first location city = geoDetailsNode.get("name").isNull() ? null : geoDetailsNode.get("name").asText(); + if(geoDetailsNode.get("country_subdivision_name") != null ) { + region = geoDetailsNode.get("country_subdivision_name").isNull() ? null : geoDetailsNode.get("country_subdivision_name").asText(); + } if (country != null) { break; } - region = geoDetailsNode.get("country_subdivision_name").isNull() ? null : geoDetailsNode.get("country_subdivision_name").asText(); } + } locationsJson = locationsNode.toString(); @@ -257,8 +259,10 @@ private OrgDisambiguatedEntity processInstitute(String sourceId, String name, Is String region, String url, String orgType, String locationsJson, String namesJson) { OrgDisambiguatedEntity existingBySourceId = orgDisambiguatedDao.findBySourceIdAndSourceType(sourceId, OrgDisambiguatedSourceType.ROR.name()); + if (existingBySourceId != null) { - if (entityChanged(existingBySourceId, name, country.value(), city, region, url, orgType) || indexAllEnabled) { + boolean entityChanged = entityChanged(existingBySourceId, name, country.value(), city, region, url, orgType, locationsJson, namesJson); + if (entityChanged || indexAllEnabled) { existingBySourceId.setCity(city); existingBySourceId.setCountry(country.name()); existingBySourceId.setName(name); @@ -340,7 +344,7 @@ private void setExternalId(OrgDisambiguatedEntity org, String identifierTypeName * * @return true if the entity has changed. */ - private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String countryCode, String city, String region, String url, String orgType) { + private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String countryCode, String city, String region, String url, String orgType, String locationsJson, String namesJson) { // Check name if (StringUtils.isNotBlank(name)) { if (!name.equalsIgnoreCase(entity.getName())) @@ -350,7 +354,7 @@ private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String } // Check country if (StringUtils.isNotBlank(countryCode)) { - if (entity.getCountry() == null || !countryCode.equals(entity.getCountry())) { + if (entity.getCountry() == null || !StringUtils.equals(countryCode, entity.getCountry())) { return true; } } else if (entity.getCountry() != null) { @@ -358,7 +362,7 @@ private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String } // Check city if (StringUtils.isNotBlank(city)) { - if (entity.getCity() == null || !city.equals(entity.getCity())) { + if (entity.getCity() == null || !StringUtils.equals(city, entity.getCity())) { return true; } } else if (StringUtils.isNotBlank(entity.getCity())) { @@ -366,7 +370,7 @@ private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String } // Check region if (StringUtils.isNotBlank(region)) { - if (entity.getRegion() == null || !region.equals(entity.getRegion())) { + if (entity.getRegion() == null || !StringUtils.equals(region, entity.getRegion())) { return true; } } else if (StringUtils.isNotBlank(entity.getRegion())) { @@ -374,7 +378,7 @@ private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String } // Check url if (StringUtils.isNotBlank(url)) { - if (entity.getUrl() == null || !url.equals(entity.getUrl())) { + if (entity.getUrl() == null || !StringUtils.equals(url, entity.getUrl())) { return true; } } else if (StringUtils.isNotBlank(entity.getUrl())) { @@ -382,12 +386,31 @@ private boolean entityChanged(OrgDisambiguatedEntity entity, String name, String } // Check org_type if (StringUtils.isNotBlank(orgType)) { - if (entity.getOrgType() == null || !orgType.equals(entity.getOrgType())) { + if (entity.getOrgType() == null || !StringUtils.equals(orgType, entity.getOrgType())) { return true; } } else if (StringUtils.isNotBlank(entity.getOrgType())) { return true; } + + // Check names json + if (StringUtils.isNotBlank(namesJson)) { + if (entity.getNamesJson() == null || !StringUtils.equals(namesJson, entity.getNamesJson())) { + return true; + } + } else if (StringUtils.isNotBlank(entity.getNamesJson())) { + return true; + } + + //Check location Json + if (StringUtils.isNotBlank(locationsJson)) { + if (entity.getLocationsJson() == null || !StringUtils.equals(locationsJson, entity.getLocationsJson())) { + return true; + } + } else if (StringUtils.isNotBlank(entity.getLocationsJson())) { + return true; + } + return false; }