Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -158,7 +158,7 @@
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.4.3</version>
|
||||
<version>8.5.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SWAGGER -->
|
||||
@@ -646,18 +646,18 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.70</version>
|
||||
<artifactId>bcpkix-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcmail-jdk15on</artifactId>
|
||||
<version>1.70</version>
|
||||
<artifactId>bcmail-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.70</version>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -709,7 +709,7 @@
|
||||
<dependency>
|
||||
<groupId>com.hierynomus</groupId>
|
||||
<artifactId>sshj</artifactId>
|
||||
<version>0.27.0</version>
|
||||
<version>0.39.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package it.integry.ems.controller;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.base.EntityImportResponse;
|
||||
@@ -72,6 +71,7 @@ import java.util.Date;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@Scope("request")
|
||||
@@ -604,13 +604,13 @@ public class EmsController {
|
||||
|
||||
|
||||
ServiceRestResponse response;
|
||||
if (entities != null && entities.size() > 0 && Stream.of(entities).anyMatch(x -> x instanceof EntityBase)) {
|
||||
List<MessageDTO> errorMessages = Stream.of(entities)
|
||||
if (entities != null && !entities.isEmpty() && entities.stream().anyMatch(x -> x instanceof EntityBase)) {
|
||||
List<MessageDTO> errorMessages = entities.stream()
|
||||
.filter(x -> x.getException() != null)
|
||||
.map(x -> MessageDTO.error(x.getException().getMessage()))
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<MessageDTO> messages = Stream.of(importResponse.getAnomalie())
|
||||
List<MessageDTO> messages = importResponse.getAnomalie().stream()
|
||||
.filter(x -> x.getTipo() != null)
|
||||
.map(x -> {
|
||||
switch (x.getTipo()) {
|
||||
@@ -621,24 +621,24 @@ public class EmsController {
|
||||
return MessageDTO.warning(x.getMessage());
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
errorMessages.addAll(messages);
|
||||
|
||||
if (errorMessages.size() > 0) {
|
||||
if (!errorMessages.isEmpty()) {
|
||||
response = ServiceRestResponse.createNegativeResponse();
|
||||
} else {
|
||||
response = ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
response.setMessages(errorMessages);
|
||||
response.setEntityList(Stream.of(entities).filter(x -> x.getException() == null).toList());
|
||||
response.setEntityList(entities.stream().filter(x -> x.getException() == null).collect(Collectors.toList()));
|
||||
|
||||
} else {
|
||||
if (importResponse.getAnomalie() != null) {
|
||||
|
||||
if (!importResponse.getAnomalie().isEmpty()) {
|
||||
|
||||
List<MessageDTO> messages = Stream.of(importResponse.getAnomalie())
|
||||
List<MessageDTO> messages = importResponse.getAnomalie().stream()
|
||||
.map(x -> {
|
||||
switch (x.getTipo()) {
|
||||
case ERROR:
|
||||
@@ -648,7 +648,7 @@ public class EmsController {
|
||||
return MessageDTO.warning(x.getMessage());
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
.collect(Collectors.toList());
|
||||
|
||||
response = ServiceRestResponse.createNegativeResponse();
|
||||
response.setMessages(messages);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241202092817 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241202092817 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
createOrUpdateView("[cvw_mov_black_list]", "CREATE VIEW [dbo].[cvw_mov_black_list] AS\n" +
|
||||
"SELECT crl_movt_rif_cmov.num_cmov, \n" +
|
||||
"\tctb_movt.num_cmov as num_cmov_rif,\n" +
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241202165228 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241202165228 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
executeStatement(
|
||||
"alter table dtb_doct add incoterms varchar(20)",
|
||||
"alter table dtb_dift add incoterms varchar(20)",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241203095628 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241203095628 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
dropIndex("arl_fogm", "ix_arl_fogm_mtb_sgrp");
|
||||
executeStatement("ALTER TABLE arl_fogm ADD id INT IDENTITY(1,1)",
|
||||
"EXEC DropPrimaryKey 'arl_fogm'",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241203161255 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241203161255 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
executeStatement("EXEC DropPrimaryKey 'arl_fogm'",
|
||||
"ALTER TABLE arl_fogm ALTER COLUMN id bigint not null" ,
|
||||
"ALTER TABLE arl_fogm ADD CONSTRAINT PK_arl_fogm_id PRIMARY KEY (id);");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241203165546 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241203165546 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
executeStatement(
|
||||
"alter table vtb_viaggi add container varchar(20)",
|
||||
"alter table vtb_viaggi add sigillo varchar(20)",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241205153404 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241205153404 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
boolean existsView = existsView("MES_MachineUsagePivot");
|
||||
|
||||
executeStatement((existsView ? "ALTER" : "CREATE") + " VIEW SYS_SequentialNumbers AS\n" +
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241205161212 extends BaseMigration implements MigrationModelInterface {
|
||||
@@ -10,6 +11,9 @@ public class Migration_20241205161212 extends BaseMigration implements Migration
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.Siciliani_DMS))
|
||||
return;
|
||||
|
||||
boolean existsView = existsView("MES_MachineUsagePivot");
|
||||
|
||||
executeStatement((existsView ? "ALTER" : "CREATE") + " VIEW [dbo].[MES_MachineUsagePivot] AS\n" +
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241212103718 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("ALTER TABLE azienda ADD cod_fda INT, cod_fce INT");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241212114532 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("alter table azienda alter column cod_fda varchar(20)");
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.RossoGargano_RossoGargano)){
|
||||
executeStatement("update azienda set cod_fda = '12273570736'" ,
|
||||
"update azienda set cod_fce = 15968");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -34,80 +34,48 @@ public class AutomatedOperationController {
|
||||
private AutomatedOperationService automatedOperationService;
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.GET)
|
||||
public ServiceRestResponse get(HttpServletRequest request, @RequestParam(required = false) String categoryFilter) {
|
||||
public ServiceRestResponse get(HttpServletRequest request, @RequestParam(required = false) String categoryFilter) throws Exception {
|
||||
|
||||
try {
|
||||
return ServiceRestResponse.createPositiveResponse(automatedOperationHandler.get(categoryFilter, null));
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
return ServiceRestResponse.createPositiveResponse(automatedOperationHandler.get(categoryFilter, null));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public ServiceRestResponse add(HttpServletRequest request,
|
||||
@RequestBody BaseAutomatedOperationDTO baseAutomatedOperationDTO) {
|
||||
@RequestBody BaseAutomatedOperationDTO baseAutomatedOperationDTO) throws Exception {
|
||||
|
||||
try {
|
||||
String uuid = automatedOperationHandler.add(baseAutomatedOperationDTO);
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(uuid);
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
String uuid = automatedOperationHandler.add(baseAutomatedOperationDTO);
|
||||
return ServiceRestResponse.createPositiveResponse(uuid);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "", method = RequestMethod.PUT)
|
||||
public ServiceRestResponse edit(HttpServletRequest request,
|
||||
@RequestBody BaseAutomatedOperationDTO baseAutomatedOperationDTO) {
|
||||
@RequestBody BaseAutomatedOperationDTO baseAutomatedOperationDTO) throws Exception {
|
||||
|
||||
try {
|
||||
automatedOperationHandler.edit(baseAutomatedOperationDTO);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
automatedOperationHandler.edit(baseAutomatedOperationDTO);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
public ServiceRestResponse delete(HttpServletRequest request,
|
||||
@PathVariable("id") String uuid) {
|
||||
@PathVariable("id") String uuid) throws Exception {
|
||||
|
||||
try {
|
||||
automatedOperationHandler.remove(uuid);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
automatedOperationHandler.remove(uuid);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/run/{id}", method = RequestMethod.GET)
|
||||
public ServiceRestResponse run(HttpServletRequest request,
|
||||
@PathVariable("id") String uuid) {
|
||||
@PathVariable("id") String uuid) throws Exception {
|
||||
|
||||
try {
|
||||
automatedOperationHandler.run(uuid);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
automatedOperationHandler.run(uuid);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/category", method = RequestMethod.GET)
|
||||
public ServiceRestResponse getCategory(HttpServletRequest request, @RequestParam(required = false) String filter) {
|
||||
|
||||
try {
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(automatedOperationService.getCategory(filter));
|
||||
} catch (Exception ex) {
|
||||
logger.error(request.getRequestURI(), ex);
|
||||
return ServiceRestResponse.createNegativeResponse(null, ex);
|
||||
}
|
||||
return ServiceRestResponse.createPositiveResponse(automatedOperationService.getCategory(filter));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ public class ImportDirectoryOperationDTO extends BaseDirectoryOperationDTO {
|
||||
@OperationField(required = true, password = true)
|
||||
private String password;
|
||||
|
||||
@OperationField(required = true)
|
||||
private DirectoryType directoryType;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -69,13 +72,20 @@ public class ImportDirectoryOperationDTO extends BaseDirectoryOperationDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DirectoryType getDirectoryType() {
|
||||
return directoryType;
|
||||
}
|
||||
|
||||
public ImportDirectoryOperationDTO setDirectoryType(DirectoryType directoryType) {
|
||||
this.directoryType = directoryType;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDirectory() {
|
||||
String path = super.getDirectory();
|
||||
try {
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(getProfileDb())) {
|
||||
SetupGest setupGest = new SetupGest();
|
||||
MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(getProfileDb());
|
||||
path = setupGest.getImportSetup(multiDBTransactionManager.getPrimaryDatasource().getConnection(), type, format, "PATH_FILE");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -86,13 +96,18 @@ public class ImportDirectoryOperationDTO extends BaseDirectoryOperationDTO {
|
||||
@Override
|
||||
public String getFilePattern() {
|
||||
String fileFilter = super.getFilePattern();
|
||||
try {
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(getProfileDb())) {
|
||||
SetupGest setupGest = new SetupGest();
|
||||
MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(getProfileDb());
|
||||
fileFilter = setupGest.getImportSetup(multiDBTransactionManager.getPrimaryDatasource().getConnection(), type, format, "FILE_FILTER");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return !UtilityString.isNullOrEmpty(fileFilter) ? fileFilter : super.getFilePattern();
|
||||
}
|
||||
|
||||
|
||||
public enum DirectoryType {
|
||||
LocalFolder,
|
||||
SftpFolder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package it.integry.ems.schedule.new_cron_job.dto.operations.runners;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.Import.dto.ImportRequestDTO;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.json.ResponseJSONObjectMapper;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.MessageDTO;
|
||||
@@ -10,6 +9,7 @@ import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.schedule.directory.base.DirectoryWatcherEventEnum;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import it.integry.ems.service.HttpRestWrapper;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.UtilityServer;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
@@ -32,17 +32,16 @@ public class ImportDirectoryOperationRunner extends BaseDirectoryOperationRunner
|
||||
}
|
||||
|
||||
if (event == DirectoryWatcherEventEnum.ON_START) {
|
||||
SetupGest setupGest = ContextLoader.getCurrentWebApplicationContext().getBean(SetupGest.class);
|
||||
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(this.getDtoInstance().getProfileDb());
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(this.getDtoInstance().getProfileDb())) {
|
||||
SetupGest setupGest = ContextLoader.getCurrentWebApplicationContext().getBean(SetupGest.class);
|
||||
String gestName = "IMPORT_" + this.getDtoInstance().getType();
|
||||
|
||||
String gestName = "IMPORT_" + this.getDtoInstance().getType();
|
||||
|
||||
if (!setupGest.getSetupBoolean(ds.getConnection(), gestName, this.getDtoInstance().getFormat(), "RECUPERA_FILE")) {
|
||||
shouldStop = true;
|
||||
if (!setupGest.getSetupBoolean(multiDBTransactionManager.getPrimaryConnection(),
|
||||
gestName, this.getDtoInstance().getFormat(), "RECUPERA_FILE")) {
|
||||
shouldStop = true;
|
||||
}
|
||||
}
|
||||
ds.forceClose();
|
||||
}
|
||||
|
||||
if (!shouldStop) {
|
||||
@@ -74,12 +73,12 @@ public class ImportDirectoryOperationRunner extends BaseDirectoryOperationRunner
|
||||
|
||||
if (serviceRestResponse.getEsito().equals(EsitoType.KO)) {
|
||||
String errorMessage = serviceRestResponse.getErrorMessage();
|
||||
if (UtilityString.isNullOrEmpty(errorMessage)){
|
||||
if (UtilityString.isNullOrEmpty(errorMessage)) {
|
||||
errorMessage = Stream.of(serviceRestResponse.getMessages())
|
||||
.filter(x->x.getLevel() != null && x.getLevel()== MessageDTO.Level.ERROR).map(x->x.getText()).findFirst().orElse(null);
|
||||
.filter(x -> x.getLevel() != null && x.getLevel() == MessageDTO.Level.ERROR).map(x -> x.getText()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(errorMessage)){
|
||||
if (!UtilityString.isNullOrEmpty(errorMessage)) {
|
||||
logger.error(String.format("Operazione [ID:%s, Name:%s] - Eccezione", this.getDtoInstance().getId(), this.getDtoInstance().getName()),
|
||||
new Exception(errorMessage));
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import it.integry.annotations.PostWebServerConstruct;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.AutomatedOperationTypeEnum;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.AutomatedOperationsWrapper;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseAutomatedOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseScheduledOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.runners.BaseAutomatedOperationRunner;
|
||||
@@ -23,6 +25,7 @@ import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityDirs;
|
||||
import it.integry.ems.utility.UtilityFile;
|
||||
import it.integry.ems_model.entity.Azienda;
|
||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||
import it.integry.ems_model.utility.UtilityServer;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -32,6 +35,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -72,6 +77,24 @@ public class AutomatedOperationHandlerComponent {
|
||||
objectMapper.writerWithDefaultPrettyPrinter().writeValue(configurationFile, modelInstance);
|
||||
} else {
|
||||
modelInstance = objectMapper.readValue(configurationFile, AutomatedOperationsWrapper.class);
|
||||
|
||||
if (modelInstance.getOperations().containsKey(AutomatedOperationTypeEnum.IMPORT_DIRECTORY)) {
|
||||
final List<BaseAutomatedOperationDTO> importDirectory = modelInstance.getOperations().get(AutomatedOperationTypeEnum.IMPORT_DIRECTORY);
|
||||
|
||||
if (!importDirectory.isEmpty() && importDirectory.stream().anyMatch(x -> ((ImportDirectoryOperationDTO) x).getDirectoryType() == null)) {
|
||||
//Make a backup
|
||||
Files.copy(configurationFile.toPath(),
|
||||
Paths.get(UtilityDirs.getConfigPath(), RESOURCE_FILENAME + "_" +
|
||||
UtilityLocalDate.getNowTime().format(CommonConstants.TIMESTAMP_FORMATTER)));
|
||||
|
||||
importDirectory.stream()
|
||||
.map(x -> (ImportDirectoryOperationDTO) x)
|
||||
.filter(x -> x.getDirectoryType() == null)
|
||||
.forEach(x -> x.setDirectoryType(ImportDirectoryOperationDTO.DirectoryType.LocalFolder));
|
||||
|
||||
objectMapper.writerWithDefaultPrettyPrinter().writeValue(configurationFile, modelInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<AutomatedOperationTypeEnum, List<BaseAutomatedOperationDTO>> operationsLists = this.get();
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.integry.ems.schedule.new_cron_job.service;
|
||||
|
||||
import it.integry.ems.schedule.directory.base.DirectoryWatcherEventEnum;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.AutomatedOperationTypeEnum;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseAutomatedOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseDirectoryOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseScheduledOperationDTO;
|
||||
@@ -11,6 +12,8 @@ import it.integry.ems.schedule.new_cron_job.dto.operations.runners.BaseScheduled
|
||||
import it.integry.ems.schedule.new_cron_job.utility.UtilityScheduler;
|
||||
import it.integry.ems.watching.DirectoryWatcher;
|
||||
import it.integry.ems.watching.IDirectoryWatcherEvents;
|
||||
import it.integry.ems.watching.LocalFolderDirectoryWatcher;
|
||||
import it.integry.ems.watching.SftpFolderDirectoryWatcher;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -83,14 +86,27 @@ public class ScheduledOperationHandlerComponent {
|
||||
AutomatedOperationTypeEnum operationType = UtilityScheduler.getTypeFromDTO(operationDTO);
|
||||
|
||||
if (!AutomatedOperationBindings.RUNNER_BINDINGS.containsKey(operationType)) {
|
||||
throw new Exception("Nessun runner associato al tipo " + operationType.toString());
|
||||
throw new Exception("Nessun runner associato al tipo " + operationType);
|
||||
}
|
||||
|
||||
if (!operationDTO.isActive()) return;
|
||||
String uuid = operationDTO.getId();
|
||||
Class<? extends BaseAutomatedOperationRunner> operationRunnerType = AutomatedOperationBindings.RUNNER_BINDINGS.get(operationType);
|
||||
|
||||
DirectoryWatcher directoryWatcher = new DirectoryWatcher(operationDTO.getDirectory(), operationDTO.getFilePattern());
|
||||
DirectoryWatcher directoryWatcher = null;
|
||||
|
||||
switch (((ImportDirectoryOperationDTO) operationDTO).getDirectoryType()) {
|
||||
case SftpFolder:
|
||||
directoryWatcher = new SftpFolderDirectoryWatcher((ImportDirectoryOperationDTO) operationDTO);
|
||||
break;
|
||||
|
||||
case LocalFolder:
|
||||
default:
|
||||
directoryWatcher = new LocalFolderDirectoryWatcher((ImportDirectoryOperationDTO) operationDTO);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
directoryWatcherOperations.put(uuid, directoryWatcher);
|
||||
|
||||
logger.debug(String.format("Automated operation [ID:%s, Name:%s]: START", operationDTO.getId(), operationDTO.getName()));
|
||||
|
||||
@@ -71,6 +71,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
@@ -202,10 +203,8 @@ public class EmsServices {
|
||||
try {
|
||||
anomaliaIsError = false;
|
||||
if (!file.isDirectory()) {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
body.setRawContent(IOUtils.toString(fis));
|
||||
body.setRawContent(new String(Files.readAllBytes(file.toPath())));
|
||||
fileContent = ((String) body.getRawContent()).getBytes();
|
||||
fis.close();
|
||||
IEntityImporter entityImporter = EntityImporterUtility.getRightImporterClassByType(enumType).newInstance();
|
||||
setEntityImporter(entityImporter, file, multiDBTransactionManager, type, format, body, headless);
|
||||
|
||||
@@ -777,7 +776,7 @@ public class EmsServices {
|
||||
|
||||
List<HashMap<String, Object>> enabledConfigList = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), query);
|
||||
|
||||
if (enabledConfigList.size() > 0) {
|
||||
if (!enabledConfigList.isEmpty()) {
|
||||
|
||||
for (HashMap<String, Object> enabledConfig : enabledConfigList) {
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import it.integry.ems.properties.EmsProperties;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -64,16 +65,16 @@ public class UtilityDirs {
|
||||
return fileToReturn;
|
||||
}
|
||||
|
||||
public static File getDirectoryImport(String nomeDB, String type, String format) {
|
||||
String dir = "IMPORT" + File.separator + nomeDB + File.separator + type + File.separator + format;
|
||||
public static String getDirectoryImport(String nomeDB, String type, String format) {
|
||||
Path dir = Paths.get(getEmsApiTempDirectoryPath(), "IMPORT", nomeDB, type, format);
|
||||
|
||||
File fileToReturn = new File(getEmsApiTempDirectoryPath() + File.separator + dir);
|
||||
File fileToReturn = dir.toFile();
|
||||
|
||||
if (!fileToReturn.exists()) {
|
||||
fileToReturn.mkdirs();
|
||||
}
|
||||
|
||||
return fileToReturn;
|
||||
return fileToReturn.getAbsolutePath();
|
||||
}
|
||||
|
||||
public static String getConfigPath() {
|
||||
|
||||
@@ -1,175 +1,68 @@
|
||||
package it.integry.ems.watching;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import org.apache.commons.io.monitor.FileAlterationListener;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DirectoryWatcher {
|
||||
public abstract class DirectoryWatcher {
|
||||
|
||||
private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
protected final Logger logger = LogManager.getLogger();
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
protected IDirectoryWatcherEvents directoryWatcherEvents;
|
||||
|
||||
private FileAlterationObserver observer;
|
||||
private FileAlterationMonitor monitor;
|
||||
private FileAlterationListener listener;
|
||||
protected ImportDirectoryOperationDTO operationData;
|
||||
|
||||
private IDirectoryWatcherEvents directoryWatcherEvents;
|
||||
|
||||
private String fileFilter;
|
||||
protected final String path;
|
||||
protected final String fileFilter;
|
||||
|
||||
private boolean isRunning = false;
|
||||
|
||||
public DirectoryWatcher(String path, String fileFilter) {
|
||||
this.fileFilter = fileFilter;
|
||||
|
||||
observer = new FileAlterationObserver(path);
|
||||
monitor = new FileAlterationMonitor(10000);
|
||||
public DirectoryWatcher(ImportDirectoryOperationDTO operationData) {
|
||||
this.operationData = operationData;
|
||||
this.path = operationData.getDirectory();
|
||||
this.fileFilter = operationData.getFilePattern();
|
||||
}
|
||||
|
||||
|
||||
public void setDirectoryWatcherEvents(final IDirectoryWatcherEvents directoryWatcherEvents) {
|
||||
this.directoryWatcherEvents = directoryWatcherEvents;
|
||||
|
||||
listener = new FileAlterationListener() {
|
||||
|
||||
@Override
|
||||
public void onStart(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryCreate(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryChange(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryDelete(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
directoryWatcherEvents.onFileCreate(file);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileChange(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileDelete(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
observer.addListener(listener);
|
||||
monitor.addObserver(observer);
|
||||
}
|
||||
|
||||
public void startMonitoring() throws Exception {
|
||||
if (!isRunning) {
|
||||
if (isRunning)
|
||||
return;
|
||||
|
||||
if (this.directoryWatcherEvents == null) {
|
||||
throw new Exception("Nessun directory listener configurato");
|
||||
}
|
||||
|
||||
logger.debug("Avviato servizio di recupero files nella cartella: " + this.observer.getDirectory().toString());
|
||||
|
||||
|
||||
File[] files = observer.getDirectory().listFiles(pathname -> getMatcher(fileFilter, pathname.getName()).matches());
|
||||
|
||||
List<File> filesList = new ArrayList<File>();
|
||||
|
||||
if (files != null) {
|
||||
filesList = Arrays.asList(files);
|
||||
}
|
||||
|
||||
filesList = Stream.of(filesList)
|
||||
.filter(x -> !x.isDirectory())
|
||||
.toList();
|
||||
|
||||
if (!filesList.isEmpty()) {
|
||||
for (final File finalFilesList : filesList) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
List<File> fileList = new ArrayList<>();
|
||||
fileList.add(finalFilesList);
|
||||
directoryWatcherEvents.onStart(fileList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Errore durante la lettura dei files all'avvio", e.getCause());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
monitor.start();
|
||||
isRunning = true;
|
||||
if (this.directoryWatcherEvents == null) {
|
||||
throw new Exception("Nessun directory listener configurato");
|
||||
}
|
||||
|
||||
start();
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
protected abstract void start() throws Exception;
|
||||
|
||||
public void stopMonitoring() throws Exception {
|
||||
if (isRunning) {
|
||||
monitor.stop();
|
||||
isRunning = false;
|
||||
}
|
||||
if (!isRunning)
|
||||
return;
|
||||
|
||||
stop();
|
||||
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
private Matcher getMatcher(String filter, String name) {
|
||||
protected abstract void stop() throws Exception;
|
||||
|
||||
|
||||
|
||||
protected Matcher getMatcher(String filter, String name) {
|
||||
Pattern pattern = Pattern.compile(filter, Pattern.CASE_INSENSITIVE);
|
||||
return pattern.matcher(name);
|
||||
}
|
||||
|
||||
private boolean isASubDirectory(File currentFile) {
|
||||
return !currentFile.getParent().equalsIgnoreCase(observer.getDirectory().getPath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
package it.integry.ems.watching;
|
||||
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import org.apache.commons.io.monitor.FileAlterationListener;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LocalFolderDirectoryWatcher extends DirectoryWatcher {
|
||||
|
||||
private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
private FileAlterationObserver observer;
|
||||
private FileAlterationMonitor monitor;
|
||||
private FileAlterationListener listener;
|
||||
|
||||
public LocalFolderDirectoryWatcher(ImportDirectoryOperationDTO operationDTO) {
|
||||
super(operationDTO);
|
||||
}
|
||||
|
||||
|
||||
public void setDirectoryWatcherEvents(final IDirectoryWatcherEvents directoryWatcherEvents) {
|
||||
this.directoryWatcherEvents = directoryWatcherEvents;
|
||||
|
||||
listener = new FileAlterationListener() {
|
||||
|
||||
@Override
|
||||
public void onStart(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryCreate(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryChange(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryDelete(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
directoryWatcherEvents.onFileCreate(file);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileChange(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileDelete(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
observer.addListener(listener);
|
||||
monitor.addObserver(observer);
|
||||
}
|
||||
|
||||
protected void start() throws Exception {
|
||||
observer = new FileAlterationObserver(path);
|
||||
monitor = new FileAlterationMonitor(10000);
|
||||
|
||||
listener = new FileAlterationListener() {
|
||||
|
||||
@Override
|
||||
public void onStart(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryCreate(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryChange(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectoryDelete(File directory) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
directoryWatcherEvents.onFileCreate(file);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileChange(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
if (!isASubDirectory(file)) {
|
||||
if (getMatcher(fileFilter, file.getName()).matches()) {
|
||||
executor.execute(() -> {
|
||||
directoryWatcherEvents.onFileDelete(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(FileAlterationObserver observer) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
observer.addListener(listener);
|
||||
monitor.addObserver(observer);
|
||||
|
||||
logger.debug("Avviato servizio di recupero files nella cartella: " + this.observer.getDirectory().toString());
|
||||
|
||||
File[] files = observer.getDirectory().listFiles(pathname -> getMatcher(fileFilter, pathname.getName()).matches());
|
||||
|
||||
List<File> filesList = new ArrayList<File>();
|
||||
|
||||
if (files != null) {
|
||||
filesList = Arrays.asList(files);
|
||||
}
|
||||
|
||||
filesList = filesList.stream()
|
||||
.filter(x -> !x.isDirectory())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!filesList.isEmpty()) {
|
||||
for (final File finalFilesList : filesList) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
List<File> fileList = new ArrayList<>();
|
||||
fileList.add(finalFilesList);
|
||||
directoryWatcherEvents.onStart(fileList);
|
||||
} catch (Exception e) {
|
||||
logger.error("Errore durante la lettura dei files all'avvio", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
monitor.start();
|
||||
}
|
||||
|
||||
|
||||
protected void stop() throws Exception {
|
||||
monitor.stop();
|
||||
|
||||
observer = null;
|
||||
monitor = null;
|
||||
}
|
||||
|
||||
private boolean isASubDirectory(File currentFile) {
|
||||
return !currentFile.getParent().equalsIgnoreCase(observer.getDirectory().getPath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
package it.integry.ems.watching;
|
||||
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.ImportDirectoryOperationDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDirs;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import net.schmizz.sshj.SSHClient;
|
||||
import net.schmizz.sshj.sftp.RemoteFile;
|
||||
import net.schmizz.sshj.sftp.RemoteResourceFilter;
|
||||
import net.schmizz.sshj.sftp.RemoteResourceInfo;
|
||||
import net.schmizz.sshj.sftp.SFTPClient;
|
||||
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SftpFolderDirectoryWatcher extends DirectoryWatcher {
|
||||
|
||||
private SSHClient sshClient;
|
||||
private SFTPClient sftpClient;
|
||||
|
||||
private String sftpHost;
|
||||
private int sftpPort = 22;
|
||||
private String sftpUsername;
|
||||
private String sftpPassword;
|
||||
|
||||
private String tempPath;
|
||||
private String filePattern;
|
||||
|
||||
private final List<String> prevImportedFiles = new ArrayList<>();
|
||||
|
||||
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
public SftpFolderDirectoryWatcher(ImportDirectoryOperationDTO operationData) {
|
||||
super(operationData);
|
||||
|
||||
retrieveConnectionSettings();
|
||||
}
|
||||
|
||||
private void retrieveConnectionSettings() {
|
||||
|
||||
SetupGest setupGest = ContextLoader.getCurrentWebApplicationContext().getBean(SetupGest.class);
|
||||
|
||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(operationData.getProfileDb())) {
|
||||
String gestName = "IMPORT_" + operationData.getType();
|
||||
|
||||
sftpHost = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, operationData.getFormat(), "SFTP_HOST");
|
||||
String sftpPortString = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, operationData.getFormat(), "SFTP_PORT");
|
||||
sftpUsername = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, operationData.getFormat(), "SFTP_USERNAME");
|
||||
sftpPassword = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), gestName, operationData.getFormat(), "SFTP_PASSWORD");
|
||||
|
||||
if (UtilityString.isNullOrEmpty(sftpHost)) {
|
||||
throw new RuntimeException(String.format("SFTP host not set [Directory Watcher: %s | %s - %s - %s]", operationData.getName(), gestName, operationData.getFormat(), "SFTP_HOST"));
|
||||
}
|
||||
if (UtilityString.isNullOrEmpty(sftpPortString)) {
|
||||
throw new RuntimeException(String.format("SFTP port not set [Directory Watcher: %s | %s - %s - %s]", operationData.getName(), gestName, operationData.getFormat(), "SFTP_PORT"));
|
||||
}
|
||||
if (UtilityString.isNullOrEmpty(sftpUsername)) {
|
||||
throw new RuntimeException(String.format("SFTP username not set [Directory Watcher: %s | %s - %s - %s]", operationData.getName(), gestName, operationData.getFormat(), "SFTP_USERNAME"));
|
||||
}
|
||||
if (UtilityString.isNullOrEmpty(sftpPassword)) {
|
||||
throw new RuntimeException(String.format("SFTP password not set [Directory Watcher: %s | %s - %s - %s]", operationData.getName(), gestName, operationData.getFormat(), "SFTP_PASSWORD"));
|
||||
}
|
||||
|
||||
sftpPort = Integer.parseInt(sftpPortString);
|
||||
filePattern = operationData.getFilePattern();
|
||||
tempPath = UtilityDirs.getDirectoryImport(operationData.getProfileDb(), operationData.getType(), operationData.getFormat());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void connect() throws Exception {
|
||||
if (sshClient == null) {
|
||||
sshClient = new SSHClient();
|
||||
|
||||
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
|
||||
sshClient.connect(sftpHost, sftpPort);
|
||||
sshClient.authPassword(sftpUsername, sftpPassword);
|
||||
|
||||
sftpClient = sshClient.newSFTPClient();
|
||||
}
|
||||
|
||||
sshClient.setConnectTimeout(40 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void start() throws Exception {
|
||||
|
||||
connect();
|
||||
|
||||
String baseDirectory = UtilityString.isNull(operationData.getDirectory(), "");
|
||||
|
||||
final List<RemoteResourceInfo> remoteFiles = sftpClient.ls(baseDirectory, getFileFilter());
|
||||
final List<File> tempFiles = new ArrayList<>();
|
||||
|
||||
for (RemoteResourceInfo remoteFile : remoteFiles) {
|
||||
File tempFile = downloadFile(remoteFile);
|
||||
tempFiles.add(tempFile);
|
||||
prevImportedFiles.add(tempFile.getName());
|
||||
}
|
||||
|
||||
disconnect();
|
||||
|
||||
directoryWatcherEvents.onStart(tempFiles);
|
||||
|
||||
executorService.scheduleAtFixedRate(this::scanForChanges, 0, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private void scanForChanges() {
|
||||
|
||||
try {
|
||||
|
||||
connect();
|
||||
|
||||
String baseDirectory = UtilityString.isNull(operationData.getDirectory(), "");
|
||||
final List<RemoteResourceInfo> ls = sftpClient.ls(baseDirectory, getFileFilter());
|
||||
|
||||
final List<RemoteResourceInfo> newFilesToImport = ls.stream().
|
||||
filter(x -> !prevImportedFiles.contains(x.getName()))
|
||||
.collect(Collectors.toList());
|
||||
final List<File> newTempFiles = new ArrayList<>();
|
||||
|
||||
for (RemoteResourceInfo resourceInfo : newFilesToImport) {
|
||||
newTempFiles.add(downloadFile(resourceInfo));
|
||||
}
|
||||
|
||||
disconnect();
|
||||
|
||||
for (File tempFile : newTempFiles) {
|
||||
directoryWatcherEvents.onFileCreate(tempFile);
|
||||
}
|
||||
|
||||
|
||||
prevImportedFiles.clear();
|
||||
prevImportedFiles.addAll(ls.stream().map(RemoteResourceInfo::getPath).collect(Collectors.toList()));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("Errore durante la connessione SFTP [Directory watcher: %s]", operationData.getName()), e);
|
||||
} finally {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private RemoteResourceFilter getFileFilter() {
|
||||
return remoteResourceInfo -> remoteResourceInfo.isRegularFile() &&
|
||||
getMatcher(filePattern, remoteResourceInfo.getName())
|
||||
.find();
|
||||
}
|
||||
|
||||
private File downloadFile(RemoteResourceInfo resourceInfo) throws Exception {
|
||||
String tempFilePath = Paths.get(tempPath, resourceInfo.getName()).toString();
|
||||
File tempFile = new File(tempFilePath);
|
||||
|
||||
if (tempFile.exists()) {
|
||||
tempFile.delete();
|
||||
}
|
||||
|
||||
final RemoteFile open = sftpClient.open(resourceInfo.getPath());
|
||||
byte[] buffer = new byte[(int) open.length()];
|
||||
open.read(0, buffer, 0, (int) open.length());
|
||||
|
||||
FileUtils.writeByteArrayToFile(tempFile, buffer);
|
||||
|
||||
// sftpClient.get(resourceInfo.getPath(), tempFilePath);
|
||||
// final byte[] bytes = FileUtils.readFileToByteArray(new File(tempFilePath));
|
||||
|
||||
|
||||
return new File(tempFilePath);
|
||||
}
|
||||
|
||||
|
||||
private byte[] convertToUtf8IfAnsi(byte[] inputByteArr) throws Exception {
|
||||
// Leggi i byte del file
|
||||
|
||||
// Controlla se il file è UTF-8 usando una semplice euristica
|
||||
boolean isUtf8 = isUtf8(inputByteArr);
|
||||
|
||||
//UtilityFile.removeDigitalSign(FilenameUtils.getName(inputFilePath), fileBytes);
|
||||
if (isUtf8) {
|
||||
System.out.println("Il file è già in UTF-8. Nessuna conversione necessaria.");
|
||||
return inputByteArr;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Charset ansiCharset = Charset.forName("windows-1252");
|
||||
try (
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(inputByteArr), ansiCharset));
|
||||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos, StandardCharsets.UTF_8));) {
|
||||
char[] buffer = new char[16384];
|
||||
int read;
|
||||
while ((read = br.read(buffer)) != -1)
|
||||
bw.write(buffer, 0, read);
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private static boolean isUtf8(byte[] bytes) {
|
||||
int i = 0;
|
||||
while (i < bytes.length) {
|
||||
int byte1 = bytes[i] & 0xFF;
|
||||
if (byte1 <= 0x7F) {
|
||||
// ASCII
|
||||
i++;
|
||||
} else if ((byte1 >> 5) == 0b110) {
|
||||
// 2-byte sequence
|
||||
if (i + 1 >= bytes.length || (bytes[i + 1] & 0xC0) != 0x80) {
|
||||
return false;
|
||||
}
|
||||
i += 2;
|
||||
} else if ((byte1 >> 4) == 0b1110) {
|
||||
// 3-byte sequence
|
||||
if (i + 2 >= bytes.length || (bytes[i + 1] & 0xC0) != 0x80 || (bytes[i + 2] & 0xC0) != 0x80) {
|
||||
return false;
|
||||
}
|
||||
i += 3;
|
||||
} else if ((byte1 >> 3) == 0b11110) {
|
||||
// 4-byte sequence
|
||||
if (i + 3 >= bytes.length || (bytes[i + 1] & 0xC0) != 0x80 || (bytes[i + 2] & 0xC0) != 0x80 || (bytes[i + 3] & 0xC0) != 0x80) {
|
||||
return false;
|
||||
}
|
||||
i += 4;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stop() throws Exception {
|
||||
//disconnect();
|
||||
executorService.shutdown();
|
||||
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
}
|
||||
|
||||
private void disconnect() {
|
||||
try {
|
||||
|
||||
if (sftpClient != null) {
|
||||
sftpClient.close();
|
||||
sftpClient = null;
|
||||
}
|
||||
|
||||
if (sshClient != null) {
|
||||
sshClient.disconnect();
|
||||
sshClient.close();
|
||||
sshClient = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,22 +64,22 @@ public class SetupGest {
|
||||
return Integer.parseInt(getSetup(conn, gestName, section, keySection, ""));
|
||||
}
|
||||
|
||||
public int getSetupInteger(Connection conn, String gestName, String section, String keySection, int defaultValue) throws Exception {
|
||||
String value = getSetup(conn, gestName, section, keySection);
|
||||
public int getSetupInteger(Connection connection, String gestName, String section, String keySection, int defaultValue) throws Exception {
|
||||
String value = getSetup(connection, gestName, section, keySection);
|
||||
return value != null ? Integer.parseInt(value) : defaultValue;
|
||||
}
|
||||
|
||||
public BigDecimal getSetupBigDecimal(Connection conn, String gestName, String section, String keySection) throws Exception {
|
||||
return getSetupBigDecimal(conn, gestName, section, keySection, null);
|
||||
public BigDecimal getSetupBigDecimal(Connection connection, String gestName, String section, String keySection) throws Exception {
|
||||
return getSetupBigDecimal(connection, gestName, section, keySection, null);
|
||||
}
|
||||
|
||||
public BigDecimal getSetupBigDecimal(Connection conn, String gestName, String section, String keySection, BigDecimal defaultValue) throws Exception {
|
||||
String value = getSetup(conn, gestName, section, keySection);
|
||||
public BigDecimal getSetupBigDecimal(Connection connection, String gestName, String section, String keySection, BigDecimal defaultValue) throws Exception {
|
||||
String value = getSetup(connection, gestName, section, keySection);
|
||||
return value != null ? BigDecimal.valueOf(Double.parseDouble(getSetup(gestName, section, keySection))) : defaultValue;
|
||||
}
|
||||
|
||||
public BigDecimal getSetupDetBigDecimal(Connection conn, String gestName, String section, String keySection, String colRif, BigDecimal defaultValue) throws Exception {
|
||||
String value = getSetupDet(conn, gestName, section, keySection, colRif);
|
||||
public BigDecimal getSetupDetBigDecimal(Connection connection, String gestName, String section, String keySection, String colRif, BigDecimal defaultValue) throws Exception {
|
||||
String value = getSetupDet(connection, gestName, section, keySection, colRif);
|
||||
return value != null ? BigDecimal.valueOf(Double.parseDouble(value)) : defaultValue;
|
||||
}
|
||||
|
||||
@@ -102,16 +102,14 @@ public class SetupGest {
|
||||
while (res.next()) {
|
||||
value = res.getString(1) == null ? "" : res.getString(1);
|
||||
}
|
||||
if (res != null)
|
||||
res.close();
|
||||
if (info != null)
|
||||
info.close();
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public void setSetup(Connection conn, String gestName, String section, String keySection, Object value) throws Exception {
|
||||
public void setSetup(Connection connection, String gestName, String section, String keySection, Object value) throws Exception {
|
||||
String sql = "";
|
||||
|
||||
if (value instanceof Date) {
|
||||
@@ -126,8 +124,7 @@ public class SetupGest {
|
||||
+ " AND section = " + UtilityDB.valueToString(section)
|
||||
+ " AND key_section = " + UtilityDB.valueToString(keySection);
|
||||
|
||||
|
||||
UtilityDB.executeSimpleUpdate(conn, query);
|
||||
UtilityDB.executeSimpleUpdate(connection, query);
|
||||
}
|
||||
|
||||
public <T> T getSetup(String gestName, String section, String keySection, TypeReference<T> type) throws Exception {
|
||||
|
||||
@@ -483,7 +483,7 @@ public class UtilityDB {
|
||||
|
||||
List<HashMap<String, Object>> queryResults = executeSimpleQuery(conn, querySql);
|
||||
|
||||
if (queryResults.size() > 0) {
|
||||
if (!queryResults.isEmpty()) {
|
||||
object = queryResults.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
|
||||
case ELO:
|
||||
entities = getContextBean(DocumentiAcquistoImportService.class)
|
||||
.importDocumentiElo(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<EloDTO>>() {}), anomalie);
|
||||
.importDocumentiElo(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<EloDTO>>() {
|
||||
}), anomalie);
|
||||
break;
|
||||
|
||||
case ISID:
|
||||
@@ -112,7 +113,8 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
|
||||
case SOCIALWEB_FIDELITY_BACM:
|
||||
entities = getContextBean(DocumentiSocialWebImportService.class)
|
||||
.importDocSocialWeb(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<ImportSocialWebFidelityDocumentDTO>>() {}));
|
||||
.importDocSocialWeb(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<ImportSocialWebFidelityDocumentDTO>>() {
|
||||
}));
|
||||
break;
|
||||
|
||||
case DOCUMENTI_WEB:
|
||||
@@ -136,7 +138,8 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
|
||||
case CARICO_SCARICO_DA_FABB:
|
||||
entities = getContextBean(DocumentiProdDaFabb.class)
|
||||
.generateCaricoScaricoDaFabb(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<DocumentiProdDaFabbDTO>>() {}), anomalie);
|
||||
.generateCaricoScaricoDaFabb(type, format, mapJsonToDTO(requestDto.getRawContent(), new TypeReference<ArrayList<DocumentiProdDaFabbDTO>>() {
|
||||
}), anomalie);
|
||||
break;
|
||||
|
||||
case GIROCONTO_MP_REPARTO:
|
||||
@@ -145,13 +148,13 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
break;
|
||||
case MEGAMARK:
|
||||
entities = getContextBean(DocumentiMegamarkImportService.class)
|
||||
.importBolle(type, format, requestDto.getRawContent(), anomalie);
|
||||
.importBolle(type, format, requestDto.getRawContent(), anomalie);
|
||||
break;
|
||||
case BRT_JSON:
|
||||
entities = getContextBean(BrtService.class)
|
||||
.importJson(requestDto);
|
||||
break;
|
||||
case GELORENT :
|
||||
case GELORENT:
|
||||
entities = getContextBean(DocumentiImportService.class)
|
||||
.importDocumentiVenditaGelorent(type, format, requestDto.getRawContent(), anomalie);
|
||||
break;
|
||||
@@ -165,6 +168,10 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
.checkPassiveInvoice(requestDto, anomalie);
|
||||
entities = new ArrayList<>();
|
||||
break;
|
||||
case TESI:
|
||||
entities = getContextBean(DocumentiAcquistoImportService.class)
|
||||
.importXmlFatturaElettronica(type, format, requestDto, anomalie, headless);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Tipo " + format + " non supportato");
|
||||
}
|
||||
@@ -219,15 +226,16 @@ public class DocumentiImporter extends BaseEntityImporter<List<EntityBase>> impl
|
||||
CONSORTILE("CONSORTILE"),
|
||||
EUROFOOD("EUROFOOD"),
|
||||
CARICO_SCARICO_DA_FABB("CARICO_SCARICO_DA_FABB"),
|
||||
ELO ("ELO"),
|
||||
GIROCONTO_MP_REPARTO ("GIROCONTO_MP_REPARTO"),
|
||||
ELO("ELO"),
|
||||
GIROCONTO_MP_REPARTO("GIROCONTO_MP_REPARTO"),
|
||||
MEGAMARK("MEGAMARK"),
|
||||
BRT_JSON("BRT_JSON"),
|
||||
SCAR_MP_DA_DIST("SCAR_MP_DA_DIST"),
|
||||
GELORENT("GELORENT"),
|
||||
APULIA_RIFORD("APULIA_RIFORD"),
|
||||
PAZIENZA_RIFORD("PAZIENZA_RIFORD"),
|
||||
CASSETTO_FISCALE("CASSETTO_FISCALE");
|
||||
CASSETTO_FISCALE("CASSETTO_FISCALE"),
|
||||
TESI("TESI");
|
||||
|
||||
private String text;
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.document.Import.dto.EloDTO;
|
||||
import it.integry.ems.document.Import.dto.EloRowsDTO;
|
||||
import it.integry.ems.document.Import.dto.RifOrdApuliaDTO;
|
||||
import it.integry.ems.document.fatture.dto.FpxToPdfDTO;
|
||||
import it.integry.ems.document.fatture.services.DigitalInvoiceConverterService;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.rules.completing.DocOrdRules;
|
||||
@@ -56,7 +58,7 @@ public class DocumentiAcquistoImportService {
|
||||
@Autowired
|
||||
private RequestDataDTO requestData;
|
||||
@Autowired
|
||||
private DocumentiWebImportService documentiWebImportService;
|
||||
private DigitalInvoiceConverterService digitalInvoiceConverterService;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
@@ -1213,4 +1215,21 @@ public class DocumentiAcquistoImportService {
|
||||
|
||||
return dtbBaseDoct;
|
||||
}
|
||||
|
||||
public List<EntityBase> importXmlFatturaElettronica(String type, String format, ImportRequestDTO requestDto, List<AnomalieDTO> anomalie, boolean headless) throws Exception {
|
||||
|
||||
FpxToPdfDTO.FpxToPdfFile fpxToPdfFile = new FpxToPdfDTO.FpxToPdfFile();
|
||||
fpxToPdfFile.setFileContentBytes(FileUtils.readFileToByteArray(new File(requestDto.getPathFile())));
|
||||
fpxToPdfFile.setFileName(requestDto.getFileName());
|
||||
|
||||
|
||||
FpxToPdfDTO dto = new FpxToPdfDTO();
|
||||
dto.setFiles(Collections.singletonList(fpxToPdfFile));
|
||||
dto.setImportPassive(true);
|
||||
dto.setUserConverted(false);
|
||||
|
||||
digitalInvoiceConverterService.fpxToPdf(dto);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -263,7 +263,6 @@ public class SicilianiDMSExportService {
|
||||
"order by dtb_ordt_local.id_viaggio, dtb_ordt_local.key_ord";
|
||||
|
||||
whereCond = UtilityString.replaceSubString(whereCond, "dtb_ordr", "dtb_ordt_local");
|
||||
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, true);
|
||||
PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet res = ps.executeQuery();
|
||||
@@ -442,6 +441,39 @@ public class SicilianiDMSExportService {
|
||||
res.close();
|
||||
ps.close();
|
||||
|
||||
// Cancellazione ID_Viaggio inviati ad Alyante, ma non più presenti in DMS
|
||||
sql = "select dtb_ordt_local.key_ord, " +
|
||||
" dtb_infoviaggi.id_viaggio " +
|
||||
" from dtb_ordt_local INNER JOIN " + serverObject + ".dtb_infoviaggi ON dtb_ordt_local.key_ord_alyante = dtb_infoviaggi.key_ord COLLATE Latin1_General_100_CI_AS " +
|
||||
" where dtb_ordt_local.id_viaggio is null ";
|
||||
|
||||
whereCond = UtilityString.replaceSubString(whereCond, "dtb_ordr", "dtb_ordt_local");
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, true);
|
||||
ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
res = ps.executeQuery();
|
||||
while (res.next()) {
|
||||
String keyOrd = res.getString(1);
|
||||
String idViaggio = res.getString(2);
|
||||
|
||||
// Verifica se l'id_viaggio è bloccato
|
||||
Optional<HashMap<String, Object>> lockIdViaggio = Stream.of(resultMap)
|
||||
.filter(x ->
|
||||
((Integer) UtilityHashMap.getValueIfExists(x, "id_viaggio")).equals(idViaggio) &&
|
||||
((String) UtilityHashMap.getValueIfExists(x, "lockIdViaggio")).equalsIgnoreCase("S")).findFirst();
|
||||
|
||||
if (!lockIdViaggio.isPresent()) {
|
||||
sql = "delete from " + serverObject + ".dtb_infoviaggi " +
|
||||
" from " + serverObject + ".dtb_infoviaggi " +
|
||||
" where chiave_traxal = " + UtilityDB.valueToString(keyOrd);
|
||||
|
||||
PreparedStatement infoUpd = conAlyante.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
infoUpd.executeUpdate();
|
||||
infoUpd.close();
|
||||
}
|
||||
}
|
||||
res.close();
|
||||
ps.close();
|
||||
|
||||
conAlyante.commit();
|
||||
} catch (Exception e) {
|
||||
//conAlyante.rollback();
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.util.List;
|
||||
public class FpxToPdfDTO {
|
||||
|
||||
private List<FpxToPdfFile> files;
|
||||
private String importPassive;
|
||||
private String userConverted;
|
||||
private boolean importPassive;
|
||||
private boolean userConverted;
|
||||
|
||||
public FpxToPdfDTO() {
|
||||
}
|
||||
@@ -37,19 +37,19 @@ public class FpxToPdfDTO {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public String getImportPassive() {
|
||||
public boolean getImportPassive() {
|
||||
return importPassive;
|
||||
}
|
||||
|
||||
public void setImportPassive(String importPassive) {
|
||||
public void setImportPassive(boolean importPassive) {
|
||||
this.importPassive = importPassive;
|
||||
}
|
||||
|
||||
public String getUserConverted() {
|
||||
public boolean getUserConverted() {
|
||||
return userConverted;
|
||||
}
|
||||
|
||||
public FpxToPdfDTO setUserConverted(String userConverted) {
|
||||
public FpxToPdfDTO setUserConverted(boolean userConverted) {
|
||||
this.userConverted = userConverted;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DigitalInvoiceConverterService {
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
fatturaElettronicaType = (FatturaElettronicaType) JAXBIntrospector.getValue(unmarshaller.unmarshal(xmlInputStream));
|
||||
|
||||
if (Boolean.parseBoolean(payload.getImportPassive())) { // se è previsto il salvataggio del file negli allegati, verrà archiviato il file originale
|
||||
if (payload.getImportPassive()) { // se è previsto il salvataggio del file negli allegati, verrà archiviato il file originale
|
||||
passiveInvoices.add(new FileItem(filenameExt, fileContent));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DigitalInvoiceConverterService {
|
||||
|
||||
List<String> attachmentNamesList = new ArrayList<>();
|
||||
|
||||
if (allegati.size() > 0) {
|
||||
if (!allegati.isEmpty()) {
|
||||
for (int i = 0; i < allegati.size(); i++) {
|
||||
AllegatiType allegato = allegati.get(i);
|
||||
int counter = 0;
|
||||
@@ -111,13 +111,13 @@ public class DigitalInvoiceConverterService {
|
||||
}
|
||||
}
|
||||
/*solo se il medoto è invocato dalla conversione file del gestionale viene generato anche il file ministeriale */
|
||||
if(Boolean.parseBoolean(payload.getUserConverted())) {
|
||||
if(payload.getUserConverted()) {
|
||||
byte[] simplePdf = documentService.generateFpxPDFMinisteriale(FpxPDFTypeEnum.SIMPLE, filenameExt, fileContent);
|
||||
convertedFiles.add(new FpxToPdfDTO.FpxToPdfFile(simplePdf, file.getDestinationPath(), pdfFileName, String.format("%s %d della fattura %s", ATTACHMENT_PREFIX, allegati.size() + 1, filenameExt)));
|
||||
}
|
||||
}
|
||||
|
||||
if (passiveInvoices.size() > 0) {
|
||||
if (!passiveInvoices.isEmpty()) {
|
||||
DigitalInvoiceBackupService digitalInvoiceBackupService = ContextLoader.getCurrentWebApplicationContext().getBean(DigitalInvoiceBackupService.class);
|
||||
if (digitalInvoiceBackupService != null) {
|
||||
List<FileItem> receiptResult = digitalInvoiceBackupService.importReceipts(passiveInvoices, false);
|
||||
|
||||
@@ -11,6 +11,7 @@ import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.service.MailTemplateService;
|
||||
import it.integry.ems.service.MapService;
|
||||
import it.integry.ems.service.dto.GenericComunicationMailTemplateDataDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDirs;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
@@ -29,9 +30,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -85,7 +83,7 @@ public class OrdiniImportService {
|
||||
StringWriter writer = new StringWriter();
|
||||
new ObjectMapper().writeValue(writer, dialogoJsonDTO);
|
||||
String contentBody = writer.toString();
|
||||
String pathFile = UtilityDirs.getDirectoryImport(multiDBTransactionManager.getPrimaryDatasource().getDbName(), type, format).getAbsolutePath();
|
||||
String pathFile = UtilityDirs.getDirectoryImport(multiDBTransactionManager.getPrimaryDatasource().getDbName(), type, format);
|
||||
String fileName = dialogoJsonDTO.getCodMdep() + "_" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + ".json";
|
||||
UtilityFile.saveFile(pathFile, fileName, contentBody);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -120,9 +121,15 @@ public class ExchangeColliImportService {
|
||||
AtomicInteger dataCount = new AtomicInteger(0);
|
||||
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||
|
||||
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||
String sqlMinDate = "SELECT MIN(data_collo) FROM " + testataTableName + (useTempTable ? "_tmp" : "");
|
||||
Timestamp startDateTimeStamp = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(exchangeMultiDb.getPrimaryConnection(), sqlMinDate);
|
||||
|
||||
LocalDate startDate = startDateTimeStamp.toLocalDateTime().toLocalDate();
|
||||
// LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||
Result<Object> firstErrorObjectIfPresent = null;
|
||||
|
||||
|
||||
|
||||
while (startDate.minusDays(1).isBefore(UtilityLocalDate.getNow())) {
|
||||
|
||||
final LocalDate tempStartDate = startDate;
|
||||
|
||||
Reference in New Issue
Block a user