From 66e08cd3ffba3415abfce33ac7c1050279771c23 Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Mon, 16 Dec 2024 15:54:28 +0100 Subject: [PATCH] Migliorati log errore exchange documenti --- .../service/ExchangeColliImportService.java | 83 ++++++++++--------- .../ExchangeDocumentImportService.java | 15 ++-- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeColliImportService.java b/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeColliImportService.java index 062ecf6fdd..82a0d615d0 100644 --- a/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeColliImportService.java +++ b/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeColliImportService.java @@ -57,8 +57,8 @@ public class ExchangeColliImportService { private SetupGest setupGest; public void importLavorazione(MultiDBTransactionManager internalMultiDb, - MultiDBTransactionManager exchangeMultiDb, - RequestDataDTO requestDataDTO) throws Exception { + MultiDBTransactionManager exchangeMultiDb, + RequestDataDTO requestDataDTO) throws Exception { this.internalImport(internalMultiDb, exchangeMultiDb, requestDataDTO, ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione); } @@ -72,8 +72,8 @@ public class ExchangeColliImportService { public void importVendita(MultiDBTransactionManager internalMultiDb, - MultiDBTransactionManager exchangeMultiDb, - RequestDataDTO requestDataDTO) throws Exception { + MultiDBTransactionManager exchangeMultiDb, + RequestDataDTO requestDataDTO) throws Exception { this.internalImport(internalMultiDb, exchangeMultiDb, requestDataDTO, ExchangeImportSchemaManagerService.SchemaType.ColliVendita); } @@ -131,7 +131,6 @@ public class ExchangeColliImportService { final Exception[] firstExceptionToThrow = {null}; - while (startDate.minusDays(1).isBefore(UtilityLocalDate.getNow())) { final LocalDate tempStartDate = startDate; @@ -173,45 +172,49 @@ public class ExchangeColliImportService { String finalLogType = logType; - logger.debug("Importati {} colli di " + finalLogType + " di {}", importedCounter.incrementAndGet(), dataCount); - try (MultiDBTransactionManager exchangeMultiDbThread = new MultiDBTransactionManager(exchangeMultiDb.getPrimaryDatasource().getProfile(), false); - MultiDBTransactionManager internalMultiDbThread = new MultiDBTransactionManager(internalMultiDb.getPrimaryDatasource().getProfile(), false)) { + logger.debug("Importati {} colli di " + finalLogType + " di {}", importedCounter.incrementAndGet(), dataCount); + try (MultiDBTransactionManager exchangeMultiDbThread = new MultiDBTransactionManager(exchangeMultiDb.getPrimaryDatasource().getProfile(), false); + MultiDBTransactionManager internalMultiDbThread = new MultiDBTransactionManager(internalMultiDb.getPrimaryDatasource().getProfile(), false)) { - MtbColt mtbColtToSave = (MtbColt) dataToSave; - if (mtbColtToSave.hasDocument() && mtbColtToSave.getOperation() == OperationType.DELETE) { - MtbColt mtbColtRemoveDocument = (MtbColt) mtbColtToSave.clone(); - mtbColtRemoveDocument.setMtbColr(new ArrayList<>()) - .setCodDtip(EmsRestConstants.NULL) - .setSerDoc(EmsRestConstants.NULL) - .setDataDoc(EmsRestConstants.DATE_NULL) - .setNumDoc(EmsRestConstants.INTEGER_NULL) - .setOperation(OperationType.UPDATE); + MtbColt mtbColtToSave = (MtbColt) dataToSave; + if (mtbColtToSave.hasDocument() && mtbColtToSave.getOperation() == OperationType.DELETE) { + MtbColt mtbColtRemoveDocument = (MtbColt) mtbColtToSave.clone(); + mtbColtRemoveDocument.setMtbColr(new ArrayList<>()) + .setCodDtip(EmsRestConstants.NULL) + .setSerDoc(EmsRestConstants.NULL) + .setDataDoc(EmsRestConstants.DATE_NULL) + .setNumDoc(EmsRestConstants.INTEGER_NULL) + .setOperation(OperationType.UPDATE); - entityProcessor.processEntity(mtbColtRemoveDocument, true, true, EXCHANGE_USER, internalMultiDbThread, requestDataDTO); + entityProcessor.processEntity(mtbColtRemoveDocument, true, true, EXCHANGE_USER, internalMultiDbThread, requestDataDTO); - mtbColtToSave.setCodDtip(null) - .setSerDoc(null) - .setDataDoc(null) - .setNumDoc(null); - } - - entityProcessor.processEntity(mtbColtToSave, true, true, EXCHANGE_USER, internalMultiDbThread, requestDataDTO); - singleUpdateImported(exchangeMultiDbThread.getPrimaryConnection(), mtbColtToSave, testataTableName, useTempTable); - singleUpdateImported(exchangeMultiDbThread.getPrimaryConnection(), mtbColtToSave, righeTableName, useTempTable); - - internalMultiDbThread.commitAll(); - exchangeMultiDbThread.commitAll(); - } catch (Exception ex) { - MtbColt collo = (MtbColt) dataToSave; - Exception newException = new EntityException("Errore durante l'importazione del collo di " + finalLogType + - " [num: " + collo.getNumCollo() + ", " + - "data: " + UtilityLocalDate.formatDate(collo.getDataCollo(), CommonConstants.DATE_FORMAT_DMY) + ", " + - "serie: " + collo.getSerCollo() + ", " + - "gestione: " + collo.getGestione() + "]", ex); - - if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = newException; - logger.error(newException); + mtbColtToSave.setCodDtip(null) + .setSerDoc(null) + .setDataDoc(null) + .setNumDoc(null); } + + entityProcessor.processEntity(mtbColtToSave, true, true, EXCHANGE_USER, internalMultiDbThread, requestDataDTO); + singleUpdateImported(exchangeMultiDbThread.getPrimaryConnection(), mtbColtToSave, testataTableName, useTempTable); + singleUpdateImported(exchangeMultiDbThread.getPrimaryConnection(), mtbColtToSave, righeTableName, useTempTable); + + internalMultiDbThread.commitAll(); + exchangeMultiDbThread.commitAll(); + } catch (Exception ex) { + + internalMultiDb.rollbackAll(); + exchangeMultiDb.rollbackAll(); + + MtbColt collo = (MtbColt) dataToSave; + Exception newException = new EntityException("Errore durante l'importazione del collo di " + finalLogType + + " [num: " + collo.getNumCollo() + ", " + + "data: " + UtilityLocalDate.formatDate(collo.getDataCollo(), CommonConstants.DATE_FORMAT_DMY) + ", " + + "serie: " + collo.getSerCollo() + ", " + + "gestione: " + collo.getGestione() + "]", ex); + + if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = newException; + logger.error(newException); + } } } diff --git a/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeDocumentImportService.java b/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeDocumentImportService.java index 8441b8f59f..859610a066 100644 --- a/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeDocumentImportService.java +++ b/ems-engine/src/main/java/it/integry/ems/system/exchange/service/ExchangeDocumentImportService.java @@ -1,6 +1,5 @@ package it.integry.ems.system.exchange.service; -import it.integry.ems.dto.Result; import it.integry.ems.javabeans.RequestDataDTO; import it.integry.ems.service.EntityProcessor; import it.integry.ems.sync.MultiDBTransaction.Connection; @@ -10,6 +9,7 @@ import it.integry.ems.system.exchange.service.structure.ExchangeImportSchemaMana import it.integry.ems_model.base.EquatableEntityInterface; import it.integry.ems_model.entity.DtbDocr; import it.integry.ems_model.entity.DtbDoct; +import it.integry.ems_model.exception.EntityException; import it.integry.ems_model.exception.MergeEntityDBToObjectException; import it.integry.ems_model.types.OperationType; import it.integry.ems_model.utility.Query; @@ -105,7 +105,7 @@ public class ExchangeDocumentImportService { AtomicInteger importedCounter = new AtomicInteger(0); LocalDate startDate = LocalDate.of(2024, 7, 1); - Result firstErrorObjectIfPresent = null; + final Exception[] firstExceptionToThrow = {null}; while (startDate.minusDays(1).isBefore(UtilityLocalDate.getNow())) { @@ -169,11 +169,7 @@ public class ExchangeDocumentImportService { internalMultiDb.commitAll(); exchangeMultiDb.commitAll(); } catch (Exception ex) { - - - if (firstErrorObjectIfPresent == null) firstErrorObjectIfPresent = new Result.Error<>(ex); - - logger.error("Errore durante l'importazione del documento di " + logType + " [" + + Exception newException = new EntityException("Errore durante l'importazione del documento di " + logType + " [" + "num: " + document.getNumDoc() + ", " + "serie: " + document.getSerDoc() + ", " + "data: " + document.getDataDoc() + ", " + @@ -182,13 +178,16 @@ public class ExchangeDocumentImportService { internalMultiDb.rollbackAll(); exchangeMultiDb.rollbackAll(); + + if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = newException; + logger.error(newException); } } } - if (firstErrorObjectIfPresent != null) throw ((Result.Error) firstErrorObjectIfPresent).getError(); + if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0]; } finally { if (useTempTable) exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), schemaType);