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);