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/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)); 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;