Skip to content

Commit

Permalink
Fixes for the check of existing entity and region (#7214)
Browse files Browse the repository at this point in the history
* Fixes for the check of existing entity  and region

* Fixed the null pointer in unit tests

---------

Co-authored-by: Angel Montenegro <[email protected]>
  • Loading branch information
Camelia-Orcid and amontenegro authored Feb 13, 2025
1 parent 25f6008 commit 43e67ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Expand All @@ -350,44 +354,63 @@ 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) {
return true;
}
// 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())) {
return true;
}
// 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())) {
return true;
}
// 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())) {
return true;
}
// 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;
}
Expand Down

0 comments on commit 43e67ce

Please sign in to comment.