From 7b66f99170435178148a7d6f2d8a4f9bca9f6584 Mon Sep 17 00:00:00 2001 From: himeshr Date: Tue, 19 Dec 2023 12:31:22 +0530 Subject: [PATCH] #000 | Handle NPE encountered when GoonjSource entity is not found during errorRetrial --- .../goonj/repository/DemandRepository.java | 2 +- .../goonj/repository/DispatchRepository.java | 2 +- .../goonj/repository/InventoryRepository.java | 2 +- .../goonj/worker/AvniGoonjErrorRecordsWorker.java | 13 +++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DemandRepository.java b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DemandRepository.java index fe6b73d5..18d0f4cb 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DemandRepository.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DemandRepository.java @@ -52,6 +52,6 @@ public DemandsResponseDTO getDemands(Date dateTime) { public HashMap getDemand(String uuid) { DemandsResponseDTO response = super.getSingleEntityResponse("DemandService/getDemand", "demandId", uuid, DemandsResponseDTO.class); - return response.getDemands()[0]; + return response.getDemands().length > 0 ? response.getDemands()[0] : null; } } diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DispatchRepository.java b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DispatchRepository.java index 9e2b409d..4a314656 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DispatchRepository.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DispatchRepository.java @@ -54,6 +54,6 @@ public DispatchesResponseDTO getDispatches(Date dateTime) { public HashMap getDispatch(String uuid) { DispatchesResponseDTO response = super.getSingleEntityResponse("DispatchService/getDispatch", "dispatchStatusId", uuid, DispatchesResponseDTO.class); - return response.getDispatchStatuses()[0]; + return response.getDispatchStatuses().length > 0 ? response.getDispatchStatuses()[0] : null; } } diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/repository/InventoryRepository.java b/goonj/src/main/java/org/avni_integration_service/goonj/repository/InventoryRepository.java index 1cd9f83e..e2d30653 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/repository/InventoryRepository.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/repository/InventoryRepository.java @@ -48,6 +48,6 @@ public InventoryResponseDTO getInventoryItemsDTOS(Date dateTime) { public HashMap getInventoryItemsDTO(String uuid) { InventoryResponseDTO response = super.getSingleEntityResponse("ImplementationInventoryService/getImplementationInventories", "inventoryId", uuid, InventoryResponseDTO.class); - return response.getInventoryItemsDTOS()[0]; + return response.getInventoryItemsDTOS().length > 0 ? response.getInventoryItemsDTOS()[0] : null; } } diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/worker/AvniGoonjErrorRecordsWorker.java b/goonj/src/main/java/org/avni_integration_service/goonj/worker/AvniGoonjErrorRecordsWorker.java index 554e5648..155188f2 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/worker/AvniGoonjErrorRecordsWorker.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/worker/AvniGoonjErrorRecordsWorker.java @@ -85,14 +85,23 @@ else if (syncDirection.equals(SyncDirection.GoonjToAvni) && allErrors) .filter(er -> !er.hasThisAsLastErrorTypeFollowUpStep(ErrorTypeFollowUpStep.Terminal)) .collect(Collectors.toList()); for (ErrorRecord errorRecord : errorRecords) { - ErrorRecordWorker errorRecordWorker = getErrorRecordWorker(errorRecord); - errorRecordWorker.processError(errorRecord.getEntityId()); + retryErroredEntitySync(errorRecord); } logger.info(String.format("Completed page number: %d with number of errors: %d, for sync direction: %s", pageNumber, errorRecords.size(), syncDirection.name())); pageNumber++; } while (errorRecordPage.getNumberOfElements() == pageSize); } + private void retryErroredEntitySync(ErrorRecord errorRecord) { + ErrorRecordWorker errorRecordWorker = getErrorRecordWorker(errorRecord); + try { + errorRecordWorker.processError(errorRecord.getEntityId()); + } catch (Exception exception) { + logger.error(String.format("Failed to process errorRecord of type: %s with entityId : %s ", + errorRecord.getIntegratingEntityType(), errorRecord.getEntityId()), exception); + } + } + private ErrorRecordWorker getErrorRecordWorker(ErrorRecord errorRecord) { if (errorRecord.getIntegratingEntityType() != null) { if (errorRecord.getIntegratingEntityType().equals(GoonjEntityType.DispatchReceipt.name())) return dispatchReceiptWorker;