From 3329067a1f5a69f8c2cb6e01883e5fe61a410e32 Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Thu, 19 Dec 2024 15:41:36 +0100 Subject: [PATCH 1/2] Fix importazione colli exchange --- .../ems_model/exception/EntityException.java | 10 ++--- .../ems_model/utility/UtilityException.java | 4 +- .../service/ExchangeColliImportService.java | 38 ++++++++++--------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/ems-core/src/main/java/it/integry/ems_model/exception/EntityException.java b/ems-core/src/main/java/it/integry/ems_model/exception/EntityException.java index 571c0b07d3..9b3c598834 100644 --- a/ems-core/src/main/java/it/integry/ems_model/exception/EntityException.java +++ b/ems-core/src/main/java/it/integry/ems_model/exception/EntityException.java @@ -26,16 +26,16 @@ public class EntityException extends Exception { this.mInnerException = innerException; } - public EntityException(Exception e, EntityBase entity, String query) { + public EntityException(Exception innerException, EntityBase entity, String query) { super("Impossibile salvare la entity " + entity.getTableName() + ".\n " + - e.getMessage() + "\n" + + innerException.getMessage() + "\n" + query + "\n"); this.mEntityTableName = entity.getTableName(); - this.mInnerException = e; + this.mInnerException = innerException; - if (e instanceof SQLException) { - sqlErrorCode = ((SQLException) e).getErrorCode(); + if (innerException instanceof SQLException) { + sqlErrorCode = ((SQLException) innerException).getErrorCode(); } } diff --git a/ems-core/src/main/java/it/integry/ems_model/utility/UtilityException.java b/ems-core/src/main/java/it/integry/ems_model/utility/UtilityException.java index 48c03a8d3c..6e3759d2cb 100644 --- a/ems-core/src/main/java/it/integry/ems_model/utility/UtilityException.java +++ b/ems-core/src/main/java/it/integry/ems_model/utility/UtilityException.java @@ -29,10 +29,10 @@ public class UtilityException { if (entityException.getInnerException() instanceof RuntimeException) { message += entityException.getInnerException().getCause().getMessage() + "\n"; isRuntimeException = true; + } else { + message += entityException.getMessage() + "\n"; } - message += "Impossibile salvare l'entity: " + entityException.getEntityTableName(); - String startMatch = "it.integry.rules.Rule_"; String endMatch = "Eval"; if (entityException.getInnerException().getMessage().startsWith(startMatch)) { 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 6250c8a893..01b5f51476 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 @@ -127,26 +127,15 @@ public class ExchangeColliImportService { String sqlDistinctDates = "SELECT DISTINCT CAST(data_collo AS DATE) FROM " + testataTableName + (useTempTable ? "_tmp" : ""); List mtbColtDates = UtilityDB.executeSimpleQueryOnlyFirstColumn(exchangeMultiDb.getPrimaryConnection(), sqlDistinctDates); - mtbColtDates = mtbColtDates.stream().sorted().collect(Collectors.toList()); + List mtbColtLocalDates = mtbColtDates.stream().map(Date::toLocalDate).sorted().collect(Collectors.toList()); -// String sqlMinDate = "SELECT CAST(MIN(data_collo) AS DATE) FROM " + testataTableName + (useTempTable ? "_tmp" : ""); -// Date startDateTimeStamp = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(exchangeMultiDb.getPrimaryConnection(), sqlMinDate); + mtbColtLocalDates = mtbColtLocalDates.stream() + .filter(x -> x.isEqual(LocalDate.of(2024, 10, 28))) + .collect(Collectors.toList()); -// LocalDate startDate = startDateTimeStamp.toLocalDate(); -// LocalDate startDate = LocalDate.of(2024, 7, 1); final Exception[] firstExceptionToThrow = {null}; - for (Date mtbColtDate : mtbColtDates) { - LocalDate mtbColtLocalDate = mtbColtDate.toLocalDate(); - -// } -// -// while (startDate.minusDays(1).isBefore(UtilityLocalDate.getNow())) { - -// final LocalDate tempStartDate = mtbColtLocalDate; -// final LocalDate tempEndDate = mtbColtLocalDate; - -// startDate = startDate.plusDays(1); + for (LocalDate mtbColtLocalDate : mtbColtLocalDates) { List exchangeImportedMtbColts = retrieveColli( exchangeMultiDb.getPrimaryConnection(), @@ -185,8 +174,11 @@ public class ExchangeColliImportService { logger.debug("Importati {} colli di " + finalLogType + " di {}", importedCounter.incrementAndGet(), dataCount); try { + MtbColt mtbColtOriginal = (MtbColt) dataToSave.clone(); MtbColt mtbColtToSave = (MtbColt) dataToSave; - if (mtbColtToSave.hasDocument() && mtbColtToSave.getOperation() == OperationType.DELETE) { + if (mtbColtToSave.hasDocument() && + (mtbColtToSave.getOperation() == OperationType.DELETE || + mtbColtToSave.getMtbColr().stream().anyMatch(x -> x.getOperation() == OperationType.DELETE))) { MtbColt mtbColtRemoveDocument = (MtbColt) mtbColtToSave.clone(); mtbColtRemoveDocument.setMtbColr(new ArrayList<>()) .setCodDtip(EmsRestConstants.NULL) @@ -204,6 +196,18 @@ public class ExchangeColliImportService { } entityProcessor.processEntity(mtbColtToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO); + + if (mtbColtOriginal.hasDocument() && mtbColtOriginal.getOperation() != OperationType.DELETE && + mtbColtToSave.getMtbColr().stream().anyMatch(x -> x.getOperation() == OperationType.DELETE)) { + mtbColtToSave.setCodDtip(mtbColtOriginal.getCodDtip()) + .setSerDoc(mtbColtOriginal.getSerDoc()) + .setDataDoc(mtbColtOriginal.getDataDoc()) + .setNumDoc(mtbColtOriginal.getNumDoc()) + .setOperation(OperationType.UPDATE); + + entityProcessor.processEntity(mtbColtToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO); + } + singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), mtbColtToSave, testataTableName, useTempTable); singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), mtbColtToSave, righeTableName, useTempTable); From dc129624357b9e6774b91e360466700300b395d0 Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Thu, 19 Dec 2024 15:42:32 +0100 Subject: [PATCH 2/2] Fix importazione colli exchange --- .../system/exchange/service/ExchangeColliImportService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 01b5f51476..d60d03df9f 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 @@ -129,9 +129,9 @@ public class ExchangeColliImportService { List mtbColtLocalDates = mtbColtDates.stream().map(Date::toLocalDate).sorted().collect(Collectors.toList()); - mtbColtLocalDates = mtbColtLocalDates.stream() - .filter(x -> x.isEqual(LocalDate.of(2024, 10, 28))) - .collect(Collectors.toList()); +// mtbColtLocalDates = mtbColtLocalDates.stream() +// .filter(x -> x.isEqual(LocalDate.of(2024, 10, 28))) +// .collect(Collectors.toList()); final Exception[] firstExceptionToThrow = {null};