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

delete only records which have deleted zoho record as proxy id #EA-3896 #328

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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 @@ -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
Loading