Skip to content

Commit

Permalink
items deleted in zoho must be retrieved by zoho coref to get the new
Browse files Browse the repository at this point in the history
organization id #EA-3896
  • Loading branch information
GordeaS authored and GordeaS committed Jul 29, 2024
1 parent a7ee0d0 commit 40eb9d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected void performOperations(BatchOperations operations, ZohoSyncReport zoho

// scheduled updates at the end, otherwise the other operations may overwrite the record in the db with the old captured in the operation
performUpdateOperations(operations.getUpdateOperations(), zohoSyncReport);

}

void performPermanentDeleteOperations(SortedSet<Operation> permanentDeleteOperations, ZohoSyncReport zohoSyncReport) {
Expand All @@ -151,9 +151,12 @@ void performPermanentDeleteOperations(SortedSet<Operation> permanentDeleteOperat
}
}

void runPermanentDelete(List<String> entitiesDeletedInZoho, ZohoSyncReport zohoSyncReport)
void runPermanentDelete(List<String> entitiesToDelete, ZohoSyncReport zohoSyncReport)
throws SolrServiceException {
long deleted = entityRecordService.deleteBulk(entitiesDeletedInZoho, true);
if(entitiesToDelete == null || entitiesToDelete.isEmpty()) {
return;
}
long deleted = entityRecordService.deleteBulk(entitiesToDelete, true);
zohoSyncReport.increaseDeleted(deleted);
}

Expand Down Expand Up @@ -428,16 +431,20 @@ protected Set<String> getZohoOrganizationUrls(final List<Record> orgList) {
}


protected List<String> getDeletedEntityIds(final List<DeletedRecord> deletedInZoho) {
protected List<String> getDeletedEntitiesZohoCoref(final List<DeletedRecord> deletedInZoho) {

List<String> deletedEntityIds = new ArrayList<String>();
// get the id list from Zoho deleted Record
if (!deletedInZoho.isEmpty()) {
deletedInZoho.forEach(
deletedRecord ->
deletedEntityIds.add(
EntityRecordUtils.buildEntityIdUri(
EntityTypes.Organization, deletedRecord.getId().toString())));
generateZohoOrganizationUrl(deletedRecord.getId().longValue())
// EntityRecordUtils.
// buildEntityIdUri(
// EntityTypes.Organization, deletedRecord.getId().toString())
)
);
}
return deletedEntityIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void synchronizeZohoOrganizations(@NonNull OffsetDateTime modifiedSince,
if (isLastPage(orgList.size(), pageSize)) {
if (logger.isDebugEnabled()) {
logger.debug(
"Processing of deleted records is complete on page on page {}, pageSize {}, items on last page {}",
"Processing updated zoho records finished at page {}, pageSize {}, items on last page {}",
page, pageSize, orgList.size());
}
hasNext = false;
Expand Down Expand Up @@ -166,8 +166,10 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
int pageSize = emConfiguration.getZohoSyncBatchSize();
boolean hasNext = true;
int currentPageSize = 0;
List<String> entitiesDeletedInZoho = null;
List<String> entitiesZohoCoref = null;
// Zoho doesn't return the total results
List<EntityRecord> deletedEntityRecords;
List<String> entityIdsToDelete;
while (hasNext) {
try {
// list of (europeana) organizations ids
Expand All @@ -177,10 +179,15 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
currentPageSize = deletedRecordsInZoho.size();
// check exists in EM (Note: zoho doesn't support filtering by lastModified for deleted
// entities)
entitiesDeletedInZoho = getDeletedEntityIds(deletedRecordsInZoho);

// build delete operations set
runPermanentDelete(entitiesDeletedInZoho, zohoSyncReport);
//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();

//perform permanent deletion
runPermanentDelete(entityIdsToDelete, zohoSyncReport);
} catch (ZohoException e) {
logger.error(
"Zoho synchronization exception occured when handling organizations deleted in Zoho",
Expand All @@ -192,7 +199,7 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
e);
String message =
buildErrorMessage("Unexpected error occured when deleting organizations with ids: ",
entitiesDeletedInZoho);
entitiesZohoCoref);
zohoSyncReport.addFailedOperation(null, ZohoSyncReportFields.ENTITY_DELETION_ERROR, message,
e);
}
Expand All @@ -201,7 +208,7 @@ void synchronizeDeletedZohoOrganizations(OffsetDateTime modifiedSince,
// last page: if no more organizations exist in Zoho
if (logger.isDebugEnabled()) {
logger.debug(
"Processing of deleted records is complete on page on page {}, pageSize {}, items on last page {}",
"Processing of deleted records is completes at page {}, pageSize {}, items on last page {}",
startPage, pageSize, currentPageSize);
}
hasNext = false;
Expand Down

0 comments on commit 40eb9d6

Please sign in to comment.