From 7b66f99170435178148a7d6f2d8a4f9bca9f6584 Mon Sep 17 00:00:00 2001 From: himeshr Date: Tue, 19 Dec 2023 12:31:22 +0530 Subject: [PATCH 1/2] #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; From 07a1da877596bd5df0e27ab22c9721e054dcd956 Mon Sep 17 00:00:00 2001 From: himeshr Date: Tue, 19 Dec 2023 17:13:34 +0530 Subject: [PATCH 2/2] #108 | Convert distributionDate to IST from UTC --- .../goonj/repository/DistributionRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DistributionRepository.java b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DistributionRepository.java index 0aea1678..1771f6df 100644 --- a/goonj/src/main/java/org/avni_integration_service/goonj/repository/DistributionRepository.java +++ b/goonj/src/main/java/org/avni_integration_service/goonj/repository/DistributionRepository.java @@ -88,6 +88,7 @@ private DistributionDTO createDistributionRequest(Subject subject) { distributionDTO.setNameOfAccount((String) subject.getObservation(ACCOUNT_NAME)); /* Distribution Related fields*/ Date distributionDate = DateTimeUtil.convertToDate((String) subject.getObservation(DISTRIBUTION_DATE)); + distributionDate = DateTimeUtil.offsetTimeZone(distributionDate, DateTimeUtil.UTC, DateTimeUtil.IST); distributionDTO.setDateOfDistribution(DateTimeUtil.formatDate(distributionDate)); distributionDTO.setTypeOfCommunity((String) subject.getObservation(TARGET_COMMUNITY)); distributionDTO.setDisasterType((String) subject.getObservation(TYPE_OF_DISASTER));