Skip to content

Commit

Permalink
#000 | Handle NPE encountered when GoonjSource entity is not found du…
Browse files Browse the repository at this point in the history
…ring errorRetrial
  • Loading branch information
himeshr committed Dec 19, 2023
1 parent d61e4ee commit 7b66f99
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public DemandsResponseDTO getDemands(Date dateTime) {

public HashMap<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public DispatchesResponseDTO getDispatches(Date dateTime) {

public HashMap<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public InventoryResponseDTO getInventoryItemsDTOS(Date dateTime) {

public HashMap<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b66f99

Please sign in to comment.