Implementata gestione pianificazioni exchange
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20240716105445 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (existsTable("stb_exchange_config"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
executeStatement("CREATE TABLE stb_exchange_config\n" +
|
||||||
|
"(\n" +
|
||||||
|
" id BIGINT IDENTITY\n" +
|
||||||
|
" CONSTRAINT stb_exchange_config_pk\n" +
|
||||||
|
" PRIMARY KEY,\n" +
|
||||||
|
" description VARCHAR(MAX),\n" +
|
||||||
|
" internal_profile_db VARCHAR(MAX) NOT NULL,\n" +
|
||||||
|
" external_profile_db VARCHAR(MAX) NOT NULL,\n" +
|
||||||
|
" schedulation_cron VARCHAR(MAX) NOT NULL,\n" +
|
||||||
|
" created_at DATETIME DEFAULT GETDATE() NOT NULL,\n" +
|
||||||
|
" last_execution DATETIME,\n" +
|
||||||
|
" last_execution_error_message VARCHAR(MAX)\n" +
|
||||||
|
")");
|
||||||
|
|
||||||
|
executeStatement("CREATE TABLE dbo.stb_exchange_config_detail\n" +
|
||||||
|
"(\n" +
|
||||||
|
" id BIGINT IDENTITY\n" +
|
||||||
|
" CONSTRAINT stb_exchange_config_detail_pk\n" +
|
||||||
|
" PRIMARY KEY,\n" +
|
||||||
|
" stb_exchange_config_id BIGINT NOT NULL\n" +
|
||||||
|
" CONSTRAINT stb_exchange_config_detail_stb_exchange_config_id_fk\n" +
|
||||||
|
" REFERENCES dbo.stb_exchange_config (id),\n" +
|
||||||
|
" type INT NOT NULL,\n" +
|
||||||
|
" execution_order INT DEFAULT 0 NOT NULL\n" +
|
||||||
|
")");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,8 +32,8 @@ public class ScheduledOperationHandlerComponent {
|
|||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private HashMap<String, ScheduledFuture<?>> scheduledOperations = new HashMap<>();
|
private final HashMap<String, ScheduledFuture<?>> scheduledOperations = new HashMap<>();
|
||||||
private HashMap<String, DirectoryWatcher> directoryWatcherOperations = new HashMap<>();
|
private final HashMap<String, DirectoryWatcher> directoryWatcherOperations = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public void scheduleOperation(BaseAutomatedOperationDTO operationModel) throws Exception {
|
public void scheduleOperation(BaseAutomatedOperationDTO operationModel) throws Exception {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import it.integry.ems.datasource.DataSource;
|
|||||||
import it.integry.ems.dto.EntityPermissionsDTO;
|
import it.integry.ems.dto.EntityPermissionsDTO;
|
||||||
import it.integry.ems.exception.InvalidPermissionsException;
|
import it.integry.ems.exception.InvalidPermissionsException;
|
||||||
import it.integry.ems.javabeans.RequestDataDTO;
|
import it.integry.ems.javabeans.RequestDataDTO;
|
||||||
import it.integry.ems.json.ResponseJSONObjectMapper;
|
|
||||||
import it.integry.ems.model.ColumnMetadataDTO;
|
import it.integry.ems.model.ColumnMetadataDTO;
|
||||||
import it.integry.ems.settings.Model.SettingsModel;
|
import it.integry.ems.settings.Model.SettingsModel;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||||
@@ -33,8 +32,8 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.josql.Query;
|
import org.josql.Query;
|
||||||
import org.josql.QueryResults;
|
import org.josql.QueryResults;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.context.ContextLoader;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
@@ -45,7 +44,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class EntityProcessor {
|
public class EntityProcessor {
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
@@ -59,18 +57,6 @@ public class EntityProcessor {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EntityPropertyHolder entityPropertyHolder;
|
private EntityPropertyHolder entityPropertyHolder;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ResponseJSONObjectMapper jsonObjectMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager mDbTransactManager;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RequestDataDTO requestDataDTO;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EntityLoggerService entityLoggerService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityLoggerNewService entityLoggerNewService;
|
private EntityLoggerNewService entityLoggerNewService;
|
||||||
|
|
||||||
@@ -78,6 +64,7 @@ public class EntityProcessor {
|
|||||||
private SettingsModel settingsModel;
|
private SettingsModel settingsModel;
|
||||||
|
|
||||||
public <T> T processEntity(EntityInterface entity, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
public <T> T processEntity(EntityInterface entity, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
|
||||||
|
|
||||||
String username = "";
|
String username = "";
|
||||||
|
|
||||||
@@ -85,31 +72,35 @@ public class EntityProcessor {
|
|||||||
username = requestDataDTO.getUsername();
|
username = requestDataDTO.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (T) processEntity(entity, true, false, username, multiDBTransactionManager, true, false);
|
return (T) processEntity(entity, true, false, username, multiDBTransactionManager, requestDataDTO, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBase processEntity(EntityInterface entity, boolean skipCommit, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
public EntityBase processEntity(EntityInterface entity, boolean skipCommit, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
|
||||||
|
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
|
||||||
String username = "";
|
String username = "";
|
||||||
|
|
||||||
if (requestDataDTO != null && requestDataDTO.isValidUsername()) {
|
if (requestDataDTO != null && requestDataDTO.isValidUsername()) {
|
||||||
username = requestDataDTO.getUsername();
|
username = requestDataDTO.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (EntityBase) processEntity(entity, true, skipCommit, username, multiDBTransactionManager, true, false);
|
return (EntityBase) processEntity(entity, true, skipCommit, username, multiDBTransactionManager, requestDataDTO, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityBase processEntity(EntityInterface entity, Boolean isSync,
|
public EntityBase processEntity(EntityInterface entity, Boolean isSync,
|
||||||
boolean skipCommit, String username,
|
boolean skipCommit, String username,
|
||||||
MultiDBTransactionManager mdb) throws Exception {
|
MultiDBTransactionManager mdb) throws Exception {
|
||||||
return (EntityBase) processEntity(entity, isSync, skipCommit, username, mdb, true, false);
|
|
||||||
|
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
|
||||||
|
return (EntityBase) processEntity(entity, isSync, skipCommit, username, mdb, requestDataDTO, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object processEntity(EntityInterface entity, Boolean isSync,
|
public Object processEntity(EntityInterface entity, Boolean isSync,
|
||||||
boolean skipCommit, String username,
|
boolean skipCommit, String username,
|
||||||
MultiDBTransactionManager mdb,
|
MultiDBTransactionManager mdb,
|
||||||
boolean completeEntity) throws Exception {
|
boolean completeEntity) throws Exception {
|
||||||
return processEntity(entity, isSync, skipCommit, username, mdb, completeEntity, false);
|
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
|
||||||
|
return processEntity(entity, isSync, skipCommit, username, mdb, requestDataDTO, completeEntity, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +117,7 @@ public class EntityProcessor {
|
|||||||
|
|
||||||
public Object processEntity(EntityInterface entity, Boolean isSync,
|
public Object processEntity(EntityInterface entity, Boolean isSync,
|
||||||
boolean skipCommit, String username,
|
boolean skipCommit, String username,
|
||||||
MultiDBTransactionManager mdb,
|
MultiDBTransactionManager mdb, RequestDataDTO requestDataDTO,
|
||||||
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -139,13 +130,13 @@ public class EntityProcessor {
|
|||||||
entity.setOperation(OperationType.NO_OP);
|
entity.setOperation(OperationType.NO_OP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!overrideEntityChildCheck) this.checkEntityChildsUsage(entity, mdb);
|
if (!overrideEntityChildCheck) this.checkEntityChildsUsage(entity, mdb, requestDataDTO);
|
||||||
|
|
||||||
if (settingsModel.isEnablePermissionCheck() && !checkUserPermissions(entity))
|
if (settingsModel.isEnablePermissionCheck() && !checkUserPermissions(entity,mdb))
|
||||||
throw new InvalidPermissionsException();
|
throw new InvalidPermissionsException();
|
||||||
|
|
||||||
if (entity.getOperation() == OperationType.NO_OP) {
|
if (entity.getOperation() == OperationType.NO_OP) {
|
||||||
processInternal(entity, isSync, mdb, completeEntity);
|
processInternal(entity, isSync, mdb, requestDataDTO, completeEntity);
|
||||||
} else if (entity.getOperation() == OperationType.SELECT_OBJECT) {
|
} else if (entity.getOperation() == OperationType.SELECT_OBJECT) {
|
||||||
return entity.selectAndMergeEntity(mdb.getPrimaryConnection(), (EntityBase) entity);
|
return entity.selectAndMergeEntity(mdb.getPrimaryConnection(), (EntityBase) entity);
|
||||||
//return entity;
|
//return entity;
|
||||||
@@ -155,7 +146,7 @@ public class EntityProcessor {
|
|||||||
return entityList;
|
return entityList;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
processInternal(entity, isSync, mdb, completeEntity);
|
processInternal(entity, isSync, mdb, requestDataDTO, completeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipCommit) {
|
if (!skipCommit) {
|
||||||
@@ -174,7 +165,7 @@ public class EntityProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkEntityChildsUsage(EntityInterface entityInterface, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
private void checkEntityChildsUsage(EntityInterface entityInterface, MultiDBTransactionManager multiDBTransactionManager, RequestDataDTO requestDataDTO) throws Exception {
|
||||||
boolean isMaster = entityPropertyHolder.isEntityMaster(((EntityBase) entityInterface).getClass());;
|
boolean isMaster = entityPropertyHolder.isEntityMaster(((EntityBase) entityInterface).getClass());;
|
||||||
OperationType operationType = entityInterface.getOperation();
|
OperationType operationType = entityInterface.getOperation();
|
||||||
|
|
||||||
@@ -209,12 +200,12 @@ public class EntityProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkUserPermissions(EntityInterface entity) throws Exception {
|
private boolean checkUserPermissions(EntityInterface entity, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
if (!UtilityUser.checkLocalUserExist(mDbTransactManager, entity.getUsername())) return true;
|
if (!UtilityUser.checkLocalUserExist(multiDBTransactionManager, entity.getUsername())) return true;
|
||||||
|
|
||||||
List<EntityPermissionsDTO> results = UtilityUser.getUserPermissions(mDbTransactManager, entity.getUsername(), (EntityBase) entity);
|
List<EntityPermissionsDTO> results = UtilityUser.getUserPermissions(multiDBTransactionManager, entity.getUsername(), (EntityBase) entity);
|
||||||
|
|
||||||
if (results == null || results.size() == 0) return false;
|
if (results == null || results.isEmpty()) return false;
|
||||||
|
|
||||||
EntityPermissionsDTO firstPermission = results.get(0);
|
EntityPermissionsDTO firstPermission = results.get(0);
|
||||||
|
|
||||||
@@ -242,7 +233,7 @@ public class EntityProcessor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processInternal(EntityInterface entity, Boolean isSync, MultiDBTransactionManager multiDBTransactionManager, boolean completeEntity) throws Exception {
|
private void processInternal(EntityInterface entity, Boolean isSync, MultiDBTransactionManager multiDBTransactionManager, RequestDataDTO requestDataDTO, boolean completeEntity) throws Exception {
|
||||||
DataSource currentDs = multiDBTransactionManager.getPrimaryDatasource();
|
DataSource currentDs = multiDBTransactionManager.getPrimaryDatasource();
|
||||||
Connection primaryDB = currentDs.getConnection();
|
Connection primaryDB = currentDs.getConnection();
|
||||||
String currentProfileDb = currentDs.getProfile();
|
String currentProfileDb = currentDs.getProfile();
|
||||||
@@ -415,6 +406,8 @@ public class EntityProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean singleTransaction) throws Exception {
|
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean singleTransaction) throws Exception {
|
||||||
|
|
||||||
|
final MultiDBTransactionManager mDbTransactManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
||||||
return processEntityList(entities, null, true, singleTransaction, false, mDbTransactManager, true, false);
|
return processEntityList(entities, null, true, singleTransaction, false, mDbTransactManager, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,10 +416,14 @@ public class EntityProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
||||||
|
|
||||||
|
final MultiDBTransactionManager mDbTransactManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
||||||
return processEntityList(entities, null, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
return processEntityList(entities, null, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, String username, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
public List<EntityBase> processEntityList(List<? extends EntityBase> entities, String username, boolean isSync, boolean singleTransaction, boolean ordinaSuPriorita) throws Exception {
|
||||||
|
|
||||||
|
final MultiDBTransactionManager mDbTransactManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
||||||
return processEntityList(entities, username, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
return processEntityList(entities, username, isSync, singleTransaction, ordinaSuPriorita, mDbTransactManager, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,6 +446,9 @@ public class EntityProcessor {
|
|||||||
MultiDBTransactionManager multiDBTransactionManager,
|
MultiDBTransactionManager multiDBTransactionManager,
|
||||||
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
|
||||||
|
|
||||||
if (UtilityString.isNullOrEmpty(username) && requestDataDTO != null && requestDataDTO.isValidUsername()) {
|
if (UtilityString.isNullOrEmpty(username) && requestDataDTO != null && requestDataDTO.isValidUsername()) {
|
||||||
username = requestDataDTO.getUsername();
|
username = requestDataDTO.getUsername();
|
||||||
}
|
}
|
||||||
@@ -466,7 +466,7 @@ public class EntityProcessor {
|
|||||||
EntityBase entity = entities.get(i);
|
EntityBase entity = entities.get(i);
|
||||||
entity.setTransactionGroupId(prevTransactionGroupId);
|
entity.setTransactionGroupId(prevTransactionGroupId);
|
||||||
try {
|
try {
|
||||||
EntityBase entityResult = (EntityBase) this.processEntity(entity, isSync, singleTransaction, username, multiDBTransactionManager, completeEntity, overrideEntityChildCheck);
|
EntityBase entityResult = (EntityBase) this.processEntity(entity, isSync, singleTransaction, username, multiDBTransactionManager, requestDataDTO, completeEntity, overrideEntityChildCheck);
|
||||||
prevTransactionGroupId = entity.getTransactionGroupId();
|
prevTransactionGroupId = entity.getTransactionGroupId();
|
||||||
if (entityResult != null) {
|
if (entityResult != null) {
|
||||||
entityList.add(entityResult);
|
entityList.add(entityResult);
|
||||||
@@ -489,7 +489,7 @@ public class EntityProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mDbTransactManager.commitAll();
|
multiDBTransactionManager.commitAll();
|
||||||
|
|
||||||
return entityList;
|
return entityList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class AsyncHistoryManager {
|
|||||||
private final AtomicReference<List<ExportHistoryGroupDTO>> currentlyInExecutionG = new AtomicReference<>(new ArrayList<>());
|
private final AtomicReference<List<ExportHistoryGroupDTO>> currentlyInExecutionG = new AtomicReference<>(new ArrayList<>());
|
||||||
|
|
||||||
|
|
||||||
@PostContextConstruct
|
@PostContextConstruct(priority = 20)
|
||||||
public void init() {
|
public void init() {
|
||||||
this.looperService.add(this::consumeRetrieveQueue, 10 * 1000, "async-history-read");
|
this.looperService.add(this::consumeRetrieveQueue, 10 * 1000, "async-history-read");
|
||||||
this.looperService.add(this::consumeProcessedQueue, 2 * 1000, "async-history-save");
|
this.looperService.add(this::consumeProcessedQueue, 2 * 1000, "async-history-save");
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Optional<AvailableConnectionsModel> availableConnectionsModel = Stream.of(SettingsModel.getInstance().getAvailableConnections())
|
java.util.Optional<AvailableConnectionsModel> availableConnectionsModel = SettingsModel.getInstance().getAvailableConnections().stream()
|
||||||
.filter(x -> x.getProfileName().equalsIgnoreCase(profileDb))
|
.filter(x -> x.getProfileName().equalsIgnoreCase(profileDb))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.groupingBy;
|
import static java.util.stream.Collectors.groupingBy;
|
||||||
@@ -79,7 +76,7 @@ public class RemoteSynchronizationSetupService {
|
|||||||
publicationGroups.add(publicationGroupDTO);
|
publicationGroups.add(publicationGroupDTO);
|
||||||
|
|
||||||
final List<PublicationDTO> publications = stbPublicationsDetails.stream()
|
final List<PublicationDTO> publications = stbPublicationsDetails.stream()
|
||||||
.filter(x -> x.getStbPublicationId() == stbPublication.getId())
|
.filter(x -> Objects.equals(x.getStbPublicationId(), stbPublication.getId()))
|
||||||
.map(PublicationDTO::fromStbPublicationDetail)
|
.map(PublicationDTO::fromStbPublicationDetail)
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
publicationGroupDTO.setPublications(publications);
|
publicationGroupDTO.setPublications(publications);
|
||||||
|
|||||||
@@ -52,64 +52,72 @@ public class MtbGrup extends EntityBase implements EquatableEntityInterface<MtbG
|
|||||||
return codMgrp;
|
return codMgrp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCodMgrp(String codMgrp) {
|
public MtbGrup setCodMgrp(String codMgrp) {
|
||||||
this.codMgrp = codMgrp;
|
this.codMgrp = codMgrp;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescrizione() {
|
public String getDescrizione() {
|
||||||
return descrizione;
|
return descrizione;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescrizione(String descrizione) {
|
public MtbGrup setDescrizione(String descrizione) {
|
||||||
this.descrizione = descrizione;
|
this.descrizione = descrizione;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFlagValMag() {
|
public String getFlagValMag() {
|
||||||
return flagValMag;
|
return flagValMag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlagValMag(String flagValMag) {
|
public MtbGrup setFlagValMag(String flagValMag) {
|
||||||
this.flagValMag = flagValMag;
|
this.flagValMag = flagValMag;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLogoWeb() {
|
public String getLogoWeb() {
|
||||||
return logoWeb;
|
return logoWeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLogoWeb(String logoWeb) {
|
public MtbGrup setLogoWeb(String logoWeb) {
|
||||||
this.logoWeb = logoWeb;
|
this.logoWeb = logoWeb;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCriterioVal() {
|
public String getCriterioVal() {
|
||||||
return criterioVal;
|
return criterioVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCriterioVal(String criterioVal) {
|
public MtbGrup setCriterioVal(String criterioVal) {
|
||||||
this.criterioVal = criterioVal;
|
this.criterioVal = criterioVal;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTipoMgrp() {
|
public String getTipoMgrp() {
|
||||||
return tipoMgrp;
|
return tipoMgrp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTipoMgrp(String tipoMgrp) {
|
public MtbGrup setTipoMgrp(String tipoMgrp) {
|
||||||
this.tipoMgrp = tipoMgrp;
|
this.tipoMgrp = tipoMgrp;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtbSgrp> getMtbSgrp() {
|
public List<MtbSgrp> getMtbSgrp() {
|
||||||
return mtbSgrp;
|
return mtbSgrp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMtbSgrp(List<MtbSgrp> mtbSgrp) {
|
public MtbGrup setMtbSgrp(List<MtbSgrp> mtbSgrp) {
|
||||||
this.mtbSgrp = mtbSgrp;
|
this.mtbSgrp = mtbSgrp;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MtbSfam> getMtbSfam() {
|
public List<MtbSfam> getMtbSfam() {
|
||||||
return mtbSfam;
|
return mtbSfam;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMtbSfam(List<MtbSfam> mtbSfam) {
|
public MtbGrup setMtbSfam(List<MtbSfam> mtbSfam) {
|
||||||
this.mtbSfam = mtbSfam;
|
this.mtbSfam = mtbSfam;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -56,40 +56,45 @@ public class MtbSgrp extends EntityBase implements EquatableEntityInterface<MtbS
|
|||||||
return codMgrp;
|
return codMgrp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCodMgrp(String codMgrp) {
|
public MtbSgrp setCodMgrp(String codMgrp) {
|
||||||
this.codMgrp = codMgrp;
|
this.codMgrp = codMgrp;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCodMsgr() {
|
public String getCodMsgr() {
|
||||||
return codMsgr;
|
return codMsgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCodMsgr(String codMsgr) {
|
public MtbSgrp setCodMsgr(String codMsgr) {
|
||||||
this.codMsgr = codMsgr;
|
this.codMsgr = codMsgr;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescrizione() {
|
public String getDescrizione() {
|
||||||
return descrizione;
|
return descrizione;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescrizione(String descrizione) {
|
public MtbSgrp setDescrizione(String descrizione) {
|
||||||
this.descrizione = descrizione;
|
this.descrizione = descrizione;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInclInStat() {
|
public String getInclInStat() {
|
||||||
return inclInStat;
|
return inclInStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInclInStat(String inclInStat) {
|
public MtbSgrp setInclInStat(String inclInStat) {
|
||||||
this.inclInStat = inclInStat;
|
this.inclInStat = inclInStat;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContoRimFin() {
|
public String getContoRimFin() {
|
||||||
return contoRimFin;
|
return contoRimFin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContoRimFin(String contoRimFin) {
|
public MtbSgrp setContoRimFin(String contoRimFin) {
|
||||||
this.contoRimFin = contoRimFin;
|
this.contoRimFin = contoRimFin;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getOrdinamento() {
|
public Integer getOrdinamento() {
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package it.integry.ems_model.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
import it.integry.ems_model.annotation.*;
|
||||||
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import org.kie.api.definition.type.PropertyReactive;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Master()
|
||||||
|
@PropertyReactive()
|
||||||
|
@Table(value = StbExchangeConfig.ENTITY)
|
||||||
|
@JsonTypeName(value = StbExchangeConfig.ENTITY)
|
||||||
|
public class StbExchangeConfig extends EntityBase {
|
||||||
|
|
||||||
|
public final static String ENTITY = "stb_exchange_config";
|
||||||
|
|
||||||
|
private final static long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@PK()
|
||||||
|
@Identity()
|
||||||
|
@SqlField(value = "id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@SqlField(value = "description", maxLength = -1, nullable = true)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@SqlField(value = "internal_profile_db", maxLength = -1, nullable = false)
|
||||||
|
private String internalProfileDb;
|
||||||
|
|
||||||
|
@SqlField(value = "external_profile_db", maxLength = -1, nullable = false)
|
||||||
|
private String externalProfileDb;
|
||||||
|
|
||||||
|
@SqlField(value = "schedulation_cron", maxLength = -1, nullable = false)
|
||||||
|
private String schedulationCron;
|
||||||
|
|
||||||
|
@SqlField(value = "created_at", nullable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@SqlField(value = "last_execution", nullable = true)
|
||||||
|
private LocalDateTime lastExecution;
|
||||||
|
|
||||||
|
@SqlField(value = "last_execution_error_message", maxLength = -1, nullable = true)
|
||||||
|
private String lastExecutionErrorMessage;
|
||||||
|
|
||||||
|
@EntityChild()
|
||||||
|
private List<StbExchangeConfigDetail> stbExchangeConfigDetail = new ArrayList<>();
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInternalProfileDb() {
|
||||||
|
return internalProfileDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setInternalProfileDb(String internalProfileDb) {
|
||||||
|
this.internalProfileDb = internalProfileDb;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExternalProfileDb() {
|
||||||
|
return externalProfileDb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setExternalProfileDb(String externalProfileDb) {
|
||||||
|
this.externalProfileDb = externalProfileDb;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSchedulationCron() {
|
||||||
|
return schedulationCron;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setSchedulationCron(String schedulationCron) {
|
||||||
|
this.schedulationCron = schedulationCron;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setCreatedAt(LocalDateTime createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getLastExecution() {
|
||||||
|
return lastExecution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setLastExecution(LocalDateTime lastExecution) {
|
||||||
|
this.lastExecution = lastExecution;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastExecutionErrorMessage() {
|
||||||
|
return lastExecutionErrorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setLastExecutionErrorMessage(String lastExecutionErrorMessage) {
|
||||||
|
this.lastExecutionErrorMessage = lastExecutionErrorMessage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<StbExchangeConfigDetail> getStbExchangeConfigDetail() {
|
||||||
|
return stbExchangeConfigDetail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfig setStbExchangeConfigDetail(List<StbExchangeConfigDetail> stbExchangeConfigDetail) {
|
||||||
|
this.stbExchangeConfigDetail = stbExchangeConfigDetail;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteChilds() throws Exception {
|
||||||
|
StbExchangeConfigDetail stbExchangeConfigDetail = new StbExchangeConfigDetail();
|
||||||
|
stbExchangeConfigDetail.deleteAllEntities(connection, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package it.integry.ems_model.entity;
|
||||||
|
|
||||||
|
import it.integry.ems_model.annotation.*;
|
||||||
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import org.kie.api.definition.type.PropertyReactive;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
|
||||||
|
@PropertyReactive()
|
||||||
|
@Table(value = StbExchangeConfigDetail.ENTITY)
|
||||||
|
@JsonTypeName(value = StbExchangeConfigDetail.ENTITY)
|
||||||
|
public class StbExchangeConfigDetail extends EntityBase {
|
||||||
|
|
||||||
|
public final static String ENTITY = "stb_exchange_config_detail";
|
||||||
|
|
||||||
|
private final static long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@PK()
|
||||||
|
@Identity()
|
||||||
|
@SqlField(value = "id", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@SqlField(value = "stb_exchange_config_id", nullable = false)
|
||||||
|
@FK(tableName = StbExchangeConfig.ENTITY, columnName = "id")
|
||||||
|
@ImportFromParent("id")
|
||||||
|
private Long stbExchangeConfigId;
|
||||||
|
|
||||||
|
@SqlField(value = "type", nullable = false)
|
||||||
|
private Integer configType;
|
||||||
|
|
||||||
|
@SqlField(value = "execution_order", nullable = false)
|
||||||
|
private Integer executionOrder;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfigDetail setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getStbExchangeConfigId() {
|
||||||
|
return stbExchangeConfigId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfigDetail setStbExchangeConfigId(Long stbExchangeConfigId) {
|
||||||
|
this.stbExchangeConfigId = stbExchangeConfigId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConfigType() {
|
||||||
|
return configType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfigDetail setConfigType(Integer configType) {
|
||||||
|
this.configType = configType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getExecutionOrder() {
|
||||||
|
return executionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StbExchangeConfigDetail setExecutionOrder(Integer executionOrder) {
|
||||||
|
this.executionOrder = executionOrder;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
|
|||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.system.exchange.service.ExchangeArticoliImportService;
|
import it.integry.ems.system.exchange.service.ExchangeArticoliImportService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -26,9 +27,14 @@ public class ExchangeArticoliImportController {
|
|||||||
@RequestMapping(value = "import", method = RequestMethod.GET)
|
@RequestMapping(value = "import", method = RequestMethod.GET)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ServiceRestResponse importArticoli(HttpServletRequest request,
|
ServiceRestResponse importArticoli(HttpServletRequest request,
|
||||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
|
||||||
|
@RequestParam() String profileDbExchange) throws Exception {
|
||||||
|
|
||||||
exchangeArticoliImportService.importArticoli();
|
|
||||||
|
try (MultiDBTransactionManager internalDb = new MultiDBTransactionManager(profileDb);
|
||||||
|
MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
|
||||||
|
exchangeArticoliImportService.importArticoli(internalDb, exchangeDb);
|
||||||
|
}
|
||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
|
|||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.system.exchange.service.ExchangeColliImportService;
|
import it.integry.ems.system.exchange.service.ExchangeColliImportService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -26,9 +27,16 @@ public class ExchangeColliImportController {
|
|||||||
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ServiceRestResponse importColliLavorazione(HttpServletRequest request,
|
ServiceRestResponse importColliLavorazione(HttpServletRequest request,
|
||||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
|
||||||
|
@RequestParam() String profileDbExchange) throws Exception {
|
||||||
|
|
||||||
|
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(profileDb);
|
||||||
|
MultiDBTransactionManager multiDBTransactionManagerExchange = new MultiDBTransactionManager(profileDbExchange)) {
|
||||||
|
|
||||||
|
exchangeColliImportService.importColliLavorazione(multiDBTransactionManager, multiDBTransactionManagerExchange);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
exchangeColliImportService.importColliLavorazione();
|
|
||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +51,8 @@ public class ExchangeColliImportController {
|
|||||||
@RequestParam(required = false) String codVdes
|
@RequestParam(required = false) String codVdes
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
LocalDate dataCertificato = LocalDate.parse(dataCert);
|
LocalDate dataCertificato = LocalDate.parse(dataCert);
|
||||||
return ServiceRestResponse.createPositiveResponse(exchangeColliImportService.getCertificati(codAnag,
|
return ServiceRestResponse.createPositiveResponse(exchangeColliImportService.getCertificati(configuration,
|
||||||
|
codAnag,
|
||||||
dataCertificato,
|
dataCertificato,
|
||||||
codMart,
|
codMart,
|
||||||
codVdes));
|
codVdes));
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package it.integry.ems.system.exchange.controller;
|
||||||
|
|
||||||
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||||
|
import it.integry.ems.settings.Model.SettingsModel;
|
||||||
|
import it.integry.ems.system.exchange.service.ExchangeConfigService;
|
||||||
|
import it.integry.ems.system.exchange.service.ExchangeImportSchemaManagerService;
|
||||||
|
import it.integry.ems_model.entity.StbExchangeConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Scope("request")
|
||||||
|
@RequestMapping("exchange/configuration/")
|
||||||
|
public class ExchangeConfigController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ExchangeConfigService exchangeConfigService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SettingsModel settingsModel;
|
||||||
|
|
||||||
|
@RequestMapping(value = "available-profiles", method = RequestMethod.GET)
|
||||||
|
public ServiceRestResponse retrieveAvailableProfiles(
|
||||||
|
@RequestParam(defaultValue = "true") boolean onlyInternal) throws Exception {
|
||||||
|
|
||||||
|
return ServiceRestResponse.createPositiveResponse(settingsModel.getAvailableConnections().stream()
|
||||||
|
.filter(x -> x.getInternalDb() || !onlyInternal)
|
||||||
|
.map(AvailableConnectionsModel::getProfileName)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "available-types", method = RequestMethod.GET)
|
||||||
|
public ServiceRestResponse retrieveAvailableTypes() throws Exception {
|
||||||
|
final HashMap<String, Integer> data = new HashMap<>();
|
||||||
|
Arrays.stream(ExchangeImportSchemaManagerService.SchemaType.values())
|
||||||
|
.forEach(x -> data.put(x.toString(), x.getValue()));
|
||||||
|
|
||||||
|
return ServiceRestResponse.createPositiveResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "retrieve", method = RequestMethod.GET)
|
||||||
|
public ServiceRestResponse retrieve() throws Exception {
|
||||||
|
return ServiceRestResponse.createPositiveResponse(exchangeConfigService.retrieveConfigurations());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "insert", method = RequestMethod.POST)
|
||||||
|
public ServiceRestResponse insert(@RequestBody StbExchangeConfig configToInsert) throws Exception {
|
||||||
|
exchangeConfigService.addConfiguration(configToInsert);
|
||||||
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "{configId}/delete", method = RequestMethod.GET)
|
||||||
|
public ServiceRestResponse deletePublicationGroup(@PathVariable long configId) throws Exception {
|
||||||
|
exchangeConfigService.deleteConfiguration(configId);
|
||||||
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
|
|||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.system.exchange.service.ExchangeDocumentImportService;
|
import it.integry.ems.system.exchange.service.ExchangeDocumentImportService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -26,9 +27,13 @@ public class ExchangeDocumentImportController {
|
|||||||
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ServiceRestResponse importDocumentiLavorazione(HttpServletRequest request,
|
ServiceRestResponse importDocumentiLavorazione(HttpServletRequest request,
|
||||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
|
||||||
|
@RequestParam() String profileDbExchange) throws Exception {
|
||||||
|
|
||||||
exchangeDocumentImportService.importTestateDocumentiLavorazione();
|
try (MultiDBTransactionManager internalDb = new MultiDBTransactionManager(profileDb);
|
||||||
|
MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
|
||||||
|
exchangeDocumentImportService.importTestateDocumentiLavorazione(internalDb, exchangeDb);
|
||||||
|
}
|
||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
|
|||||||
|
|
||||||
import it.integry.common.var.CommonConstants;
|
import it.integry.common.var.CommonConstants;
|
||||||
import it.integry.ems.response.ServiceRestResponse;
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
import it.integry.ems.system.exchange.service.ExchangeOrdiniImportService;
|
import it.integry.ems.system.exchange.service.ExchangeOrdiniImportService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -23,13 +24,17 @@ public class ExchangeOrdiniImportController {
|
|||||||
private ExchangeOrdiniImportService exchangeOrdiniImportService;
|
private ExchangeOrdiniImportService exchangeOrdiniImportService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ServiceRestResponse importLavorazione(HttpServletRequest request,
|
ServiceRestResponse importLavorazione(HttpServletRequest request,
|
||||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
|
||||||
|
@RequestParam() String profileDbExchange) throws Exception {
|
||||||
|
|
||||||
exchangeOrdiniImportService.importOrdiniLavorazione();
|
|
||||||
|
try (MultiDBTransactionManager internalDb = new MultiDBTransactionManager(profileDb);
|
||||||
|
MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
|
||||||
|
exchangeOrdiniImportService.importOrdiniLavorazione(internalDb, exchangeDb);
|
||||||
|
}
|
||||||
return ServiceRestResponse.createPositiveResponse();
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import it.integry.ems_model.utility.UtilityDB;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -25,19 +24,14 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class ExchangeArticoliImportService {
|
public class ExchangeArticoliImportService {
|
||||||
|
|
||||||
//TODO: To be remove, only for fast development
|
//TODO: To be remove, only for fast development
|
||||||
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
|
|
||||||
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
|
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityProcessor entityProcessor;
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||||
|
|
||||||
@@ -46,61 +40,59 @@ public class ExchangeArticoliImportService {
|
|||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public void importArticoli() throws Exception {
|
public void importArticoli(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
|
||||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
try {
|
||||||
try {
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli, useTempTable);
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli, useTempTable);
|
|
||||||
|
|
||||||
importGruppiMerceologici(exchangeDb, useTempTable);
|
importGruppiMerceologici(internalMultiDb, exchangeMultiDb, useTempTable);
|
||||||
|
|
||||||
final List<MtbAart> exchangeImportedData = retrieveArticoli(
|
final List<MtbAart> exchangeImportedData = retrieveArticoli(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<MtbAart> exchangeUpdatedData = retrieveArticoli(
|
final List<MtbAart> exchangeUpdatedData = retrieveArticoli(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||||
.runSync(MtbAart.class, exchangeImportedData, exchangeUpdatedData);
|
.runSync(MtbAart.class, exchangeImportedData, exchangeUpdatedData);
|
||||||
|
|
||||||
allData.stream()
|
allData.stream()
|
||||||
.filter(x -> x.getOperation() == OperationType.INSERT)
|
.filter(x -> x.getOperation() == OperationType.INSERT)
|
||||||
.forEach(x -> x.setOperation(OperationType.INSERT_OR_UPDATE));
|
.forEach(x -> x.setOperation(OperationType.INSERT_OR_UPDATE));
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
final Exception[] firstExceptionToThrow = {null};
|
||||||
|
|
||||||
AtomicInteger importedCounter = new AtomicInteger();
|
AtomicInteger importedCounter = new AtomicInteger();
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
List<RunnableThrowable> calls = new ArrayList<>();
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : allData) {
|
for (EquatableEntityInterface dataToSave : allData) {
|
||||||
|
|
||||||
// calls.add(() -> {
|
// calls.add(() -> {
|
||||||
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importati {} articoli di {}", importedCounter.incrementAndGet(), allData.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, multiDBTransactionManager);
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbAart) dataToSave, useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (MtbAart) dataToSave, useTempTable);
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del documento", ex);
|
logger.error("Errore durante l'importazione dell'articolo", ex);
|
||||||
multiDBTransactionManager.rollbackAll();
|
internalMultiDb.rollbackAll();
|
||||||
//throw ex;
|
//throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
// UtilityThread.executeParallel(calls);
|
// UtilityThread.executeParallel(calls);
|
||||||
|
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,60 +122,133 @@ public class ExchangeArticoliImportService {
|
|||||||
connection.commit();
|
connection.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importGruppiMerceologici(MultiDBTransactionManager exchangeDb, boolean useTempTable) throws Exception {
|
private void importGruppiMerceologici(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeDb, boolean useTempTable) throws Exception {
|
||||||
final List<MtbGrup> exchangeImportedData = retrieveMtbGrup(
|
final List<MtbGrup> exchangeImportedDataMtbGrup = retrieveMtbGrup(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeDb.getPrimaryConnection(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<MtbGrup> exchangeUpdatedData = retrieveMtbGrup(
|
final List<MtbSgrp> exchangeImportedDataMtbSgrp = retrieveMtbSgrup(
|
||||||
|
exchangeDb.getPrimaryConnection(),
|
||||||
|
true, false);
|
||||||
|
|
||||||
|
final List<MtbSfam> exchangeImportedDataMtbSfam = retrieveMtbSfam(
|
||||||
|
exchangeDb.getPrimaryConnection(),
|
||||||
|
true, false);
|
||||||
|
|
||||||
|
final List<MtbGrup> exchangeUpdatedDataMtbGrup = retrieveMtbGrup(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeDb.getPrimaryConnection(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
final List<MtbSgrp> exchangeUpdatedDataMtbSgrp = retrieveMtbSgrup(
|
||||||
.runSync(MtbGrup.class, exchangeImportedData, exchangeUpdatedData);
|
exchangeDb.getPrimaryConnection(),
|
||||||
|
false, useTempTable);
|
||||||
|
|
||||||
allData.stream()
|
final List<MtbSfam> exchangeUpdatedDataMtbSfam = retrieveMtbSfam(
|
||||||
.map(x -> (MtbGrup) x)
|
exchangeDb.getPrimaryConnection(),
|
||||||
|
false, useTempTable);
|
||||||
|
|
||||||
|
|
||||||
|
List<EquatableEntityInterface> allMgrpData = exchangeImportDataManagerService
|
||||||
|
.runSync(MtbGrup.class, exchangeImportedDataMtbGrup, exchangeUpdatedDataMtbGrup);
|
||||||
|
|
||||||
|
List<EquatableEntityInterface> allMsgrpData = exchangeImportDataManagerService
|
||||||
|
.runSync(MtbSgrp.class, exchangeImportedDataMtbSgrp, exchangeUpdatedDataMtbSgrp);
|
||||||
|
|
||||||
|
List<EquatableEntityInterface> allMsfamData = exchangeImportDataManagerService
|
||||||
|
.runSync(MtbSfam.class, exchangeImportedDataMtbSfam, exchangeUpdatedDataMtbSfam);
|
||||||
|
|
||||||
|
|
||||||
|
allMgrpData.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||||
|
allMsgrpData.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||||
|
allMsfamData.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||||
|
|
||||||
|
|
||||||
|
allMsgrpData.stream()
|
||||||
|
.map(x -> (MtbSgrp) x)
|
||||||
|
.forEach(x -> x.setMtbSfam(allMsfamData.stream()
|
||||||
|
.map(y -> (MtbSfam) y)
|
||||||
|
.filter(y -> y.getCodMgrp().equalsIgnoreCase(x.getCodMgrp()) &&
|
||||||
|
y.getCodMsgr().equalsIgnoreCase(x.getCodMsgr()))
|
||||||
|
.collect(Collectors.toList())));
|
||||||
|
|
||||||
|
allMsfamData.stream()
|
||||||
|
.map(x -> (MtbSfam) x)
|
||||||
|
.filter(x -> allMsgrpData.stream()
|
||||||
|
.map(y -> (MtbSgrp) y)
|
||||||
|
.noneMatch(y -> x.getCodMgrp().equalsIgnoreCase(y.getCodMgrp()) &&
|
||||||
|
x.getCodMsgr().equalsIgnoreCase(y.getCodMsgr())))
|
||||||
.forEach(x -> {
|
.forEach(x -> {
|
||||||
|
MtbSgrp testata = new MtbSgrp()
|
||||||
|
.setCodMgrp(x.getCodMgrp())
|
||||||
|
.setCodMsgr(x.getCodMsgr());
|
||||||
|
|
||||||
if (x.getOperation() == OperationType.INSERT)
|
testata.setOperation(OperationType.UPDATE);
|
||||||
x.setOperation(OperationType.INSERT_OR_UPDATE);
|
allMsgrpData.add(testata);
|
||||||
|
|
||||||
x.getMtbSgrp()
|
|
||||||
.forEach(y -> {
|
|
||||||
|
|
||||||
if (y.getOperation() == OperationType.INSERT)
|
|
||||||
y.setOperation(OperationType.INSERT_OR_UPDATE);
|
|
||||||
|
|
||||||
y.getMtbSfam().stream()
|
|
||||||
.filter(z -> z.getOperation() == OperationType.INSERT)
|
|
||||||
.forEach(z -> z.setOperation(OperationType.INSERT_OR_UPDATE));
|
|
||||||
|
|
||||||
y.setOperation(OperationType.INSERT_OR_UPDATE);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
allMgrpData.stream()
|
||||||
|
.map(x -> (MtbGrup) x)
|
||||||
|
.forEach(x -> x.setMtbSgrp(allMsgrpData.stream()
|
||||||
|
.map(y -> (MtbSgrp) y)
|
||||||
|
.filter(y -> y.getCodMgrp().equalsIgnoreCase(x.getCodMgrp()))
|
||||||
|
.collect(Collectors.toList())));
|
||||||
|
|
||||||
|
allMsgrpData.stream()
|
||||||
|
.map(x -> (MtbSgrp) x)
|
||||||
|
.filter(x -> allMgrpData.stream()
|
||||||
|
.map(y -> (MtbGrup) y)
|
||||||
|
.noneMatch(y -> x.getCodMgrp().equalsIgnoreCase(y.getCodMgrp())))
|
||||||
|
.forEach(x -> {
|
||||||
|
MtbGrup testata = new MtbGrup()
|
||||||
|
.setCodMgrp(x.getCodMgrp());
|
||||||
|
|
||||||
|
testata.setOperation(OperationType.UPDATE);
|
||||||
|
allMgrpData.add(testata);
|
||||||
|
});
|
||||||
|
|
||||||
|
// allData.stream()
|
||||||
|
// .map(x -> (MtbGrup) x)
|
||||||
|
// .forEach(x -> {
|
||||||
|
//
|
||||||
|
// if (x.getOperation() == OperationType.INSERT)
|
||||||
|
// x.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
|
//
|
||||||
|
// x.getMtbSgrp()
|
||||||
|
// .forEach(y -> {
|
||||||
|
//
|
||||||
|
// if (y.getOperation() == OperationType.INSERT)
|
||||||
|
// y.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
|
//
|
||||||
|
// y.getMtbSfam().stream()
|
||||||
|
// .filter(z -> z.getOperation() == OperationType.INSERT)
|
||||||
|
// .forEach(z -> z.setOperation(OperationType.INSERT_OR_UPDATE));
|
||||||
|
//
|
||||||
|
// y.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
final Exception[] firstExceptionToThrow = {null};
|
||||||
|
|
||||||
AtomicInteger importedCounter = new AtomicInteger();
|
AtomicInteger importedCounter = new AtomicInteger();
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
List<RunnableThrowable> calls = new ArrayList<>();
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : allData) {
|
for (EquatableEntityInterface dataToSave : allMgrpData) {
|
||||||
|
|
||||||
// calls.add(() -> {
|
// calls.add(() -> {
|
||||||
logger.debug("Importati {} gruppi merceologici di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importati {} gruppi merceologici di {}", importedCounter.incrementAndGet(), allMgrpData.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, multiDBTransactionManager);
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbGrup) dataToSave, useTempTable);
|
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbGrup) dataToSave, useTempTable);
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del gruppo merceologico", ex);
|
logger.error("Errore durante l'importazione del gruppo merceologico", ex);
|
||||||
multiDBTransactionManager.rollbackAll();
|
internalMultiDb.rollbackAll();
|
||||||
//throw ex;
|
//throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,49 +262,52 @@ public class ExchangeArticoliImportService {
|
|||||||
private List<MtbGrup> retrieveMtbGrup(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
private List<MtbGrup> retrieveMtbGrup(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||||
String mtbGrupOriginalTableName = "mtb_grup";
|
String mtbGrupOriginalTableName = "mtb_grup";
|
||||||
String mtbGrupTableName = mtbGrupOriginalTableName + (useTempTable ? "_tmp" : "");
|
String mtbGrupTableName = mtbGrupOriginalTableName + (useTempTable ? "_tmp" : "");
|
||||||
|
|
||||||
|
|
||||||
|
if (useTempTable) {
|
||||||
|
UtilityDB.executeStatement(connection,
|
||||||
|
"INSERT INTO " + mtbGrupTableName +
|
||||||
|
" SELECT * FROM " + mtbGrupOriginalTableName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbGrup.class,
|
||||||
|
mtbGrupTableName, null, retrieveAlreadyImported);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MtbSgrp> retrieveMtbSgrup(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||||
String mtbSgrpOriginalTableName = "mtb_sgrp";
|
String mtbSgrpOriginalTableName = "mtb_sgrp";
|
||||||
String mtbSgrpTableName = mtbSgrpOriginalTableName + (useTempTable ? "_tmp" : "");
|
String mtbSgrpTableName = mtbSgrpOriginalTableName + (useTempTable ? "_tmp" : "");
|
||||||
|
|
||||||
|
|
||||||
|
if (useTempTable) {
|
||||||
|
UtilityDB.executeStatement(connection,
|
||||||
|
"INSERT INTO " + mtbSgrpTableName +
|
||||||
|
" SELECT * FROM " + mtbSgrpOriginalTableName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSgrp.class,
|
||||||
|
mtbSgrpTableName, null, retrieveAlreadyImported);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MtbSfam> retrieveMtbSfam(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||||
String mtbSfamOriginalTableName = "mtb_sfam";
|
String mtbSfamOriginalTableName = "mtb_sfam";
|
||||||
String mtbSfamTableName = mtbSfamOriginalTableName + (useTempTable ? "_tmp" : "");
|
String mtbSfamTableName = mtbSfamOriginalTableName + (useTempTable ? "_tmp" : "");
|
||||||
|
|
||||||
|
|
||||||
if (useTempTable) {
|
if (useTempTable) {
|
||||||
UtilityDB.executeStatement(connection,
|
UtilityDB.executeStatement(connection,
|
||||||
"INSERT INTO " + mtbGrupTableName +
|
|
||||||
" SELECT * FROM " + mtbGrupOriginalTableName,
|
|
||||||
"INSERT INTO " + mtbSgrpTableName +
|
|
||||||
" SELECT * FROM " + mtbSgrpOriginalTableName,
|
|
||||||
"INSERT INTO " + mtbSfamTableName +
|
"INSERT INTO " + mtbSfamTableName +
|
||||||
" SELECT * FROM " + mtbSfamOriginalTableName
|
" SELECT * FROM " + mtbSfamOriginalTableName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MtbGrup> mtbGrups = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbGrup.class,
|
|
||||||
mtbGrupTableName, null, retrieveAlreadyImported);
|
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSfam.class,
|
||||||
List<MtbSgrp> mtbSgrps = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSgrp.class,
|
|
||||||
mtbSgrpTableName, null, retrieveAlreadyImported);
|
|
||||||
List<MtbSfam> mtbSfams = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSfam.class,
|
|
||||||
mtbSfamTableName, null, retrieveAlreadyImported);
|
mtbSfamTableName, null, retrieveAlreadyImported);
|
||||||
|
|
||||||
|
|
||||||
mtbSgrps.forEach(mtbSgrp -> {
|
|
||||||
|
|
||||||
mtbSgrp.setMtbSfam(mtbSfams.stream()
|
|
||||||
.filter(mtbSfam -> mtbSfam.getCodMgrp().equalsIgnoreCase(mtbSgrp.getCodMgrp()) &&
|
|
||||||
mtbSfam.getCodMsgr().equalsIgnoreCase(mtbSgrp.getCodMsgr()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
mtbGrups.forEach(mtbGrup -> {
|
|
||||||
|
|
||||||
mtbGrup.setMtbSgrp(mtbSgrps.stream()
|
|
||||||
.filter(mtbSgrp -> mtbSgrp.getCodMgrp().equalsIgnoreCase(mtbGrup.getCodMgrp()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return mtbGrups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package it.integry.ems.system.exchange.service;
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
import it.integry.ems.datasource.DataSource;
|
|
||||||
import it.integry.ems.expansion.RunnableThrowable;
|
import it.integry.ems.expansion.RunnableThrowable;
|
||||||
import it.integry.ems.service.EntityProcessor;
|
import it.integry.ems.service.EntityProcessor;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
@@ -12,16 +11,13 @@ import it.integry.ems_model.entity.MtbColt;
|
|||||||
import it.integry.ems_model.service.SetupGest;
|
import it.integry.ems_model.service.SetupGest;
|
||||||
import it.integry.ems_model.utility.Query;
|
import it.integry.ems_model.utility.Query;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
|
import it.integry.ems_model.utility.UtilityList;
|
||||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||||
import it.integry.ems_model.utility.UtilityQuery;
|
|
||||||
import it.integry.ems_model.utility.*;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -32,18 +28,14 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class ExchangeColliImportService {
|
public class ExchangeColliImportService {
|
||||||
|
|
||||||
//TODO: To be remove, only for fast development
|
|
||||||
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityProcessor entityProcessor;
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||||
|
|
||||||
@@ -53,78 +45,74 @@ public class ExchangeColliImportService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
|
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SetupGest setupGest;
|
private SetupGest setupGest;
|
||||||
|
|
||||||
public void importColliLavorazione() throws Exception {
|
public void importColliLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
|
||||||
|
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
|
||||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
try {
|
||||||
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione, useTempTable);
|
||||||
|
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
|
||||||
|
|
||||||
try {
|
final List<MtbColt> exchangeImportedMtbColts = importColliLavorazione(
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione, useTempTable);
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
|
UtilityLocalDate.getNow(),
|
||||||
|
true, false);
|
||||||
|
|
||||||
final List<MtbColt> exchangeImportedMtbColts = importColliLavorazione(
|
List<MtbColt> exchangeUpdatedMtbColts = importColliLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
true, false);
|
false, useTempTable);
|
||||||
|
|
||||||
List<MtbColt> exchangeUpdatedMtbColts = importColliLavorazione(
|
|
||||||
exchangeDb.getPrimaryConnection(),
|
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
|
||||||
UtilityLocalDate.getNow(),
|
|
||||||
false, useTempTable);
|
|
||||||
|
|
||||||
|
|
||||||
List<EquatableEntityInterface> importedMtbColts = exchangeImportedMtbColts.stream()
|
List<EquatableEntityInterface> importedMtbColts = exchangeImportedMtbColts.stream()
|
||||||
.map(x -> (EquatableEntityInterface) x)
|
.map(x -> (EquatableEntityInterface) x)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<EquatableEntityInterface> updatedMtbColts = exchangeUpdatedMtbColts.stream()
|
List<EquatableEntityInterface> updatedMtbColts = exchangeUpdatedMtbColts.stream()
|
||||||
.map(x -> (EquatableEntityInterface) x)
|
.map(x -> (EquatableEntityInterface) x)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<EquatableEntityInterface> allMtbColts = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allMtbColts = exchangeImportDataManagerService
|
||||||
.runSync(MtbColt.class, importedMtbColts, updatedMtbColts);
|
.runSync(MtbColt.class, importedMtbColts, updatedMtbColts);
|
||||||
|
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
final Exception[] firstExceptionToThrow = {null};
|
||||||
|
|
||||||
AtomicInteger importedCounter = new AtomicInteger();
|
AtomicInteger importedCounter = new AtomicInteger();
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
List<RunnableThrowable> calls = new ArrayList<>();
|
||||||
|
|
||||||
for (EquatableEntityInterface mtbColtToSave : allMtbColts) {
|
for (EquatableEntityInterface mtbColtToSave : allMtbColts) {
|
||||||
|
|
||||||
// calls.add(() -> {
|
// calls.add(() -> {
|
||||||
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allMtbColts.size());
|
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allMtbColts.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(mtbColtToSave, multiDBTransactionManager);
|
entityProcessor.processEntity(mtbColtToSave, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbColt) mtbColtToSave, useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (MtbColt) mtbColtToSave, useTempTable);
|
||||||
|
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del collo", ex);
|
logger.error("Errore durante l'importazione del collo", ex);
|
||||||
//multiDBTransactionManager.rollbackAll();
|
//multiDBTransactionManager.rollbackAll();
|
||||||
//throw ex;
|
//throw ex;
|
||||||
}
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
// });
|
||||||
|
}
|
||||||
// UtilityThread.executeParallel(calls);
|
// UtilityThread.executeParallel(calls);
|
||||||
|
|
||||||
|
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,65 +176,66 @@ public class ExchangeColliImportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<CertificatiSinfoOneDTO> getCertificati(String codAnag, LocalDate dataCert, String codMart, String codVdes) throws Exception {
|
public List<CertificatiSinfoOneDTO> getCertificati(String profileDb, String codAnag, LocalDate dataCert, String codMart, String codVdes) throws Exception {
|
||||||
String profileDbExchange = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "PVM", "PIAN_ACC_ROSSG", "PROFILE_DB_CERT");
|
|
||||||
|
|
||||||
|
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(profileDb)) {
|
||||||
|
|
||||||
DataSource dsSync = new DataSource();
|
String profileDbExchange = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "PVM", "PIAN_ACC_ROSSG", "PROFILE_DB_CERT");
|
||||||
dsSync.initialize(profileDbExchange);
|
|
||||||
multiDBTransactionManager.addConnection(profileDbExchange, dsSync);
|
|
||||||
Connection conExch = multiDBTransactionManager.getDatabaseDataSource(profileDbExchange).getConnection();
|
|
||||||
|
|
||||||
List<CertificatiSinfoOneDTO> listaCert = UtilityDB.executeSimpleQueryDTO(
|
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
|
||||||
conExch,
|
|
||||||
Query.format("SELECT TRIM(cod_anag) AS codAnag,\n" +
|
|
||||||
" TRIM(rag_soc) AS ragSoc,\n" +
|
|
||||||
" TRIM(cod_Vdes) AS codVdes,\n" +
|
|
||||||
" data_cert AS dataCert,\n" +
|
|
||||||
" CONVERT(NUMERIC(10, 0), num_cert) AS numCert,\n" +
|
|
||||||
" data_bolla AS dataBolla,\n" +
|
|
||||||
" TRIM(num_bolla) AS numBolla,\n" +
|
|
||||||
" TRIM(PMB_TIPO_POMODORO) AS codMart,\n" +
|
|
||||||
" TRIM(PMB_SEME) AS varieta,\n" +
|
|
||||||
" TRIM(lotto_fornitore) AS lottoFornitore,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), peso_lordo_kg) AS pesoLordoKg,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), peso_netto_kg) AS pesoNettoKg,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), scarto_kg) AS scartoKg,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), val_unt) AS valUnt,\n" +
|
|
||||||
" CONVERT(NUMERIC(10, 0), casse_scaricate) AS casseScaricate,\n" +
|
|
||||||
" CONVERT(NUMERIC(10, 0), casse_rese) AS casseRese,\n" +
|
|
||||||
" TRIM(targa_motrice) AS targaMotrice,\n" +
|
|
||||||
" TRIM(targa_rimorchio) AS targaRimorchio,\n" +
|
|
||||||
" TRIM(tagliando_pesa) AS tagliandoPesa,\n" +
|
|
||||||
" data_ora_lordo AS dataOraLordo,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), sconto8) AS sconto8,\n" +
|
|
||||||
" cod_vettore AS cod_vvet,\n" +
|
|
||||||
" vettore AS vettore,\n" +
|
|
||||||
" CONVERT(NUMERIC(15, 3), PMB_SCARTO_CQ) AS scartoCq\n " +
|
|
||||||
"FROM s1_Certificati\n" +
|
|
||||||
"WHERE cod_anag = {}\n" +
|
|
||||||
" AND data_cert = {}\n" +
|
|
||||||
" AND PMB_TIPO_POMODORO = {}", codAnag, dataCert, codMart),
|
|
||||||
CertificatiSinfoOneDTO.class);
|
|
||||||
String codDtipLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
|
||||||
"SETUP",
|
|
||||||
"COD_DTIP_CAR");
|
|
||||||
|
|
||||||
List<DtbDoct> certificatiImportati = UtilityDB.executeSimpleQueryDTO(
|
List<CertificatiSinfoOneDTO> listaCert = UtilityDB.executeSimpleQueryDTO(
|
||||||
multiDBTransactionManager.getPrimaryConnection(),
|
exchangeDb.getPrimaryConnection(),
|
||||||
Query.format("SELECT data_doc,num_doc,ser_doc,cod_dtip,cod_anag \n" +
|
Query.format("SELECT TRIM(cod_anag) AS codAnag,\n" +
|
||||||
"from dtb_doct \n" +
|
" TRIM(rag_soc) AS ragSoc,\n" +
|
||||||
" WHERE " +
|
" TRIM(cod_Vdes) AS codVdes,\n" +
|
||||||
" cod_dtip = {}" +
|
" data_cert AS dataCert,\n" +
|
||||||
" AND cod_anag = {}\n" +
|
" CONVERT(NUMERIC(10, 0), num_cert) AS numCert,\n" +
|
||||||
" AND data_doc = {}\n", codDtipLavCar, codAnag, dataCert),
|
" data_bolla AS dataBolla,\n" +
|
||||||
DtbDoct.class);
|
" TRIM(num_bolla) AS numBolla,\n" +
|
||||||
if (!UtilityList.isNullOrEmpty(certificatiImportati) && ! UtilityList.isNullOrEmpty(listaCert)) {
|
" TRIM(PMB_TIPO_POMODORO) AS codMart,\n" +
|
||||||
listaCert = listaCert.stream().filter((CertificatiSinfoOneDTO cert) ->
|
" TRIM(PMB_SEME) AS varieta,\n" +
|
||||||
certificatiImportati.stream().noneMatch(ddt -> ddt.getNumDoc() == cert.getNumCert().intValue())
|
" TRIM(lotto_fornitore) AS lottoFornitore,\n" +
|
||||||
).collect(Collectors.toList());
|
" CONVERT(NUMERIC(15, 3), peso_lordo_kg) AS pesoLordoKg,\n" +
|
||||||
|
" CONVERT(NUMERIC(15, 3), peso_netto_kg) AS pesoNettoKg,\n" +
|
||||||
|
" CONVERT(NUMERIC(15, 3), scarto_kg) AS scartoKg,\n" +
|
||||||
|
" CONVERT(NUMERIC(15, 3), val_unt) AS valUnt,\n" +
|
||||||
|
" CONVERT(NUMERIC(10, 0), casse_scaricate) AS casseScaricate,\n" +
|
||||||
|
" CONVERT(NUMERIC(10, 0), casse_rese) AS casseRese,\n" +
|
||||||
|
" TRIM(targa_motrice) AS targaMotrice,\n" +
|
||||||
|
" TRIM(targa_rimorchio) AS targaRimorchio,\n" +
|
||||||
|
" TRIM(tagliando_pesa) AS tagliandoPesa,\n" +
|
||||||
|
" data_ora_lordo AS dataOraLordo,\n" +
|
||||||
|
" CONVERT(NUMERIC(15, 3), sconto8) AS sconto8,\n" +
|
||||||
|
" cod_vettore AS cod_vvet,\n" +
|
||||||
|
" vettore AS vettore,\n" +
|
||||||
|
" CONVERT(NUMERIC(15, 3), PMB_SCARTO_CQ) AS scartoCq\n " +
|
||||||
|
"FROM s1_Certificati\n" +
|
||||||
|
"WHERE cod_anag = {}\n" +
|
||||||
|
" AND data_cert = {}\n" +
|
||||||
|
" AND PMB_TIPO_POMODORO = {}", codAnag, dataCert, codMart),
|
||||||
|
CertificatiSinfoOneDTO.class);
|
||||||
|
String codDtipLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
||||||
|
"SETUP",
|
||||||
|
"COD_DTIP_CAR");
|
||||||
|
|
||||||
|
List<DtbDoct> certificatiImportati = UtilityDB.executeSimpleQueryDTO(
|
||||||
|
multiDBTransactionManager.getPrimaryConnection(),
|
||||||
|
Query.format("SELECT data_doc,num_doc,ser_doc,cod_dtip,cod_anag \n" +
|
||||||
|
"from dtb_doct \n" +
|
||||||
|
" WHERE " +
|
||||||
|
" cod_dtip = {}" +
|
||||||
|
" AND cod_anag = {}\n" +
|
||||||
|
" AND data_doc = {}\n", codDtipLavCar, codAnag, dataCert),
|
||||||
|
DtbDoct.class);
|
||||||
|
if (!UtilityList.isNullOrEmpty(certificatiImportati) && !UtilityList.isNullOrEmpty(listaCert)) {
|
||||||
|
listaCert = listaCert.stream().filter((CertificatiSinfoOneDTO cert) ->
|
||||||
|
certificatiImportati.stream().noneMatch(ddt -> ddt.getNumDoc() == cert.getNumCert().intValue())
|
||||||
|
).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaCert;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return listaCert;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
|
import it.integry.ems.service.EntityProcessor;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems_model.entity.StbExchangeConfig;
|
||||||
|
import it.integry.ems_model.entity.StbExchangeConfigDetail;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Scope(value = "request")
|
||||||
|
public class ExchangeConfigService {
|
||||||
|
|
||||||
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MultiDBTransactionManager multiDBTransactionManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
|
public List<StbExchangeConfig> retrieveConfigurations() throws Exception {
|
||||||
|
|
||||||
|
List<StbExchangeConfig> stbExchangeConfigsToRetrieve = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||||
|
"SELECT * FROM " + StbExchangeConfig.ENTITY, StbExchangeConfig.class);
|
||||||
|
if (stbExchangeConfigsToRetrieve == null) return null;
|
||||||
|
|
||||||
|
List<StbExchangeConfigDetail> stbExchangeConfigsDetailsToRetrieve = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),
|
||||||
|
"SELECT * FROM " + StbExchangeConfigDetail.ENTITY, StbExchangeConfigDetail.class);
|
||||||
|
if (stbExchangeConfigsDetailsToRetrieve == null) stbExchangeConfigsDetailsToRetrieve = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
for (StbExchangeConfig stbExchangeConfig : stbExchangeConfigsToRetrieve) {
|
||||||
|
stbExchangeConfig.getStbExchangeConfigDetail()
|
||||||
|
.addAll(stbExchangeConfigsDetailsToRetrieve.stream()
|
||||||
|
.filter(x -> Objects.equals(x.getStbExchangeConfigId(), stbExchangeConfig.getId()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stbExchangeConfigsToRetrieve;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConfiguration(StbExchangeConfig stbExchangeConfig) throws Exception {
|
||||||
|
stbExchangeConfig.setOperation(OperationType.INSERT);
|
||||||
|
entityProcessor.processEntity(stbExchangeConfig, multiDBTransactionManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void deleteConfiguration(long idToDelete) throws Exception {
|
||||||
|
StbExchangeConfig stbExchangeConfigToDelete = new StbExchangeConfig()
|
||||||
|
.setId(idToDelete);
|
||||||
|
stbExchangeConfigToDelete.setOperation(OperationType.DELETE);
|
||||||
|
|
||||||
|
entityProcessor.processEntity(stbExchangeConfigToDelete, multiDBTransactionManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -27,19 +26,14 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class ExchangeDocumentImportService {
|
public class ExchangeDocumentImportService {
|
||||||
|
|
||||||
//TODO: To be remove, only for fast development
|
//TODO: To be remove, only for fast development
|
||||||
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
|
|
||||||
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
|
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityProcessor entityProcessor;
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||||
|
|
||||||
@@ -51,120 +45,118 @@ public class ExchangeDocumentImportService {
|
|||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public void importTestateDocumentiLavorazione() throws Exception {
|
public void importTestateDocumentiLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
|
||||||
|
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
|
||||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione, useTempTable);
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione, useTempTable);
|
||||||
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
|
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
|
||||||
|
|
||||||
|
|
||||||
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
|
|
||||||
final List<DtbDocr> exchangeImportedRigheData = importRigheDocumentiLavorazione(
|
final List<DtbDocr> exchangeImportedRigheData = importRigheDocumentiLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbDocr> exchangeUpdatedRigheData = importRigheDocumentiLavorazione(
|
final List<DtbDocr> exchangeUpdatedRigheData = importRigheDocumentiLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allTestateData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allTestateData = exchangeImportDataManagerService
|
||||||
.runSync(DtbDoct.class, exchangeImportedTestateData, exchangeUpdatedTestateData);
|
.runSync(DtbDoct.class, exchangeImportedTestateData, exchangeUpdatedTestateData);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allRigheData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allRigheData = exchangeImportDataManagerService
|
||||||
.runSync(DtbDocr.class, exchangeImportedRigheData, exchangeUpdatedRigheData);
|
.runSync(DtbDocr.class, exchangeImportedRigheData, exchangeUpdatedRigheData);
|
||||||
|
|
||||||
|
|
||||||
allTestateData.stream()
|
allTestateData.stream()
|
||||||
.map(x -> (DtbDoct) x)
|
.map(x -> (DtbDoct) x)
|
||||||
.forEach(x ->
|
.forEach(x ->
|
||||||
x.setDtbDocr(allRigheData.stream()
|
x.setDtbDocr(allRigheData.stream()
|
||||||
.map(y -> (DtbDocr) y)
|
.map(y -> (DtbDocr) y)
|
||||||
.filter(y -> y.getDataDoc().equals(x.getDataDoc()) &&
|
.filter(y -> y.getDataDoc().equals(x.getDataDoc()) &&
|
||||||
y.getNumDoc().equals(x.getNumDoc()) &&
|
y.getNumDoc().equals(x.getNumDoc()) &&
|
||||||
y.getSerDoc().equalsIgnoreCase(x.getSerDoc()) &&
|
y.getSerDoc().equalsIgnoreCase(x.getSerDoc()) &&
|
||||||
y.getCodAnag().equalsIgnoreCase(x.getCodAnag()) &&
|
y.getCodAnag().equalsIgnoreCase(x.getCodAnag()) &&
|
||||||
y.getCodDtip().equalsIgnoreCase(x.getCodDtip()))
|
y.getCodDtip().equalsIgnoreCase(x.getCodDtip()))
|
||||||
.collect(Collectors.toList())));
|
.collect(Collectors.toList())));
|
||||||
|
|
||||||
allRigheData.stream()
|
allRigheData.stream()
|
||||||
.map(x -> (DtbDocr) x)
|
.map(x -> (DtbDocr) x)
|
||||||
.filter(x -> allTestateData.stream()
|
.filter(x -> allTestateData.stream()
|
||||||
.map(y -> (DtbDoct) y)
|
.map(y -> (DtbDoct) y)
|
||||||
.noneMatch(y -> x.getCodDtip().equalsIgnoreCase(y.getCodDtip()) &&
|
.noneMatch(y -> x.getCodDtip().equalsIgnoreCase(y.getCodDtip()) &&
|
||||||
x.getDataDoc().equals(y.getDataDoc()) &&
|
x.getDataDoc().equals(y.getDataDoc()) &&
|
||||||
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
||||||
x.getCodAnag().equalsIgnoreCase(y.getCodAnag()) &&
|
x.getCodAnag().equalsIgnoreCase(y.getCodAnag()) &&
|
||||||
x.getSerDoc().equalsIgnoreCase(y.getSerDoc())))
|
x.getSerDoc().equalsIgnoreCase(y.getSerDoc())))
|
||||||
.forEach(x -> {
|
.forEach(x -> {
|
||||||
DtbDoct testata = new DtbDoct()
|
DtbDoct testata = new DtbDoct()
|
||||||
.setSerDoc(x.getSerDoc())
|
.setSerDoc(x.getSerDoc())
|
||||||
.setDataDoc(x.getDataDoc())
|
.setDataDoc(x.getDataDoc())
|
||||||
.setNumDoc(x.getNumDoc())
|
.setNumDoc(x.getNumDoc())
|
||||||
.setCodDtip(x.getCodDtip())
|
.setCodDtip(x.getCodDtip())
|
||||||
.setCodAnag(x.getCodAnag());
|
.setCodAnag(x.getCodAnag());
|
||||||
|
|
||||||
testata.setOperation(OperationType.UPDATE);
|
testata.setOperation(OperationType.UPDATE);
|
||||||
allTestateData.add(testata);
|
allTestateData.add(testata);
|
||||||
});
|
});
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = allTestateData;
|
List<EquatableEntityInterface> allData = allTestateData;
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
final Exception[] firstExceptionToThrow = {null};
|
||||||
|
|
||||||
AtomicInteger importedCounter = new AtomicInteger();
|
AtomicInteger importedCounter = new AtomicInteger();
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
List<RunnableThrowable> calls = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : allData) {
|
for (EquatableEntityInterface dataToSave : allData) {
|
||||||
|
|
||||||
// calls.add(() -> {
|
// calls.add(() -> {
|
||||||
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allData.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, multiDBTransactionManager);
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (DtbDoct) dataToSave, useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbDoct) dataToSave, useTempTable);
|
||||||
//multiDBTransactionManager.commitAll();
|
//multiDBTransactionManager.commitAll();
|
||||||
|
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del documento", ex);
|
logger.error("Errore durante l'importazione del documento", ex);
|
||||||
//multiDBTransactionManager.rollbackAll();
|
//multiDBTransactionManager.rollbackAll();
|
||||||
//throw ex;
|
//throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
// UtilityThread.executeParallel(calls);
|
// UtilityThread.executeParallel(calls);
|
||||||
|
|
||||||
|
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package it.integry.ems.system.exchange.service;
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import it.integry.ems.entity_logger.db_schema_manager.component.SQLServerDBSchemaManager;
|
import it.integry.ems.entity_logger.db_schema_manager.component.SQLServerDBSchemaManager;
|
||||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTable;
|
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTable;
|
||||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTableColumn;
|
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTableColumn;
|
||||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTableView;
|
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseTableView;
|
||||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseView;
|
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseView;
|
||||||
|
import it.integry.ems_model.entity._enum.IBaseEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -18,14 +20,45 @@ import java.util.stream.Collectors;
|
|||||||
public class ExchangeImportSchemaManagerService {
|
public class ExchangeImportSchemaManagerService {
|
||||||
|
|
||||||
|
|
||||||
public enum SchemaType {
|
public enum SchemaType implements IBaseEnum {
|
||||||
ColliLavorazione,
|
ColliLavorazione(1),
|
||||||
OrdiniLavorazione,
|
OrdiniLavorazione(2),
|
||||||
DocumentiLavorazione,
|
DocumentiLavorazione(3),
|
||||||
Articoli,
|
Articoli(4),
|
||||||
PartiteMagazzinoLavorazione
|
PartiteMagazzinoLavorazione(5);
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
SchemaType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SchemaType from(Object value) {
|
||||||
|
int castValue = (int) value;
|
||||||
|
for (SchemaType b : SchemaType.values()) {
|
||||||
|
if (b.value == castValue)
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public int getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object get() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object fromInternal(Object val) {
|
||||||
|
return from(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final HashMap<SchemaType, List<String>> schemaToTableBinding = new HashMap<SchemaType, List<String>>() {{
|
private final HashMap<SchemaType, List<String>> schemaToTableBinding = new HashMap<SchemaType, List<String>>() {{
|
||||||
put(SchemaType.ColliLavorazione, Arrays.asList("mtb_colt_lav", "mtb_colr_lav"));
|
put(SchemaType.ColliLavorazione, Arrays.asList("mtb_colt_lav", "mtb_colr_lav"));
|
||||||
put(SchemaType.OrdiniLavorazione, Arrays.asList("dtb_ordt_lav", "dtb_ordr_lav"));
|
put(SchemaType.OrdiniLavorazione, Arrays.asList("dtb_ordt_lav", "dtb_ordr_lav"));
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -28,20 +27,13 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class ExchangeOrdiniImportService {
|
public class ExchangeOrdiniImportService {
|
||||||
|
|
||||||
//TODO: To be remove, only for fast development
|
|
||||||
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
|
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityProcessor entityProcessor;
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||||
|
|
||||||
@@ -51,90 +43,88 @@ public class ExchangeOrdiniImportService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
|
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
|
||||||
|
|
||||||
public void importOrdiniLavorazione() throws Exception {
|
public void importOrdiniLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
|
||||||
|
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
|
||||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione, useTempTable);
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione, useTempTable);
|
||||||
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
|
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusWeeks(1),
|
UtilityLocalDate.getNow().minusWeeks(1),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||||
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
||||||
|
|
||||||
allData.stream()
|
allData.stream()
|
||||||
.map(x -> (DtbOrdt) x)
|
.map(x -> (DtbOrdt) x)
|
||||||
.filter(x -> x.getGestione().equalsIgnoreCase("L") &&
|
.filter(x -> x.getGestione().equalsIgnoreCase("L") &&
|
||||||
(x.getOperation() == OperationType.INSERT_OR_UPDATE || x.getOperation() == OperationType.INSERT))
|
(x.getOperation() == OperationType.INSERT_OR_UPDATE || x.getOperation() == OperationType.INSERT))
|
||||||
.forEach(x -> {
|
.forEach(x -> {
|
||||||
DtbOrdSteps ordStep =
|
DtbOrdSteps ordStep =
|
||||||
new DtbOrdSteps()
|
new DtbOrdSteps()
|
||||||
.setIdRiga(0)
|
.setIdRiga(0)
|
||||||
.setCodJfas(x.getCodJfas())
|
.setCodJfas(x.getCodJfas())
|
||||||
.setQtaProd(x.getQtaProd());
|
.setQtaProd(x.getQtaProd());
|
||||||
|
|
||||||
ordStep.setOperation(OperationType.INSERT_OR_UPDATE);
|
ordStep.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
x.getDtbOrdSteps().add(ordStep);
|
x.getDtbOrdSteps().add(ordStep);
|
||||||
});
|
});
|
||||||
|
|
||||||
List<List<EquatableEntityInterface>> splittedOrders =
|
List<List<EquatableEntityInterface>> splittedOrders =
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
allData.stream().filter(x -> ((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList()),
|
allData.stream().filter(x -> ((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList()),
|
||||||
allData.stream().filter(x -> !((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList())
|
allData.stream().filter(x -> !((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
final Exception[] firstExceptionToThrow = {null};
|
||||||
|
|
||||||
final AtomicInteger[] importedCounter = {new AtomicInteger()};
|
final AtomicInteger[] importedCounter = {new AtomicInteger()};
|
||||||
|
|
||||||
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
List<RunnableThrowable> calls = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
for (EquatableEntityInterface dtbOrdtToSave : listToProcess) {
|
for (EquatableEntityInterface dtbOrdtToSave : listToProcess) {
|
||||||
//calls.add(() -> {
|
//calls.add(() -> {
|
||||||
|
|
||||||
logger.debug("Importati {} di {}", importedCounter[0].incrementAndGet(), allData.size());
|
logger.debug("Importati {} di {}", importedCounter[0].incrementAndGet(), allData.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dtbOrdtToSave, multiDBTransactionManager);
|
entityProcessor.processEntity(dtbOrdtToSave, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (DtbOrdt) dtbOrdtToSave, useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbOrdt) dtbOrdtToSave, useTempTable);
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione dell'ordine", ex);
|
|
||||||
multiDBTransactionManager.rollbackAll();
|
|
||||||
//throw ex;
|
|
||||||
}
|
|
||||||
//});
|
|
||||||
|
|
||||||
|
logger.error("Errore durante l'importazione dell'ordine", ex);
|
||||||
|
internalMultiDb.rollbackAll();
|
||||||
|
//throw ex;
|
||||||
}
|
}
|
||||||
|
//});
|
||||||
|
|
||||||
|
|
||||||
//UtilityThread.executeParallel(calls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
|
||||||
} finally {
|
//UtilityThread.executeParallel(calls);
|
||||||
if (useTempTable)
|
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||||
|
} finally {
|
||||||
|
if (useTempTable)
|
||||||
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -24,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Service
|
@Service
|
||||||
@Scope("request")
|
|
||||||
public class ExchangePartiteMagazzinoImportService {
|
public class ExchangePartiteMagazzinoImportService {
|
||||||
|
|
||||||
//TODO: To be remove, only for fast development
|
//TODO: To be remove, only for fast development
|
||||||
@@ -35,9 +33,6 @@ public class ExchangePartiteMagazzinoImportService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EntityProcessor entityProcessor;
|
private EntityProcessor entityProcessor;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MultiDBTransactionManager multiDBTransactionManager;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||||
|
|
||||||
@@ -46,22 +41,21 @@ public class ExchangePartiteMagazzinoImportService {
|
|||||||
|
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public void importPartiteMagazzinoLavorazione() throws Exception {
|
public void importPartiteMagazzinoLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
|
||||||
|
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
|
||||||
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
|
|
||||||
try {
|
try {
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione, useTempTable);
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione, useTempTable);
|
||||||
|
|
||||||
final List<MtbPartitaMag> exchangeImportedData = retrievePartite(
|
final List<MtbPartitaMag> exchangeImportedData = retrievePartite(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(3),
|
UtilityLocalDate.getNow().minusMonths(3),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<MtbPartitaMag> exchangeUpdatedData = retrievePartite(
|
final List<MtbPartitaMag> exchangeUpdatedData = retrievePartite(
|
||||||
exchangeDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(3),
|
UtilityLocalDate.getNow().minusMonths(3),
|
||||||
UtilityLocalDate.getNow(),
|
UtilityLocalDate.getNow(),
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
@@ -83,13 +77,13 @@ public class ExchangePartiteMagazzinoImportService {
|
|||||||
// calls.add(() -> {
|
// calls.add(() -> {
|
||||||
logger.debug("Importate {} partite di magazzino di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importate {} partite di magazzino di {}", importedCounter.incrementAndGet(), allData.size());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, multiDBTransactionManager);
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb);
|
||||||
|
|
||||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbPartitaMag) dataToSave, useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (MtbPartitaMag) dataToSave, useTempTable);
|
||||||
//multiDBTransactionManager.commitAll();
|
//multiDBTransactionManager.commitAll();
|
||||||
|
|
||||||
multiDBTransactionManager.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||||
@@ -107,9 +101,8 @@ public class ExchangePartiteMagazzinoImportService {
|
|||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
|
import it.integry.annotations.PostContextAutowired;
|
||||||
|
import it.integry.annotations.PostContextConstruct;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems_model.entity.StbExchangeConfig;
|
||||||
|
import it.integry.ems_model.entity.StbExchangeConfigDetail;
|
||||||
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.scheduling.support.CronTrigger;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ExchangeSystemManagerService {
|
||||||
|
|
||||||
|
|
||||||
|
@PostContextAutowired
|
||||||
|
private MultiDBTransactionManager multiDBTransactionManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskScheduler taskScheduler;
|
||||||
|
|
||||||
|
private final HashMap<Long, ScheduledFuture<?>> scheduledOperations = new HashMap<>();
|
||||||
|
|
||||||
|
@PostContextConstruct(priority = 20)
|
||||||
|
public void init() throws Exception {
|
||||||
|
|
||||||
|
for (AdvancedDataSource db : multiDBTransactionManager.getActiveConnections()) {
|
||||||
|
|
||||||
|
String query = "SELECT cast(Count(*) as bit) existTable FROM sys.objects WHERE object_id = OBJECT_ID(N'" + StbExchangeConfig.ENTITY + "') AND type in (N'U')";
|
||||||
|
boolean existTable = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(db.getConnection(), query);
|
||||||
|
|
||||||
|
if (!existTable) continue;
|
||||||
|
|
||||||
|
List<StbExchangeConfig> stbExchangeConfigsToRetrieve = UtilityDB.executeSimpleQueryDTO(db.getConnection(),
|
||||||
|
"SELECT * FROM " + StbExchangeConfig.ENTITY, StbExchangeConfig.class);
|
||||||
|
if (stbExchangeConfigsToRetrieve == null) continue;
|
||||||
|
|
||||||
|
for (StbExchangeConfig stbExchangeConfig : stbExchangeConfigsToRetrieve) {
|
||||||
|
registerSchedulation(stbExchangeConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerSchedulation(StbExchangeConfig stbExchangeConfig) {
|
||||||
|
if (scheduledOperations.containsKey(stbExchangeConfig.getId())) {
|
||||||
|
scheduledOperations.get(stbExchangeConfig.getId()).cancel(false);
|
||||||
|
scheduledOperations.remove(stbExchangeConfig.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
CronTrigger cronTrigger = new CronTrigger(stbExchangeConfig.getSchedulationCron());
|
||||||
|
|
||||||
|
ScheduledFuture<?> future =
|
||||||
|
taskScheduler.schedule(() -> executeExchange(stbExchangeConfig), cronTrigger);
|
||||||
|
|
||||||
|
scheduledOperations.put(stbExchangeConfig.getId(), future);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeExchange(StbExchangeConfig stbExchangeConfig) {
|
||||||
|
|
||||||
|
|
||||||
|
for (StbExchangeConfigDetail stbExchangeConfigDetail : stbExchangeConfig.getStbExchangeConfigDetail()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user