Merge branch 'master' into develop
This commit is contained in:
@@ -5,6 +5,8 @@ import it.integry.ems.expansion.RunnableThrowable;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.system.exchange.service.structure.ExchangeImportDataManagerService;
|
||||
import it.integry.ems.system.exchange.service.structure.ExchangeImportSchemaManagerService;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity.*;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
@@ -46,95 +48,95 @@ public class ExchangeBancheImportService {
|
||||
|
||||
boolean useTempTable = true;
|
||||
|
||||
try {
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche, useTempTable);
|
||||
try {
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche, useTempTable);
|
||||
|
||||
|
||||
importBanche(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO);
|
||||
importBanche(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO);
|
||||
|
||||
final List<GtbBancAzi> exchangeImportedDataBancheAzi = retrieveBancheAzi(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
final List<GtbBancAzi> exchangeImportedDataBancheAzi = retrieveBancheAzi(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
|
||||
final List<GtbBancAzi> exchangeUpdatedDataBancheAzi = retrieveBancheAzi(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
final List<GtbBancAzi> exchangeUpdatedDataBancheAzi = retrieveBancheAzi(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
|
||||
final List<GtbBancAziIntercode> exchangeImportedDataBancheIntercode = retrieveBancheIntercode(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
final List<GtbBancAziIntercode> exchangeImportedDataBancheIntercode = retrieveBancheIntercode(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
|
||||
final List<GtbBancAziIntercode> exchangeUpdatedDataBancheIntercode = retrieveBancheIntercode(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
|
||||
List<EquatableEntityInterface> allDataBancheAzie = exchangeImportDataManagerService
|
||||
.runSync(GtbBancAzi.class, exchangeImportedDataBancheAzi, exchangeUpdatedDataBancheAzi);
|
||||
final List<GtbBancAziIntercode> exchangeUpdatedDataBancheIntercode = retrieveBancheIntercode(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
|
||||
List<EquatableEntityInterface> allDataBancheIntercode = exchangeImportDataManagerService
|
||||
.runSync(GtbBancAziIntercode.class, exchangeImportedDataBancheIntercode, exchangeUpdatedDataBancheIntercode );
|
||||
List<EquatableEntityInterface> allDataBancheAzie = exchangeImportDataManagerService
|
||||
.runSync(GtbBancAzi.class, exchangeImportedDataBancheAzi, exchangeUpdatedDataBancheAzi);
|
||||
|
||||
allDataBancheAzie.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||
allDataBancheIntercode.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||
List<EquatableEntityInterface> allDataBancheIntercode = exchangeImportDataManagerService
|
||||
.runSync(GtbBancAziIntercode.class, exchangeImportedDataBancheIntercode, exchangeUpdatedDataBancheIntercode);
|
||||
|
||||
allDataBancheAzie = allDataBancheAzie.stream().filter(x -> x.getOperation() != OperationType.DELETE)
|
||||
.collect(Collectors.toList());
|
||||
allDataBancheIntercode = allDataBancheIntercode.stream().filter(x -> x.getOperation() != OperationType.DELETE)
|
||||
.collect(Collectors.toList());
|
||||
allDataBancheAzie.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||
allDataBancheIntercode.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||
|
||||
List<EquatableEntityInterface> finalAllBancheData = allDataBancheAzie;
|
||||
List<EquatableEntityInterface> finalAllBancheDataIntercode = allDataBancheIntercode;
|
||||
allDataBancheAzie = allDataBancheAzie.stream().filter(x -> x.getOperation() != OperationType.DELETE)
|
||||
.collect(Collectors.toList());
|
||||
allDataBancheIntercode = allDataBancheIntercode.stream().filter(x -> x.getOperation() != OperationType.DELETE)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
allDataBancheIntercode.stream()
|
||||
.map(x -> (GtbBancAziIntercode) x)
|
||||
.filter(x -> finalAllBancheData.stream()
|
||||
.map(y -> (GtbBancAzi) y)
|
||||
.noneMatch(y -> x.getCodBancAzi().equalsIgnoreCase(y.getCodBancAzi()) ))
|
||||
.forEach(x -> {
|
||||
GtbBancAzi testata = new GtbBancAzi()
|
||||
.setCodBancAzi(x.getCodBancAzi());
|
||||
List<EquatableEntityInterface> finalAllBancheData = allDataBancheAzie;
|
||||
List<EquatableEntityInterface> finalAllBancheDataIntercode = allDataBancheIntercode;
|
||||
|
||||
testata.setOperation(OperationType.UPDATE);
|
||||
finalAllBancheData.add(testata);
|
||||
});
|
||||
allDataBancheIntercode.stream()
|
||||
.map(x -> (GtbBancAziIntercode) x)
|
||||
.filter(x -> finalAllBancheData.stream()
|
||||
.map(y -> (GtbBancAzi) y)
|
||||
.noneMatch(y -> x.getCodBancAzi().equalsIgnoreCase(y.getCodBancAzi())))
|
||||
.forEach(x -> {
|
||||
GtbBancAzi testata = new GtbBancAzi()
|
||||
.setCodBancAzi(x.getCodBancAzi());
|
||||
|
||||
allDataBancheAzie.stream()
|
||||
.map(x -> (GtbBancAzi) x)
|
||||
.forEach(x -> x.setGtbBancAziIntercode(finalAllBancheDataIntercode.stream()
|
||||
.map(y -> (GtbBancAziIntercode) y)
|
||||
.filter(y -> y.getCodBancAzi().equalsIgnoreCase(x.getCodBancAzi()))
|
||||
.collect(Collectors.toList())));
|
||||
testata.setOperation(OperationType.UPDATE);
|
||||
finalAllBancheData.add(testata);
|
||||
});
|
||||
|
||||
final Exception[] firstExceptionToThrow = {null};
|
||||
allDataBancheAzie.stream()
|
||||
.map(x -> (GtbBancAzi) x)
|
||||
.forEach(x -> x.setGtbBancAziIntercode(finalAllBancheDataIntercode.stream()
|
||||
.map(y -> (GtbBancAziIntercode) y)
|
||||
.filter(y -> y.getCodBancAzi().equalsIgnoreCase(x.getCodBancAzi()))
|
||||
.collect(Collectors.toList())));
|
||||
|
||||
AtomicInteger importedCounter = new AtomicInteger();
|
||||
List<RunnableThrowable> calls = new ArrayList<>();
|
||||
final Exception[] firstExceptionToThrow = {null};
|
||||
|
||||
for (EquatableEntityInterface dataToSave : allDataBancheAzie) {
|
||||
logger.debug("Importate {} banche aziendali di {}", importedCounter.incrementAndGet(), allDataBancheAzie.size());
|
||||
try {
|
||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (GtbBancAzi) dataToSave, useTempTable);
|
||||
AtomicInteger importedCounter = new AtomicInteger();
|
||||
List<RunnableThrowable> calls = new ArrayList<>();
|
||||
|
||||
internalMultiDb.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
for (EquatableEntityInterface dataToSave : allDataBancheAzie) {
|
||||
logger.debug("Importate {} banche aziendali di {}", importedCounter.incrementAndGet(), allDataBancheAzie.size());
|
||||
try {
|
||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (GtbBancAzi) dataToSave, useTempTable);
|
||||
|
||||
} catch (Exception ex) {
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||
|
||||
logger.error("Errore durante l'importazione della banca aziendale", ex);
|
||||
internalMultiDb.rollbackAll();
|
||||
exchangeMultiDb.rollbackAll();
|
||||
}
|
||||
internalMultiDb.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
|
||||
} catch (Exception ex) {
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||
|
||||
logger.error("Errore durante l'importazione della banca aziendale", ex);
|
||||
internalMultiDb.rollbackAll();
|
||||
exchangeMultiDb.rollbackAll();
|
||||
}
|
||||
|
||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||
} finally {
|
||||
if (useTempTable)
|
||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche);
|
||||
|
||||
}
|
||||
|
||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||
} finally {
|
||||
if (useTempTable)
|
||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche);
|
||||
}
|
||||
}
|
||||
|
||||
private void importBanche(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, boolean useTempTable, RequestDataDTO requestDataDTO) throws Exception {
|
||||
@@ -204,7 +206,7 @@ public class ExchangeBancheImportService {
|
||||
|
||||
|
||||
private List<GtbBanc> retrieveBanche(Connection connection,
|
||||
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
|
||||
String gtbBancOriginalName = "gtb_banc";
|
||||
String gtbBancTableName = gtbBancOriginalName + (useTempTable ? "_tmp" : "");
|
||||
@@ -221,7 +223,7 @@ public class ExchangeBancheImportService {
|
||||
}
|
||||
|
||||
private List<GtbBancAziIntercode> retrieveBancheIntercode(Connection connection,
|
||||
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
|
||||
String gtbBancAziIntercodeOriginalName = "gtb_banc_azi_intercode";
|
||||
String gtbBancAziIntercodeTableName = gtbBancAziIntercodeOriginalName + (useTempTable ? "_tmp" : "");
|
||||
|
||||
Reference in New Issue
Block a user