Skip to content

Commit

Permalink
Merge pull request #328 from europeana/EA-3896-fix-zoho-sync-deleted-…
Browse files Browse the repository at this point in the history
…orgs

delete only records which have deleted zoho record as proxy id #EA-3896
  • Loading branch information
gsergiu authored Jul 30, 2024
2 parents 82a2599 + 0f57263 commit f4f0659
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -181,10 +182,7 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
// entities)
//build the Zoho Coref URL
entitiesZohoCoref = getDeletedEntitiesZohoCoref(deletedRecordsInZoho);
//retrieve records by coref
deletedEntityRecords = entityRecordService.retrieveMultipleByEntityIdsOrCoreference(entitiesZohoCoref, null);
//fetch entity IDs
entityIdsToDelete = deletedEntityRecords.stream().map(er -> er.getEntityId()).toList();
entityIdsToDelete = getEntityIdsByZohoCorefs(entitiesZohoCoref);

//perform permanent deletion
runPermanentDelete(entityIdsToDelete, zohoSyncReport);
Expand Down Expand Up @@ -219,6 +217,37 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
}
}

List<String> getEntityIdsByZohoCorefs(List<String> entitiesZohoCoref) {
List<EntityRecord> recordsToDelete;
List<String> entityIdsToDelete = new ArrayList<String>(entitiesZohoCoref.size());
//retrieve records by coref
recordsToDelete = entityRecordService.retrieveMultipleByEntityIdsOrCoreference(entitiesZohoCoref, null);
String zohoProxyId;
for (EntityRecord entityRecord : recordsToDelete) {
zohoProxyId = getZohoProxyId(entityRecord);
if(zohoProxyId == null && logger.isWarnEnabled()) {
logger.warn(
"Cannot get zohoProxyId! Organization does not have a zoho proxy, but a zoho coref: {} ", entityRecord);
}
//for deprecated organizations, make sure to not delete the valid organizations which may contain the deprecated id in corefs
//threrefore, delete only records which have the deleted zoho record id in zoho proxy id
if(entitiesZohoCoref.contains(zohoProxyId)) {
entityIdsToDelete.add(entityRecord.getEntityId());
}
}

return entityIdsToDelete;
}

String getZohoProxyId(EntityRecord entityRecord) {
for (String proxyId : entityRecord.getExternalProxyIds()) {
if(proxyId.startsWith(zohoConfiguration.getZohoBaseUrl())) {
return proxyId;
}
}
return null;
}

boolean isLastPage(int currentPageSize, int maxItemsPerPage) {
// END LOOP: if no more organizations exist in Zoho
return currentPageSize < maxItemsPerPage;
Expand Down

0 comments on commit f4f0659

Please sign in to comment.