Implementata gestione pianificazioni exchange

This commit is contained in:
2024-07-17 10:21:48 +02:00
parent 9ba1078d5a
commit 8397e7c6aa
23 changed files with 1016 additions and 457 deletions

View File

@@ -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 {
}
}

View File

@@ -32,8 +32,8 @@ public class ScheduledOperationHandlerComponent {
private final Logger logger = LogManager.getLogger();
private HashMap<String, ScheduledFuture<?>> scheduledOperations = new HashMap<>();
private HashMap<String, DirectoryWatcher> directoryWatcherOperations = new HashMap<>();
private final HashMap<String, ScheduledFuture<?>> scheduledOperations = new HashMap<>();
private final HashMap<String, DirectoryWatcher> directoryWatcherOperations = new HashMap<>();
public void scheduleOperation(BaseAutomatedOperationDTO operationModel) throws Exception {

View File

@@ -10,7 +10,6 @@ import it.integry.ems.datasource.DataSource;
import it.integry.ems.dto.EntityPermissionsDTO;
import it.integry.ems.exception.InvalidPermissionsException;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.json.ResponseJSONObjectMapper;
import it.integry.ems.model.ColumnMetadataDTO;
import it.integry.ems.settings.Model.SettingsModel;
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
@@ -33,8 +32,8 @@ import org.apache.logging.log4j.Logger;
import org.josql.Query;
import org.josql.QueryResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;
import java.io.StringWriter;
import java.sql.*;
@@ -45,7 +44,6 @@ import java.util.HashMap;
import java.util.List;
@Service
@Scope("request")
public class EntityProcessor {
private final Logger logger = LogManager.getLogger();
@@ -59,18 +57,6 @@ public class EntityProcessor {
@Autowired
private EntityPropertyHolder entityPropertyHolder;
@Autowired
private ResponseJSONObjectMapper jsonObjectMapper;
@Autowired
private MultiDBTransactionManager mDbTransactManager;
@Autowired
private RequestDataDTO requestDataDTO;
@Autowired
private EntityLoggerService entityLoggerService;
@Autowired
private EntityLoggerNewService entityLoggerNewService;
@@ -78,6 +64,7 @@ public class EntityProcessor {
private SettingsModel settingsModel;
public <T> T processEntity(EntityInterface entity, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
String username = "";
@@ -85,31 +72,35 @@ public class EntityProcessor {
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 {
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
String username = "";
if (requestDataDTO != null && requestDataDTO.isValidUsername()) {
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,
boolean skipCommit, String username,
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,
boolean skipCommit, String username,
MultiDBTransactionManager mdb,
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,
boolean skipCommit, String username,
MultiDBTransactionManager mdb,
MultiDBTransactionManager mdb, RequestDataDTO requestDataDTO,
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
try {
@@ -139,13 +130,13 @@ public class EntityProcessor {
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();
if (entity.getOperation() == OperationType.NO_OP) {
processInternal(entity, isSync, mdb, completeEntity);
processInternal(entity, isSync, mdb, requestDataDTO, completeEntity);
} else if (entity.getOperation() == OperationType.SELECT_OBJECT) {
return entity.selectAndMergeEntity(mdb.getPrimaryConnection(), (EntityBase) entity);
//return entity;
@@ -155,7 +146,7 @@ public class EntityProcessor {
return entityList;
} else {
processInternal(entity, isSync, mdb, completeEntity);
processInternal(entity, isSync, mdb, requestDataDTO, completeEntity);
}
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());;
OperationType operationType = entityInterface.getOperation();
@@ -209,12 +200,12 @@ public class EntityProcessor {
}
}
private boolean checkUserPermissions(EntityInterface entity) throws Exception {
if (!UtilityUser.checkLocalUserExist(mDbTransactManager, entity.getUsername())) return true;
private boolean checkUserPermissions(EntityInterface entity, MultiDBTransactionManager multiDBTransactionManager) throws Exception {
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);
@@ -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();
Connection primaryDB = currentDs.getConnection();
String currentProfileDb = currentDs.getProfile();
@@ -415,6 +406,8 @@ public class EntityProcessor {
}
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);
}
@@ -423,10 +416,14 @@ public class EntityProcessor {
}
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);
}
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);
}
@@ -449,6 +446,9 @@ public class EntityProcessor {
MultiDBTransactionManager multiDBTransactionManager,
boolean completeEntity, boolean overrideEntityChildCheck) throws Exception {
final RequestDataDTO requestDataDTO = ContextLoader.getCurrentWebApplicationContext().getBean(RequestDataDTO.class);
if (UtilityString.isNullOrEmpty(username) && requestDataDTO != null && requestDataDTO.isValidUsername()) {
username = requestDataDTO.getUsername();
}
@@ -466,7 +466,7 @@ public class EntityProcessor {
EntityBase entity = entities.get(i);
entity.setTransactionGroupId(prevTransactionGroupId);
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();
if (entityResult != null) {
entityList.add(entityResult);
@@ -489,7 +489,7 @@ public class EntityProcessor {
}
}
mDbTransactManager.commitAll();
multiDBTransactionManager.commitAll();
return entityList;
}

View File

@@ -57,7 +57,7 @@ public class AsyncHistoryManager {
private final AtomicReference<List<ExportHistoryGroupDTO>> currentlyInExecutionG = new AtomicReference<>(new ArrayList<>());
@PostContextConstruct
@PostContextConstruct(priority = 20)
public void init() {
this.looperService.add(this::consumeRetrieveQueue, 10 * 1000, "async-history-read");
this.looperService.add(this::consumeProcessedQueue, 2 * 1000, "async-history-save");

View File

@@ -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))
.findFirst();

View File

@@ -29,10 +29,7 @@ import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.groupingBy;
@@ -79,7 +76,7 @@ public class RemoteSynchronizationSetupService {
publicationGroups.add(publicationGroupDTO);
final List<PublicationDTO> publications = stbPublicationsDetails.stream()
.filter(x -> x.getStbPublicationId() == stbPublication.getId())
.filter(x -> Objects.equals(x.getStbPublicationId(), stbPublication.getId()))
.map(PublicationDTO::fromStbPublicationDetail)
.collect(toList());
publicationGroupDTO.setPublications(publications);

View File

@@ -52,64 +52,72 @@ public class MtbGrup extends EntityBase implements EquatableEntityInterface<MtbG
return codMgrp;
}
public void setCodMgrp(String codMgrp) {
public MtbGrup setCodMgrp(String codMgrp) {
this.codMgrp = codMgrp;
return this;
}
public String getDescrizione() {
return descrizione;
}
public void setDescrizione(String descrizione) {
public MtbGrup setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
public String getFlagValMag() {
return flagValMag;
}
public void setFlagValMag(String flagValMag) {
public MtbGrup setFlagValMag(String flagValMag) {
this.flagValMag = flagValMag;
return this;
}
public String getLogoWeb() {
return logoWeb;
}
public void setLogoWeb(String logoWeb) {
public MtbGrup setLogoWeb(String logoWeb) {
this.logoWeb = logoWeb;
return this;
}
public String getCriterioVal() {
return criterioVal;
}
public void setCriterioVal(String criterioVal) {
public MtbGrup setCriterioVal(String criterioVal) {
this.criterioVal = criterioVal;
return this;
}
public String getTipoMgrp() {
return tipoMgrp;
}
public void setTipoMgrp(String tipoMgrp) {
public MtbGrup setTipoMgrp(String tipoMgrp) {
this.tipoMgrp = tipoMgrp;
return this;
}
public List<MtbSgrp> getMtbSgrp() {
return mtbSgrp;
}
public void setMtbSgrp(List<MtbSgrp> mtbSgrp) {
public MtbGrup setMtbSgrp(List<MtbSgrp> mtbSgrp) {
this.mtbSgrp = mtbSgrp;
return this;
}
public List<MtbSfam> getMtbSfam() {
return mtbSfam;
}
public void setMtbSfam(List<MtbSfam> mtbSfam) {
public MtbGrup setMtbSfam(List<MtbSfam> mtbSfam) {
this.mtbSfam = mtbSfam;
return this;
}
@Override

View File

@@ -56,40 +56,45 @@ public class MtbSgrp extends EntityBase implements EquatableEntityInterface<MtbS
return codMgrp;
}
public void setCodMgrp(String codMgrp) {
public MtbSgrp setCodMgrp(String codMgrp) {
this.codMgrp = codMgrp;
return this;
}
public String getCodMsgr() {
return codMsgr;
}
public void setCodMsgr(String codMsgr) {
public MtbSgrp setCodMsgr(String codMsgr) {
this.codMsgr = codMsgr;
return this;
}
public String getDescrizione() {
return descrizione;
}
public void setDescrizione(String descrizione) {
public MtbSgrp setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
public String getInclInStat() {
return inclInStat;
}
public void setInclInStat(String inclInStat) {
public MtbSgrp setInclInStat(String inclInStat) {
this.inclInStat = inclInStat;
return this;
}
public String getContoRimFin() {
return contoRimFin;
}
public void setContoRimFin(String contoRimFin) {
public MtbSgrp setContoRimFin(String contoRimFin) {
this.contoRimFin = contoRimFin;
return this;
}
public Integer getOrdinamento() {

View File

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

View File

@@ -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;
}
}

View File

@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
import it.integry.common.var.CommonConstants;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.system.exchange.service.ExchangeArticoliImportService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -26,9 +27,14 @@ public class ExchangeArticoliImportController {
@RequestMapping(value = "import", method = RequestMethod.GET)
public @ResponseBody
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();
}

View File

@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
import it.integry.common.var.CommonConstants;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.system.exchange.service.ExchangeColliImportService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -26,9 +27,16 @@ public class ExchangeColliImportController {
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
public @ResponseBody
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();
}
@@ -43,7 +51,8 @@ public class ExchangeColliImportController {
@RequestParam(required = false) String codVdes
) throws Exception {
LocalDate dataCertificato = LocalDate.parse(dataCert);
return ServiceRestResponse.createPositiveResponse(exchangeColliImportService.getCertificati(codAnag,
return ServiceRestResponse.createPositiveResponse(exchangeColliImportService.getCertificati(configuration,
codAnag,
dataCertificato,
codMart,
codVdes));

View File

@@ -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();
}
}

View File

@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
import it.integry.common.var.CommonConstants;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.system.exchange.service.ExchangeDocumentImportService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -26,9 +27,13 @@ public class ExchangeDocumentImportController {
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
public @ResponseBody
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();
}
}

View File

@@ -2,6 +2,7 @@ package it.integry.ems.system.exchange.controller;
import it.integry.common.var.CommonConstants;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.system.exchange.service.ExchangeOrdiniImportService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -23,13 +24,17 @@ public class ExchangeOrdiniImportController {
private ExchangeOrdiniImportService exchangeOrdiniImportService;
@RequestMapping(value = "importLavorazione", method = RequestMethod.GET)
public @ResponseBody
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();
}
}

View File

@@ -13,7 +13,6 @@ 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.sql.Connection;
@@ -25,19 +24,14 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
@Service
@Scope("request")
public class ExchangeArticoliImportService {
//TODO: To be remove, only for fast development
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
@@ -46,21 +40,20 @@ public class ExchangeArticoliImportService {
private final Logger logger = LogManager.getLogger();
public void importArticoli() throws Exception {
public void importArticoli(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
boolean useTempTable = true;
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
try {
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli, useTempTable);
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Articoli, useTempTable);
importGruppiMerceologici(exchangeDb, useTempTable);
importGruppiMerceologici(internalMultiDb, exchangeMultiDb, useTempTable);
final List<MtbAart> exchangeImportedData = retrieveArticoli(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
true, false);
final List<MtbAart> exchangeUpdatedData = retrieveArticoli(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
false, useTempTable);
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
@@ -78,17 +71,17 @@ public class ExchangeArticoliImportService {
for (EquatableEntityInterface dataToSave : allData) {
// calls.add(() -> {
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allData.size());
logger.debug("Importati {} articoli di {}", importedCounter.incrementAndGet(), allData.size());
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);
multiDBTransactionManager.commitAll();
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (MtbAart) dataToSave, useTempTable);
internalMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
logger.error("Errore durante l'importazione del documento", ex);
multiDBTransactionManager.rollbackAll();
logger.error("Errore durante l'importazione dell'articolo", ex);
internalMultiDb.rollbackAll();
//throw ex;
}
@@ -99,8 +92,7 @@ public class ExchangeArticoliImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
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();
}
private void importGruppiMerceologici(MultiDBTransactionManager exchangeDb, boolean useTempTable) throws Exception {
final List<MtbGrup> exchangeImportedData = retrieveMtbGrup(
private void importGruppiMerceologici(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeDb, boolean useTempTable) throws Exception {
final List<MtbGrup> exchangeImportedDataMtbGrup = retrieveMtbGrup(
exchangeDb.getPrimaryConnection(),
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(),
false, useTempTable);
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
.runSync(MtbGrup.class, exchangeImportedData, exchangeUpdatedData);
final List<MtbSgrp> exchangeUpdatedDataMtbSgrp = retrieveMtbSgrup(
exchangeDb.getPrimaryConnection(),
false, useTempTable);
allData.stream()
.map(x -> (MtbGrup) x)
final List<MtbSfam> exchangeUpdatedDataMtbSfam = retrieveMtbSfam(
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 -> {
MtbSgrp testata = new MtbSgrp()
.setCodMgrp(x.getCodMgrp())
.setCodMsgr(x.getCodMsgr());
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);
testata.setOperation(OperationType.UPDATE);
allMsgrpData.add(testata);
});
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};
AtomicInteger importedCounter = new AtomicInteger();
List<RunnableThrowable> calls = new ArrayList<>();
for (EquatableEntityInterface dataToSave : allData) {
for (EquatableEntityInterface dataToSave : allMgrpData) {
// calls.add(() -> {
logger.debug("Importati {} gruppi merceologici di {}", importedCounter.incrementAndGet(), allData.size());
logger.debug("Importati {} gruppi merceologici di {}", importedCounter.incrementAndGet(), allMgrpData.size());
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);
multiDBTransactionManager.commitAll();
internalMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
logger.error("Errore durante l'importazione del gruppo merceologico", ex);
multiDBTransactionManager.rollbackAll();
internalMultiDb.rollbackAll();
//throw ex;
}
@@ -197,49 +262,52 @@ public class ExchangeArticoliImportService {
private List<MtbGrup> retrieveMtbGrup(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
String mtbGrupOriginalTableName = "mtb_grup";
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 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 mtbSfamTableName = mtbSfamOriginalTableName + (useTempTable ? "_tmp" : "");
if (useTempTable) {
UtilityDB.executeStatement(connection,
"INSERT INTO " + mtbGrupTableName +
" SELECT * FROM " + mtbGrupOriginalTableName,
"INSERT INTO " + mtbSgrpTableName +
" SELECT * FROM " + mtbSgrpOriginalTableName,
"INSERT INTO " + mtbSfamTableName +
" SELECT * FROM " + mtbSfamOriginalTableName
);
}
List<MtbGrup> mtbGrups = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbGrup.class,
mtbGrupTableName, null, retrieveAlreadyImported);
List<MtbSgrp> mtbSgrps = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSgrp.class,
mtbSgrpTableName, null, retrieveAlreadyImported);
List<MtbSfam> mtbSfams = exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSfam.class,
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbSfam.class,
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;
}

View File

@@ -1,6 +1,5 @@
package it.integry.ems.system.exchange.service;
import it.integry.ems.datasource.DataSource;
import it.integry.ems.expansion.RunnableThrowable;
import it.integry.ems.service.EntityProcessor;
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.utility.Query;
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.UtilityQuery;
import it.integry.ems_model.utility.*;
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.math.BigDecimal;
import java.sql.Connection;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -32,18 +28,14 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
@Service
@Scope("request")
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
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
@@ -53,28 +45,25 @@ public class ExchangeColliImportService {
@Autowired
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
private final Logger logger = LogManager.getLogger();
@Autowired
private SetupGest setupGest;
public void importColliLavorazione() throws Exception {
public void importColliLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
boolean useTempTable = true;
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
try {
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
final List<MtbColt> exchangeImportedMtbColts = importColliLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
true, false);
List<MtbColt> exchangeUpdatedMtbColts = importColliLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
false, useTempTable);
@@ -102,12 +91,12 @@ public class ExchangeColliImportService {
// calls.add(() -> {
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allMtbColts.size());
try {
entityProcessor.processEntity(mtbColtToSave, multiDBTransactionManager);
entityProcessor.processEntity(mtbColtToSave, internalMultiDb);
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbColt) mtbColtToSave, useTempTable);
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (MtbColt) mtbColtToSave, useTempTable);
multiDBTransactionManager.commitAll();
exchangeDb.commitAll();
internalMultiDb.commitAll();
exchangeMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
@@ -123,8 +112,7 @@ public class ExchangeColliImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
if (useTempTable)
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione);
}
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.ColliLavorazione);
}
}
@@ -188,17 +176,16 @@ 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 {
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(profileDb)) {
String profileDbExchange = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "PVM", "PIAN_ACC_ROSSG", "PROFILE_DB_CERT");
DataSource dsSync = new DataSource();
dsSync.initialize(profileDbExchange);
multiDBTransactionManager.addConnection(profileDbExchange, dsSync);
Connection conExch = multiDBTransactionManager.getDatabaseDataSource(profileDbExchange).getConnection();
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
List<CertificatiSinfoOneDTO> listaCert = UtilityDB.executeSimpleQueryDTO(
conExch,
exchangeDb.getPrimaryConnection(),
Query.format("SELECT TRIM(cod_anag) AS codAnag,\n" +
" TRIM(rag_soc) AS ragSoc,\n" +
" TRIM(cod_Vdes) AS codVdes,\n" +
@@ -250,3 +237,5 @@ public class ExchangeColliImportService {
return listaCert;
}
}
}
}

View File

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

View File

@@ -13,7 +13,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
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.sql.Connection;
@@ -27,19 +26,14 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
@Service
@Scope("request")
public class ExchangeDocumentImportService {
//TODO: To be remove, only for fast development
private final String ROSSOGARGANO_EXCHANGE_PROFILEDB = "ROSSO_GARGANO_EXCHANGE";
private final String ROSSOGARGANO_EXCHANGE_USER = "DBA";
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
@@ -51,38 +45,37 @@ public class ExchangeDocumentImportService {
private final Logger logger = LogManager.getLogger();
public void importTestateDocumentiLavorazione() throws Exception {
public void importTestateDocumentiLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
boolean useTempTable = true;
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
try {
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
true, false);
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
false, useTempTable);
final List<DtbDocr> exchangeImportedRigheData = importRigheDocumentiLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
true, false);
final List<DtbDocr> exchangeUpdatedRigheData = importRigheDocumentiLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
false, useTempTable);
@@ -140,13 +133,13 @@ public class ExchangeDocumentImportService {
// calls.add(() -> {
logger.debug("Importati {} di {}", importedCounter.incrementAndGet(), allData.size());
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();
exchangeDb.commitAll();
internalMultiDb.commitAll();
exchangeMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
@@ -163,8 +156,7 @@ public class ExchangeDocumentImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
if (useTempTable)
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione);
}
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione);
}
}

View File

@@ -1,10 +1,12 @@
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.dto.DatabaseTable;
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.DatabaseView;
import it.integry.ems_model.entity._enum.IBaseEnum;
import org.springframework.stereotype.Service;
import java.sql.Connection;
@@ -18,14 +20,45 @@ import java.util.stream.Collectors;
public class ExchangeImportSchemaManagerService {
public enum SchemaType {
ColliLavorazione,
OrdiniLavorazione,
DocumentiLavorazione,
Articoli,
PartiteMagazzinoLavorazione
public enum SchemaType implements IBaseEnum {
ColliLavorazione(1),
OrdiniLavorazione(2),
DocumentiLavorazione(3),
Articoli(4),
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>>() {{
put(SchemaType.ColliLavorazione, Arrays.asList("mtb_colt_lav", "mtb_colr_lav"));
put(SchemaType.OrdiniLavorazione, Arrays.asList("dtb_ordt_lav", "dtb_ordr_lav"));

View File

@@ -14,7 +14,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
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.sql.Connection;
@@ -28,20 +27,13 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
@Service
@Scope("request")
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();
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
@@ -51,24 +43,23 @@ public class ExchangeOrdiniImportService {
@Autowired
private ExchangePartiteMagazzinoImportService exchangePartiteMagazzinoImportService;
public void importOrdiniLavorazione() throws Exception {
public void importOrdiniLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
boolean useTempTable = true;
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
try {
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione();
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione, useTempTable);
exchangePartiteMagazzinoImportService.importPartiteMagazzinoLavorazione(internalMultiDb, exchangeMultiDb);
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
true, false);
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusWeeks(1),
UtilityLocalDate.getNow(),
false, useTempTable);
@@ -110,16 +101,16 @@ public class ExchangeOrdiniImportService {
logger.debug("Importati {} di {}", importedCounter[0].incrementAndGet(), allData.size());
try {
entityProcessor.processEntity(dtbOrdtToSave, multiDBTransactionManager);
entityProcessor.processEntity(dtbOrdtToSave, internalMultiDb);
singleUpdateImported(exchangeDb.getPrimaryConnection(), (DtbOrdt) dtbOrdtToSave, useTempTable);
multiDBTransactionManager.commitAll();
exchangeDb.commitAll();
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbOrdt) dtbOrdtToSave, useTempTable);
internalMultiDb.commitAll();
exchangeMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
logger.error("Errore durante l'importazione dell'ordine", ex);
multiDBTransactionManager.rollbackAll();
internalMultiDb.rollbackAll();
//throw ex;
}
//});
@@ -133,8 +124,7 @@ public class ExchangeOrdiniImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
if (useTempTable)
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
}
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
}
}

View File

@@ -12,7 +12,6 @@ import it.integry.ems_model.utility.UtilityLocalDate;
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.sql.Connection;
@@ -24,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
@SuppressWarnings("rawtypes")
@Service
@Scope("request")
public class ExchangePartiteMagazzinoImportService {
//TODO: To be remove, only for fast development
@@ -35,9 +33,6 @@ public class ExchangePartiteMagazzinoImportService {
@Autowired
private EntityProcessor entityProcessor;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@Autowired
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
@@ -46,22 +41,21 @@ public class ExchangePartiteMagazzinoImportService {
private final Logger logger = LogManager.getLogger();
public void importPartiteMagazzinoLavorazione() throws Exception {
public void importPartiteMagazzinoLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb) throws Exception {
boolean useTempTable = true;
try (MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(ROSSOGARGANO_EXCHANGE_PROFILEDB)) {
try {
exchangeImportSchemaManagerService.syncSchema(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione, useTempTable);
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione, useTempTable);
final List<MtbPartitaMag> exchangeImportedData = retrievePartite(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusMonths(3),
UtilityLocalDate.getNow(),
true, false);
final List<MtbPartitaMag> exchangeUpdatedData = retrievePartite(
exchangeDb.getPrimaryConnection(),
exchangeMultiDb.getPrimaryConnection(),
UtilityLocalDate.getNow().minusMonths(3),
UtilityLocalDate.getNow(),
false, useTempTable);
@@ -83,13 +77,13 @@ public class ExchangePartiteMagazzinoImportService {
// calls.add(() -> {
logger.debug("Importate {} partite di magazzino di {}", importedCounter.incrementAndGet(), allData.size());
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();
exchangeDb.commitAll();
internalMultiDb.commitAll();
exchangeMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
@@ -107,8 +101,7 @@ public class ExchangePartiteMagazzinoImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
if (useTempTable)
exchangeImportSchemaManagerService.deleteTempTables(exchangeDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione);
}
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.PartiteMagazzinoLavorazione);
}
}

View File

@@ -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()) {
}
}
}