Skip to content

Commit

Permalink
#122 | Make Goonj Error type name in ErrorRecordLog independent of Go…
Browse files Browse the repository at this point in the history
…onjErrorType Enum
  • Loading branch information
himeshr committed Apr 11, 2024
1 parent 2601bee commit 12b84b0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.log4j.Logger;
import org.avni_integration_service.goonj.GoonjEntityType;
import org.avni_integration_service.goonj.GoonjErrorType;
import org.avni_integration_service.goonj.config.GoonjContextProvider;
import org.avni_integration_service.integration_data.domain.AvniEntityType;
import org.avni_integration_service.integration_data.domain.error.ErrorRecord;
Expand Down Expand Up @@ -37,8 +36,9 @@ public List<ErrorType> getUnprocessableErrorTypes() {
return getErrorTypeBy(ErrorTypeFollowUpStep.Terminal);
}

private void saveAvniError(String uuid, GoonjErrorType goonjErrorType, AvniEntityType avniEntityType, String errorMsg) {
ErrorType errorType = getErrorType(goonjErrorType);

private void saveAvniError(String uuid, String goonjErrorTypeName, AvniEntityType avniEntityType, String errorMsg) {
ErrorType errorType = getErrorType(goonjErrorTypeName);
ErrorRecord errorRecord = errorRecordRepository.findByAvniEntityTypeAndEntityId(avniEntityType, uuid);
if (errorRecord != null && errorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType, errorMsg)) {
logger.info(String.format("Same error as the last processing for entity uuid %s, and type %s", uuid, avniEntityType));
Expand All @@ -60,18 +60,18 @@ private void saveAvniError(String uuid, GoonjErrorType goonjErrorType, AvniEntit
}
}

private ErrorType getErrorType(GoonjErrorType goonjErrorType) {
return errorTypeRepository.findByNameAndIntegrationSystemId(goonjErrorType.name(), goonjContextProvider.get().getIntegrationSystem().getId());
private ErrorType getErrorType(String goonjErrorTypeName) {
return errorTypeRepository.findByNameAndIntegrationSystemId(goonjErrorTypeName, goonjContextProvider.get().getIntegrationSystem().getId());
}

private List<ErrorType> getErrorTypeBy(ErrorTypeFollowUpStep followUpStep) {
return errorTypeRepository.findByIntegrationSystemIdAndFollowUpStep(
goonjContextProvider.get().getIntegrationSystem().getId(), String.valueOf(followUpStep.ordinal()));
}

private ErrorRecord saveGoonjError(String uuid, GoonjErrorType goonjErrorType, GoonjEntityType goonjEntityType, String errorMsg) {
private ErrorRecord saveGoonjError(String uuid, String goonjErrorTypeName, GoonjEntityType goonjEntityType, String errorMsg) {
ErrorRecord errorRecord = errorRecordRepository.findByIntegratingEntityTypeAndEntityId(goonjEntityType.name(), uuid);
ErrorType errorType = getErrorType(goonjErrorType);
ErrorType errorType = getErrorType(goonjErrorTypeName);
if (errorRecord != null && errorRecord.hasThisAsLastErrorTypeAndErrorMessage(errorType, errorMsg)) {
logger.info(String.format("Same error as the last processing for entity uuid %s, and type %s", uuid, goonjEntityType));
if (!errorRecord.isProcessingDisabled()) {
Expand All @@ -96,12 +96,12 @@ private ErrorRecord saveGoonjError(String uuid, GoonjErrorType goonjErrorType, G
}


public ErrorRecord errorOccurred(String entityUuid, GoonjErrorType goonjErrorType, GoonjEntityType goonjEntityType, String errorMsg) {
return saveGoonjError(entityUuid, goonjErrorType, goonjEntityType, errorMsg);
public ErrorRecord errorOccurred(String entityUuid, String goonjErrorTypeName, GoonjEntityType goonjEntityType, String errorMsg) {
return saveGoonjError(entityUuid, goonjErrorTypeName, goonjEntityType, errorMsg);
}

public void errorOccurred(String entityUuid, GoonjErrorType goonjErrorType, AvniEntityType avniEntityType, String errorMsg) {
saveAvniError(entityUuid, goonjErrorType, avniEntityType, errorMsg);
public void errorOccurred(String entityUuid, String goonjErrorTypeName, AvniEntityType avniEntityType, String errorMsg) {
saveAvniError(entityUuid, goonjErrorTypeName, avniEntityType, errorMsg);
}

private void successfullyProcessedGoonjEntity(GoonjEntityType goonjEntityType, String uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void processError(String entityUuid) throws Exception {
if (generalEncounter == null) {
String message = String.format("GeneralEncounter has been deleted now: %s", entityUuid);
logger.warn(message);
avniGoonjErrorService.errorOccurred(entityUuid, GoonjErrorType.EntityIsDeleted, AvniEntityType.GeneralEncounter, message);
avniGoonjErrorService.errorOccurred(entityUuid, GoonjErrorType.EntityIsDeleted.name(), AvniEntityType.GeneralEncounter, message);
return;
}

Expand Down Expand Up @@ -133,9 +133,8 @@ protected void handleError(GeneralEncounter generalEncounter, Exception exceptio
if (classifiedErrorType == null) {
throw exception;
}
GoonjErrorType errorType = GoonjErrorType.safeGetValueOf(classifiedErrorType.getName(), goonjErrorType);
createOrUpdateErrorRecordAndSyncStatus(generalEncounter, updateSyncStatus, generalEncounter.getUuid(),
errorType, exception.getLocalizedMessage());
classifiedErrorType.getName(), exception.getLocalizedMessage());
}

protected abstract void createOrUpdateGeneralEncounter(GeneralEncounter generalEncounter, Subject subject);
Expand All @@ -160,8 +159,8 @@ private void updateErrorRecordAndSyncStatus(GeneralEncounter generalEncounter, b
updateSyncStatus(generalEncounter, updateSyncStatus);
}

private void createOrUpdateErrorRecordAndSyncStatus(GeneralEncounter generalEncounter, boolean updateSyncStatus, String sid, GoonjErrorType goonjErrorType, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorType, entityType, errorMsg);
private void createOrUpdateErrorRecordAndSyncStatus(GeneralEncounter generalEncounter, boolean updateSyncStatus, String sid, String goonjErrorTypeName, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorTypeName, entityType, errorMsg);
updateSyncStatus(generalEncounter, updateSyncStatus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void processError(String entityUuid) throws Exception {
if (subject == null) {
String message = String.format("Subject has been deleted now: %s", entityUuid);
logger.warn(message);
avniGoonjErrorService.errorOccurred(entityUuid, GoonjErrorType.EntityIsDeleted, AvniEntityType.Subject, message);
avniGoonjErrorService.errorOccurred(entityUuid, GoonjErrorType.EntityIsDeleted.name(), AvniEntityType.Subject, message);
return;
}

Expand Down Expand Up @@ -121,9 +121,8 @@ protected void handleError(Subject subject, Exception exception,
if (classifiedErrorType == null) {
throw exception;
}
GoonjErrorType errorType = GoonjErrorType.safeGetValueOf(classifiedErrorType.getName(), goonjErrorType);
createOrUpdateErrorRecordAndSyncStatus(subject, updateSyncStatus, subject.getUuid(),
errorType, exception.getLocalizedMessage());
classifiedErrorType.getName(), exception.getLocalizedMessage());
}

protected abstract void createSubject(Subject subject);
Expand All @@ -148,8 +147,8 @@ private void updateErrorRecordAndSyncStatus(Subject subject, boolean updateSyncS
updateSyncStatus(subject, updateSyncStatus);
}

private void createOrUpdateErrorRecordAndSyncStatus(Subject subject, boolean updateSyncStatus, String sid, GoonjErrorType goonjErrorType, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorType, entityType, errorMsg);
private void createOrUpdateErrorRecordAndSyncStatus(Subject subject, boolean updateSyncStatus, String sid, String goonjErrorTypeName, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorTypeName, entityType, errorMsg);
updateSyncStatus(subject, updateSyncStatus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void processDispatchLineItemDeletion(DeletedDispatchStatusLineItem delete
} catch (Exception e) {
logger.error(String.format("Failed to delete dispatch line items: externalId %s", deletedEntity.getDispatchStatusLineItemId()));
createOrUpdateErrorRecordAndSyncStatus(null, false, deletedEntity.getDispatchStatusLineItemId(),
GoonjErrorType.DispatchLineItemsDeletionFailure, e.getLocalizedMessage());
GoonjErrorType.DispatchLineItemsDeletionFailure.name(), e.getLocalizedMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void updateErrorRecordAndSyncStatus(Map<String, Object> callResponse, boolean up
}

void createOrUpdateErrorRecordAndSyncStatus(Map<String, Object> callResponse, boolean updateSyncStatus, String sid,
GoonjErrorType goonjErrorType, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorType, entityType, errorMsg);
String goonjErrorTypeName, String errorMsg) {
avniGoonjErrorService.errorOccurred(sid, goonjErrorTypeName, entityType, errorMsg);
updateSyncStatus(callResponse, updateSyncStatus);
}

Expand Down Expand Up @@ -69,9 +69,8 @@ protected void handleError(Map<String, Object> event, Exception exception, Strin
if(classifiedErrorType == null) {
throw exception;
}
GoonjErrorType errorType = GoonjErrorType.safeGetValueOf(classifiedErrorType.getName(), goonjErrorType);
createOrUpdateErrorRecordAndSyncStatus(event, updateSyncStatus, (String) event.get(entityId),
errorType , exception.getLocalizedMessage());
classifiedErrorType.getName() , exception.getLocalizedMessage());
}

public abstract void processDeletion(String deletedEntity);
Expand Down

0 comments on commit 12b84b0

Please sign in to comment.