Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for the check of existing entity and region #7214

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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