Skip to content

Commit

Permalink
MDEXP-787 - Export all - Combine "error.nonExisting.instance" and "er…
Browse files Browse the repository at this point in the history
…ror.deletedDuplicate.instance" errors
  • Loading branch information
khandramai committed Sep 16, 2024
1 parent 7e3d138 commit 23e7ed8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.stream.Collectors.toMap;
import static net.minidev.json.parser.JSONParser.DEFAULT_PERMISSIVE_MODE;
import static org.folio.dataexp.service.export.Constants.DELETED_KEY;
import static org.folio.dataexp.service.export.Constants.OUTPUT_BUFFER_SIZE;
import static org.folio.dataexp.util.ErrorCode.ERROR_CONVERTING_JSON_TO_MARC;
import static org.folio.dataexp.util.ErrorCode.ERROR_FIELDS_MAPPING_SRS;
Expand All @@ -17,7 +16,6 @@
import org.folio.dataexp.domain.dto.ExportRequest;
import org.folio.dataexp.domain.dto.MappingProfile;
import org.folio.dataexp.domain.entity.ExportIdEntity;
import org.folio.dataexp.domain.entity.InstanceEntity;
import org.folio.dataexp.domain.entity.JobExecutionExportFilesEntity;
import org.folio.dataexp.domain.entity.JobExecutionExportFilesStatus;
import org.folio.dataexp.domain.entity.MarcRecordEntity;
Expand Down Expand Up @@ -205,28 +203,17 @@ private void saveDuplicateErrors(LinkedHashMap<UUID, Optional<ExportIdentifiersF
List<MarcRecordEntity> marcRecords, UUID jobExecutionId) {
var externalIdsAsKeys = duplicatedUuidWithIdentifiers.keySet();
var srsIdByExternalId = getSrsIdByExternalIdMap(marcRecords);
var deletedSrsIdByExternalId = getSrsIdByDeletedExternalIdMap(marcRecords);
for (var externalId : externalIdsAsKeys) {
var exportIdentifiersOpt = duplicatedUuidWithIdentifiers.get(externalId);
if (exportIdentifiersOpt.isPresent()) {
var exportIdentifiers = exportIdentifiersOpt.get();
var errorMessage = getDuplicatedSRSErrorMessage(externalId, marcRecords, exportIdentifiers);
log.warn(errorMessage);
if (exportIdentifiers.getAssociatedJsonObject() != null) {
var associatedJson = exportIdentifiers.getAssociatedJsonObject();
if (deletedSrsIdByExternalId.containsKey(externalId)) {
associatedJson.put(DELETED_KEY, true);
errorLogService.saveGeneralErrorWithMessageValues(ErrorCode.ERROR_DELETED_DUPLICATED_INSTANCE.getCode(), List.of(deletedSrsIdByExternalId.get(externalId).toString()), jobExecutionId);
log.error(String.format(ErrorCode.ERROR_DELETED_DUPLICATED_INSTANCE.getDescription(), deletedSrsIdByExternalId.get(externalId)));
}
errorLogService.saveWithAffectedRecord(associatedJson, errorMessage, ErrorCode.ERROR_DUPLICATE_SRS_RECORD.getCode(), jobExecutionId);
} else {
if (instanceEntityRepository.findByIdIn(Set.of(externalId)).isEmpty()) {
errorLogService.saveGeneralErrorWithMessageValues(ErrorCode.ERROR_NON_EXISTING_INSTANCE.getCode(),
List.of(String.format(ErrorCode.ERROR_NON_EXISTING_INSTANCE.getDescription(), srsIdByExternalId.get(externalId))), jobExecutionId);
}
errorLogService.saveGeneralErrorWithMessageValues(ErrorCode.ERROR_DUPLICATE_SRS_RECORD.getCode(), List.of(errorMessage), jobExecutionId);
if (instanceEntityRepository.findByIdIn(Set.of(externalId)).isEmpty()) {
errorLogService.saveGeneralErrorWithMessageValues(ErrorCode.ERROR_NON_EXISTING_INSTANCE.getCode(),
List.of(String.format(ErrorCode.ERROR_NON_EXISTING_INSTANCE.getDescription(), srsIdByExternalId.get(externalId))), jobExecutionId);
}
errorLogService.saveGeneralErrorWithMessageValues(ErrorCode.ERROR_DUPLICATE_SRS_RECORD.getCode(), List.of(errorMessage), jobExecutionId);
}
}
}
Expand Down Expand Up @@ -277,7 +264,7 @@ protected void processSlices(JobExecutionExportFilesEntity exportFilesEntity,
}

@Autowired
private void setInstanceEntityRepository(InstanceEntityRepository instanceEntityRepository) {
protected void setInstanceEntityRepository(InstanceEntityRepository instanceEntityRepository) {
this.instanceEntityRepository = instanceEntityRepository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
import org.folio.dataexp.service.export.strategies.handlers.RuleHandler;
import org.folio.dataexp.service.logs.ErrorLogService;
import org.folio.dataexp.service.transformationfields.ReferenceDataProvider;
import org.folio.dataexp.util.ErrorCode;
import org.folio.processor.RuleProcessor;
import org.folio.spring.FolioExecutionContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mapstruct.ap.internal.util.Collections;
import org.marc4j.MarcException;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.util.ReflectionTestUtils;

import java.io.IOException;
Expand All @@ -39,6 +42,7 @@
import static org.folio.dataexp.util.ErrorCode.ERROR_DELETED_DUPLICATED_INSTANCE;
import static org.folio.dataexp.util.ErrorCode.ERROR_DELETED_TOO_LONG_INSTANCE;
import static org.folio.dataexp.util.ErrorCode.ERROR_MESSAGE_JSON_CANNOT_BE_CONVERTED_TO_MARC;
import static org.folio.dataexp.util.ErrorCode.ERROR_NON_EXISTING_INSTANCE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -137,8 +141,10 @@ void saveConvertJsonRecordToMarcRecordErrorIfErrorRecordTooLongAndInstanceDelete
@Test
void saveDuplicateErrorsIfInstanceDeletedTest() {
instancesExportAllStrategy.setErrorLogService(errorLogService);
instancesExportAllStrategy.setInstanceEntityRepository(instanceEntityRepository);

ReflectionTestUtils.setField(instancesExportAllStrategy, "jsonToMarcConverter", jsonToMarcConverter);

var auditInstanceEntity = AuditInstanceEntity.builder()
.id(UUID.randomUUID()).hrid("123").title("title").build();
var jobExecutionId = UUID.randomUUID();
Expand All @@ -153,7 +159,8 @@ void saveDuplicateErrorsIfInstanceDeletedTest() {
when(auditInstanceEntityRepository.findByIdIn(anySet())).thenReturn(List.of(auditInstanceEntity));

instancesExportAllStrategy.createAndSaveMarcFromJsonRecord(externalIds, statistic, new MappingProfile(), jobExecutionId, Set.of(instanceId), List.of(marcRecord, marcRecordDuplicate), localStorageWriter);
verify(errorLogService).saveGeneralErrorWithMessageValues(eq(ERROR_DELETED_DUPLICATED_INSTANCE.getCode()), eq(List.of(marcRecord.getId().toString())), isA(UUID.class));
verify(errorLogService).saveGeneralErrorWithMessageValues(eq(ERROR_NON_EXISTING_INSTANCE.getCode()), eq(List.of(marcRecord.getId().toString())), isA(UUID.class));

}

@Test
Expand Down

0 comments on commit 23e7ed8

Please sign in to comment.