From 189347f01cf9aad6d3c63b337c8c326b715a1a29 Mon Sep 17 00:00:00 2001 From: Camelia Dumitru Date: Tue, 11 Feb 2025 10:27:14 +0000 Subject: [PATCH 1/2] Fixes for the check of existing entity and region --- .../jpa/entities/OrgDisambiguatedEntity.java | 4 +- .../loader/source/ror/RorOrgLoadSource.java | 37 ++++++++++++++----- 2 files changed, 31 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..eb28e52798a 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,16 +206,15 @@ 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(); + 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(); } } @@ -258,7 +257,8 @@ 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 +340,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 +350,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 +358,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 +366,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 +374,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 +382,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; } From f3a403ab38ce0f1b7ceb7eb0d83da4e39361b33e Mon Sep 17 00:00:00 2001 From: Camelia Dumitru Date: Tue, 11 Feb 2025 11:56:48 +0000 Subject: [PATCH 2/2] Fixed the null pointer in unit tests --- .../orcid/scheduler/loader/source/ror/RorOrgLoadSource.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 eb28e52798a..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 @@ -211,11 +211,14 @@ private boolean loadData() { 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(); - region = geoDetailsNode.get("country_subdivision_name").isNull() ? null : geoDetailsNode.get("country_subdivision_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; } } + } locationsJson = locationsNode.toString(); @@ -256,6 +259,7 @@ 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) { boolean entityChanged = entityChanged(existingBySourceId, name, country.value(), city, region, url, orgType, locationsJson, namesJson); if (entityChanged || indexAllEnabled) {