Compare commits
1 Commits
feature/JD
...
JpaTest
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d7212ce97 |
18
.idea/copilotDiffState.xml
generated
Normal file
18
.idea/copilotDiffState.xml
generated
Normal file
File diff suppressed because one or more lines are too long
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="central" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
|
||||
@@ -404,6 +404,17 @@
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>2.7.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.6.15.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
|
||||
@@ -3,6 +3,7 @@ package it.integry.ems.javabeans;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems._context.ApplicationContextProvider;
|
||||
import it.integry.ems.jpa.TenantContext;
|
||||
import it.integry.ems.json.ResponseJSONObjectMapper;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.model.IntegryApplicationEnum;
|
||||
@@ -19,13 +20,15 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
@Scope("request")
|
||||
@Scope(WebApplicationContext.SCOPE_REQUEST)
|
||||
public class RequestDataDTO {
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
@@ -100,6 +103,24 @@ public class RequestDataDTO {
|
||||
} else {
|
||||
jsonObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
// Logica di fallback o recupero tenant da sessione/utente
|
||||
if (profileDB == null || profileDB.isEmpty()) {
|
||||
// Esempio: recupero da sessione se presente
|
||||
// tenantId = (String) request.getSession().getAttribute("TENANT_ID");
|
||||
|
||||
// Fallback temporaneo per test
|
||||
// tenantId = DEFAULT_TENANT;
|
||||
}
|
||||
|
||||
if (profileDB != null) {
|
||||
TenantContext.setCurrentTenant(profileDB);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() throws Exception {
|
||||
TenantContext.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package it.integry.ems.jpa;
|
||||
|
||||
import it.integry.ems.settings.Model.AvailableConnectionModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.BasicConnectionPool;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MultiTenantDataSource extends AbstractRoutingDataSource {
|
||||
|
||||
private final BasicConnectionPool basicConnectionPool;
|
||||
private final SettingsModel settingsModel;
|
||||
|
||||
public MultiTenantDataSource(BasicConnectionPool basicConnectionPool, SettingsModel settingsModel) {
|
||||
this.basicConnectionPool = basicConnectionPool;
|
||||
this.settingsModel = settingsModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return TenantContext.getCurrentTenant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||
List<AvailableConnectionModel> connections = settingsModel.getAvailableConnections(false);
|
||||
|
||||
// Imposta il primo come default se necessario, o gestisci il caso null
|
||||
DataSource defaultDataSource = null;
|
||||
|
||||
for (AvailableConnectionModel model : connections) {
|
||||
DataSource ds = basicConnectionPool.getDataSource(model.getProfileName());
|
||||
if (ds != null) {
|
||||
targetDataSources.put(model.getProfileName(), ds);
|
||||
if (defaultDataSource == null) {
|
||||
defaultDataSource = ds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setTargetDataSources(targetDataSources);
|
||||
this.setDefaultTargetDataSource(defaultDataSource);
|
||||
super.afterPropertiesSet();
|
||||
}
|
||||
|
||||
// Metodo per ricaricare i datasource se vengono aggiunti nuovi tenant a runtime
|
||||
public void refreshDataSources() {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
18
ems-core/src/main/java/it/integry/ems/jpa/TenantContext.java
Normal file
18
ems-core/src/main/java/it/integry/ems/jpa/TenantContext.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package it.integry.ems.jpa;
|
||||
|
||||
public class TenantContext {
|
||||
private static final ThreadLocal<String> currentTenant = new ThreadLocal<>();
|
||||
|
||||
public static void setCurrentTenant(String tenant) {
|
||||
currentTenant.set(tenant);
|
||||
}
|
||||
|
||||
public static String getCurrentTenant() {
|
||||
return currentTenant.get();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
currentTenant.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package it.integry.ems.jpa.entity;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import java.io.Serializable;
|
||||
|
||||
@MappedSuperclass
|
||||
public abstract class BaseEntity implements Serializable {
|
||||
// Classe base per le entity JPA
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package it.integry.ems.jpa.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface BaseRepository<T, ID> extends JpaRepository<T, ID> {
|
||||
// Interfaccia base per i repository
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package it.integry.ems.jpa.repository;
|
||||
|
||||
import it.integry.ems_model.entity.MtbAart;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface MtbAartRepository extends BaseRepository<MtbAart, String> {
|
||||
|
||||
Optional<MtbAart> findByCodMart(String codMart);
|
||||
|
||||
List<MtbAart> findByCodMartIn(List<String> codMarts);
|
||||
|
||||
|
||||
@Query("SELECT m FROM MtbAart m WHERE m.untMis = 'KG'")
|
||||
List<MtbAart> findMtbAartsByUntMisKG();
|
||||
}
|
||||
@@ -109,6 +109,20 @@ public class BasicConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
public javax.sql.DataSource getDataSource(String profileName) {
|
||||
AvailableConnectionModel model = settingsModel.findConnectionModel(profileName);
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
registerDataSourceIfNotExists(model);
|
||||
return registeredDatasources.get(model);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving DataSource for profile: " + profileName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerDataSourceIfNotExists(AvailableConnectionModel connectionModel) throws Exception {
|
||||
if (!registeredDatasources.containsKey(connectionModel)) {
|
||||
|
||||
@@ -12,14 +12,16 @@ import it.integry.ems_model.utility.UtilityDB;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@javax.persistence.Entity
|
||||
@javax.persistence.Table(name = MtbAart.ENTITY)
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@Table(MtbAart.ENTITY)
|
||||
@@ -32,344 +34,457 @@ public class MtbAart extends EntityBase implements EquatableEntityInterface<MtbA
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@javax.persistence.Id
|
||||
@javax.persistence.Column(name = "cod_mart")
|
||||
@PK
|
||||
@SqlField(value = "cod_mart", maxLength = 15, nullable = false)
|
||||
private String codMart;
|
||||
|
||||
@javax.persistence.Column(name = "descrizione")
|
||||
@SqlField(value = "descrizione", maxLength = 40, nullable = false)
|
||||
private String descrizione;
|
||||
|
||||
@javax.persistence.Column(name = "unt_mis")
|
||||
@FK(tableName = "mtb_unt_mis", columnName = "unt_mis")
|
||||
@SqlField(value = "unt_mis", maxLength = 3, nullable = false)
|
||||
private String untMis;
|
||||
|
||||
@javax.persistence.Column(name = "bar_code")
|
||||
@SqlField(value = "bar_code", maxLength = 40)
|
||||
private String barCode;
|
||||
|
||||
@javax.persistence.Column(name = "peso_kg")
|
||||
@SqlField(value = "peso_kg", nullable = false, defaultObjectValue = "0")
|
||||
private BigDecimal pesoKg;
|
||||
|
||||
@javax.persistence.Column(name = "qta_cnf")
|
||||
@SqlField(value = "qta_cnf", nullable = false, defaultObjectValue = "1")
|
||||
private BigDecimal qtaCnf;
|
||||
|
||||
@javax.persistence.Column(name = "cod_aliq")
|
||||
@SqlField(value = "cod_aliq", maxLength = 5)
|
||||
private String codAliq;
|
||||
|
||||
@javax.persistence.Column(name = "cod_sco_art")
|
||||
@SqlField(value = "cod_sco_art", maxLength = 5)
|
||||
private String codScoArt;
|
||||
|
||||
@javax.persistence.Column(name = "cod_tcol_ui")
|
||||
@SqlField(value = "cod_tcol_ui")
|
||||
private String codTcolUi;
|
||||
|
||||
@javax.persistence.Column(name = "cod_tcol_ul")
|
||||
@SqlField(value = "cod_tcol_ul")
|
||||
private String codTcolUl;
|
||||
|
||||
@javax.persistence.Column(name = "articolo_composto")
|
||||
@SqlField(value = "articolo_composto", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String articoloComposto;
|
||||
|
||||
@javax.persistence.Column(name = "esposizione_comp")
|
||||
@SqlField(value = "esposizione_comp", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String esposizioneComp;
|
||||
|
||||
@javax.persistence.Column(name = "descrizione_estesa")
|
||||
@SqlField(value = "descrizione_estesa", maxLength = 4096)
|
||||
private String descrizioneEstesa;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ult_forn")
|
||||
@SqlField(value = "cod_ult_forn", maxLength = 5)
|
||||
private String codUltForn;
|
||||
|
||||
@javax.persistence.Column(name = "data_ult_car")
|
||||
@SqlField(value = "data_ult_car")
|
||||
private Date dataUltCar;
|
||||
|
||||
@javax.persistence.Column(name = "val_ult_car")
|
||||
@SqlField(value = "val_ult_car")
|
||||
private BigDecimal valUltCar;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ult_clie")
|
||||
@SqlField(value = "cod_ult_clie", maxLength = 5)
|
||||
private String codUltClie;
|
||||
|
||||
@javax.persistence.Column(name = "data_ult_scar")
|
||||
@SqlField(value = "data_ult_scar")
|
||||
private Date dataUltScar;
|
||||
|
||||
@javax.persistence.Column(name = "val_ult_scar")
|
||||
@SqlField(value = "val_ult_scar")
|
||||
private BigDecimal valUltScar;
|
||||
|
||||
@javax.persistence.Column(name = "tipo_codice")
|
||||
@SqlField(value = "tipo_codice", maxLength = 10)
|
||||
private String tipoCodice;
|
||||
|
||||
@javax.persistence.Column(name = "note")
|
||||
@SqlField(value = "note", maxLength = 255)
|
||||
private String note;
|
||||
|
||||
@javax.persistence.Column(name = "posizione")
|
||||
@SqlField(value = "posizione", maxLength = 15)
|
||||
private String posizione;
|
||||
|
||||
@javax.persistence.Column(name = "colli_pedana")
|
||||
@SqlField(value = "colli_pedana", defaultObjectValue = "1")
|
||||
private BigDecimal colliPedana;
|
||||
|
||||
@javax.persistence.Column(name = "unt_mis2")
|
||||
@FK(tableName = "mtb_unt_mis", columnName = "unt_mis")
|
||||
@SqlField(value = "unt_mis2", maxLength = 3)
|
||||
private String untMis2;
|
||||
|
||||
@javax.persistence.Column(name = "rap_conv2")
|
||||
@SqlField(value = "rap_conv2", defaultObjectValue = "1")
|
||||
private BigDecimal rapConv2;
|
||||
|
||||
@javax.persistence.Column(name = "flag_incl_listino")
|
||||
@SqlField(value = "flag_incl_listino", maxLength = 1, nullable = false, defaultObjectValue = "S")
|
||||
private String flagInclListino;
|
||||
|
||||
@javax.persistence.Column(name = "unt_mis3")
|
||||
@FK(tableName = "mtb_unt_mis", columnName = "unt_mis")
|
||||
@SqlField(value = "unt_mis3", maxLength = 3)
|
||||
private String untMis3;
|
||||
|
||||
@javax.persistence.Column(name = "rap_conv3")
|
||||
@SqlField(value = "rap_conv3", defaultObjectValue = "1")
|
||||
private BigDecimal rapConv3;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mart_stat")
|
||||
@SqlField(value = "cod_mart_stat", maxLength = 15)
|
||||
private String codMartStat;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mcon")
|
||||
@SqlField(value = "cod_mcon", maxLength = 5)
|
||||
private String codMcon;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mgrp")
|
||||
@SqlField(value = "cod_mgrp", maxLength = 5, nullable = false)
|
||||
private String codMgrp;
|
||||
|
||||
@javax.persistence.Column(name = "cod_msfa")
|
||||
@SqlField(value = "cod_msfa", maxLength = 6)
|
||||
private String codMsfa;
|
||||
|
||||
@javax.persistence.Column(name = "cod_msgr")
|
||||
@SqlField(value = "cod_msgr", maxLength = 5, nullable = false)
|
||||
private String codMsgr;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mstp")
|
||||
@SqlField(value = "cod_mstp", maxLength = 5)
|
||||
private String codMstp;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mtip")
|
||||
@SqlField(value = "cod_mtip", maxLength = 5)
|
||||
private String codMtip;
|
||||
|
||||
@javax.persistence.Column(name = "descrizione_stat")
|
||||
@SqlField(value = "descrizione_stat", maxLength = 40)
|
||||
private String descrizioneStat;
|
||||
|
||||
@javax.persistence.Column(name = "flag_stato")
|
||||
@SqlField(value = "flag_stato", maxLength = 1, nullable = false, defaultObjectValue = "A")
|
||||
private String flagStato;
|
||||
|
||||
@javax.persistence.Column(name = "cambio_divi_car")
|
||||
@SqlField(value = "cambio_divi_car", nullable = false)
|
||||
private BigDecimal cambioDiviCar;
|
||||
|
||||
@javax.persistence.Column(name = "cambio_divi_scar")
|
||||
@SqlField(value = "cambio_divi_scar", nullable = false)
|
||||
private BigDecimal cambioDiviScar;
|
||||
|
||||
@javax.persistence.Column(name = "gg_scad_partita")
|
||||
@SqlField(value = "gg_scad_partita", nullable = false, defaultObjectValue = "0")
|
||||
private Integer ggScadPartita;
|
||||
|
||||
@javax.persistence.Column(name = "volume_mc")
|
||||
@SqlField(value = "volume_mc", defaultObjectValue = "0")
|
||||
private BigDecimal volumeMc;
|
||||
|
||||
@javax.persistence.Column(name = "flag_esponi_prz")
|
||||
@SqlField(value = "flag_esponi_prz", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String flagEsponiPrz;
|
||||
|
||||
@javax.persistence.Column(name = "data_ult_var")
|
||||
@SqlField(value = "data_ult_var", format = CommonConstants.SYSDATE)
|
||||
private Date dataUltVar;
|
||||
|
||||
@javax.persistence.Column(name = "perc_sfrido")
|
||||
@SqlField(value = "perc_sfrido", nullable = false, defaultObjectValue = "0")
|
||||
private BigDecimal percSfrido;
|
||||
|
||||
@javax.persistence.Column(name = "cod_barre_imb")
|
||||
@SqlField(value = "cod_barre_imb", maxLength = 40)
|
||||
private String codBarreImb;
|
||||
|
||||
@javax.persistence.Column(name = "flag_calc_prz")
|
||||
@SqlField(value = "flag_calc_prz", maxLength = 1, nullable = false, defaultObjectValue = "K")
|
||||
private String flagCalcPrz;
|
||||
|
||||
@javax.persistence.Column(name = "esposizione_comp_acq")
|
||||
@SqlField(value = "esposizione_comp_acq", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String esposizioneCompAcq;
|
||||
|
||||
@javax.persistence.Column(name = "flag_calc_prz_acq")
|
||||
@SqlField(value = "flag_calc_prz_acq", maxLength = 1, nullable = false, defaultObjectValue = "K")
|
||||
private String flagCalcPrzAcq;
|
||||
|
||||
@javax.persistence.Column(name = "diacod")
|
||||
@SqlField(value = "diacod", maxLength = 40)
|
||||
private String diacod;
|
||||
|
||||
@javax.persistence.Column(name = "plu")
|
||||
@SqlField(value = "plu", maxLength = 6)
|
||||
private String plu;
|
||||
|
||||
@javax.persistence.Column(name = "part_iva_prod")
|
||||
@SqlField(value = "part_iva_prod", maxLength = 20)
|
||||
private String partIvaProd;
|
||||
|
||||
@javax.persistence.Column(name = "rag_soc_prod")
|
||||
@SqlField(value = "rag_soc_prod", maxLength = 40)
|
||||
private String ragSocProd;
|
||||
|
||||
@javax.persistence.Column(name = "flag_rap_conv_variabile")
|
||||
@SqlField(value = "flag_rap_conv_variabile", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String flagRapConvVariabile;
|
||||
|
||||
@javax.persistence.Column(name = "flag_mov_art_mag")
|
||||
@SqlField(value = "flag_mov_art_mag", maxLength = 1, nullable = false, defaultObjectValue = "S")
|
||||
private String flagMovArtMag;
|
||||
|
||||
@javax.persistence.Column(name = "flag_tracciabilita")
|
||||
@SqlField(value = "flag_tracciabilita", maxLength = 1, nullable = false, defaultObjectValue = "N")
|
||||
private String flagTracciabilita;
|
||||
|
||||
@javax.persistence.Column(name = "tara_kg")
|
||||
@SqlField(value = "tara_kg", defaultObjectValue = "0")
|
||||
private BigDecimal taraKg;
|
||||
|
||||
@javax.persistence.Column(name = "colli_strato")
|
||||
@SqlField(value = "colli_strato", nullable = false, defaultObjectValue = "1")
|
||||
private BigDecimal colliStrato;
|
||||
|
||||
@javax.persistence.Column(name = "flag_qta_cnf_fissa")
|
||||
@SqlField(value = "flag_qta_cnf_fissa", maxLength = 1, nullable = false, defaultObjectValue = "S")
|
||||
private String flagQtaCnfFissa;
|
||||
|
||||
@javax.persistence.Column(name = "flag_colli_pedana_fisso")
|
||||
@SqlField(value = "flag_colli_pedana_fisso", maxLength = 1, nullable = false, defaultObjectValue = "S")
|
||||
private String flagColliPedanaFisso;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ccon_costi")
|
||||
@SqlField(value = "cod_ccon_costi", maxLength = 6)
|
||||
private String codCconCosti;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ccon_ricavi")
|
||||
@SqlField(value = "cod_ccon_ricavi", maxLength = 6)
|
||||
private String codCconRicavi;
|
||||
|
||||
@javax.persistence.Column(name = "cod_dgrp_art")
|
||||
@SqlField(value = "cod_dgrp_art", maxLength = 5)
|
||||
private String codDgrpArt;
|
||||
|
||||
@javax.persistence.Column(name = "cod_divi_car")
|
||||
@SqlField(value = "cod_divi_car", maxLength = 5, nullable = false)
|
||||
private String codDiviCar;
|
||||
|
||||
@javax.persistence.Column(name = "cod_divi_scar")
|
||||
@SqlField(value = "cod_divi_scar", maxLength = 5, nullable = false)
|
||||
private String codDiviScar;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ecr_cat")
|
||||
@SqlField(value = "cod_ecr_cat", maxLength = 10)
|
||||
private String codEcrCat;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ecr_mcat")
|
||||
@SqlField(value = "cod_ecr_mcat", maxLength = 10)
|
||||
private String codEcrMcat;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ecr_rep")
|
||||
@SqlField(value = "cod_ecr_rep", maxLength = 10)
|
||||
private String codEcrRep;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ecr_stipo")
|
||||
@SqlField(value = "cod_ecr_stipo", maxLength = 10)
|
||||
private String codEcrStipo;
|
||||
|
||||
@javax.persistence.Column(name = "cod_ecr_tipo")
|
||||
@SqlField(value = "cod_ecr_tipo", maxLength = 10)
|
||||
private String codEcrTipo;
|
||||
|
||||
@javax.persistence.Column(name = "cod_grp_bolla")
|
||||
@SqlField(value = "cod_grp_bolla", maxLength = 5)
|
||||
private String codGrpBolla;
|
||||
|
||||
@javax.persistence.Column(name = "ingredienti")
|
||||
@SqlField(value = "ingredienti", maxLength = 8000)
|
||||
private String ingredienti;
|
||||
|
||||
@javax.persistence.Column(name = "id_art_equi")
|
||||
@SqlField(value = "id_art_equi", maxLength = 25)
|
||||
private String idArtEqui;
|
||||
|
||||
@javax.persistence.Column(name = "descr_cassa")
|
||||
@SqlField(value = "descr_cassa", maxLength = 40)
|
||||
private String descrCassa;
|
||||
|
||||
@javax.persistence.Column(name = "cod_nc_intracee")
|
||||
@SqlField(value = "cod_nc_intracee", maxLength = 20)
|
||||
private String codNcIntracee;
|
||||
|
||||
@javax.persistence.Column(name = "marchio")
|
||||
@SqlField(value = "marchio", maxLength = 255)
|
||||
private String marchio;
|
||||
|
||||
@javax.persistence.Column(name = "sezione")
|
||||
@SqlField(value = "sezione")
|
||||
private Integer sezione;
|
||||
|
||||
@javax.persistence.Column(name = "tipo_reg")
|
||||
@SqlField(value = "tipo_reg", maxLength = 1)
|
||||
private String tipoReg;
|
||||
|
||||
@javax.persistence.Column(name = "tipo_stock")
|
||||
@SqlField(value = "tipo_stock", maxLength = 1)
|
||||
private String tipoStock;
|
||||
|
||||
@javax.persistence.Column(name = "qta_multipla_ord")
|
||||
@SqlField(value = "qta_multipla_ord")
|
||||
private BigDecimal qtaMultiplaOrd;
|
||||
|
||||
@MapToTable(value = "flag_kit")
|
||||
@Transient
|
||||
private String flagKit;
|
||||
|
||||
@javax.persistence.Column(name = "cod_forn_cv")
|
||||
@SqlField(value = "cod_forn_cv", maxLength = 5)
|
||||
private String codFornCv;
|
||||
|
||||
@javax.persistence.Column(name = "cpa")
|
||||
@SqlField(value = "cpa", maxLength = 5)
|
||||
private String cpa;
|
||||
|
||||
@javax.persistence.Column(name = "taric")
|
||||
@SqlField(value = "taric", maxLength = 5)
|
||||
private String taric;
|
||||
|
||||
@javax.persistence.Column(name = "sezione_dogana")
|
||||
@SqlField(value = "sezione_dogana", maxLength = 6)
|
||||
private String sezioneDogana;
|
||||
|
||||
@javax.persistence.Column(name = "flag_peso_egalizzato")
|
||||
@SqlField(value = "flag_peso_egalizzato", nullable = false, defaultObjectValue = "0")
|
||||
private Boolean flagPesoEgalizzato;
|
||||
|
||||
@javax.persistence.Column(name = "cod_jfas_costi")
|
||||
@SqlField(value = "cod_jfas_costi", maxLength = 5)
|
||||
private String codJfasCosti;
|
||||
|
||||
@javax.persistence.Column(name = "cod_jfas_ricavi")
|
||||
@SqlField(value = "cod_jfas_ricavi", maxLength = 5)
|
||||
private String codJfasRicavi;
|
||||
|
||||
@Transient
|
||||
private String mtbAartEqui_descrizione;
|
||||
|
||||
@javax.persistence.Column(name = "flag_arr_prz_vend_iva")
|
||||
@SqlField(value = "flag_arr_prz_vend_iva", nullable = false, defaultObjectValue = "1")
|
||||
private Boolean flagArrPrzVendIva;
|
||||
|
||||
@javax.persistence.Column(name = "classificazione_abc")
|
||||
@SqlField(value = "classificazione_abc", maxLength = 1)
|
||||
private String classificazioneAbc;
|
||||
|
||||
@javax.persistence.Column(name = "tipo_codice_imballo")
|
||||
@SqlField(value = "tipo_codice_imballo", maxLength = 10)
|
||||
private String tipoCodiceImballo;
|
||||
|
||||
@javax.persistence.Column(name = "flag_stampa_docu_vend")
|
||||
@SqlField(value = "flag_stampa_docu_vend", nullable = false, defaultObjectValue = "1")
|
||||
private Boolean flagStampaDocuVend;
|
||||
|
||||
@javax.persistence.Column(name = "flag_reso_tec")
|
||||
@SqlField(value = "flag_reso_tec", nullable = false, defaultObjectValue = "0")
|
||||
private Boolean flagResoTec;
|
||||
|
||||
@javax.persistence.Column(name = "cod_mssfa")
|
||||
@SqlField(value = "cod_mssfa", maxLength = 6)
|
||||
private String codMssfa;
|
||||
|
||||
@javax.persistence.Column(name = "cod_linea")
|
||||
@SqlField(value = "cod_linea", maxLength = 6)
|
||||
private String codLinea;
|
||||
|
||||
@javax.persistence.Column(name = "cod_slinea")
|
||||
@SqlField(value = "cod_slinea", maxLength = 6)
|
||||
private String codSlinea;
|
||||
|
||||
@javax.persistence.Column(name = "cod_sslinea")
|
||||
@SqlField(value = "cod_sslinea", maxLength = 6)
|
||||
private String codSslinea;
|
||||
|
||||
@Priority(1)
|
||||
@Transient
|
||||
private MtbAartMarchio mtbAartMarchio;
|
||||
|
||||
@Priority(1)
|
||||
@Transient
|
||||
private MtbAartEqui mtbAartEqui;
|
||||
|
||||
@Priority(1)
|
||||
@Transient
|
||||
private List<MtbUntMis> mtbUntMis;
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartBarCode> mtbAartBarCode = new ArrayList<>();
|
||||
|
||||
/*@EntityChild
|
||||
private List<MtbPart> mtbPart;*/
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartCarat> mtbAartCarat = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartAnag> mtbAartAnag = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbSpes> mtbSpes = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbComp> mtbComp = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartDesc> mtbAartDesc = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartLink> mtbAartLink = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbPartitaMag> mtbPartitaMag = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MrlAartSchTecSet> mrlAartSchTecSet = new ArrayList<>();
|
||||
|
||||
@EntityChild
|
||||
@Transient
|
||||
private List<MtbAartColori> mtbAartColori = new ArrayList<>();
|
||||
|
||||
@Priority(101)
|
||||
@Transient
|
||||
List<JtbCicl> jtbCicl;
|
||||
|
||||
@Transient
|
||||
private List<MtbLisa> mtbLisa;
|
||||
|
||||
public MtbAart() {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package it.integry.ems.jpa;
|
||||
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class TenantInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestDataDTO;
|
||||
|
||||
// private static final String TENANT_HEADER = "X-Tenant-ID";
|
||||
// private static final String DEFAULT_TENANT = "default"; // O recuperalo da configurazione
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String profileDb = requestDataDTO.getProfileDB();
|
||||
|
||||
// String tenantId = request.getHeader(TENANT_HEADER);
|
||||
|
||||
// Logica di fallback o recupero tenant da sessione/utente
|
||||
if (profileDb == null || profileDb.isEmpty()) {
|
||||
// Esempio: recupero da sessione se presente
|
||||
// tenantId = (String) request.getSession().getAttribute("TENANT_ID");
|
||||
|
||||
// Fallback temporaneo per test
|
||||
// tenantId = DEFAULT_TENANT;
|
||||
}
|
||||
|
||||
if (profileDb != null) {
|
||||
TenantContext.setCurrentTenant(profileDb);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ public class ProductController {
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@Autowired
|
||||
private it.integry.ems.jpa.repository.MtbAartRepository mtbAartRepository;
|
||||
|
||||
@Autowired
|
||||
private ServiceChecker serviceChecker;
|
||||
|
||||
@@ -287,6 +290,18 @@ public class ProductController {
|
||||
return new ServiceRestResponse(EsitoType.OK, null, mtbAartList);
|
||||
}
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_SMART_ENTERPRISE_GET_ART_BY_CODMART + "/jpa", method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse getArticoloByCodMartJpa(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam("codMart") String codMartString) throws Exception {
|
||||
|
||||
List<String> codMarts = Arrays.asList(codMartString.split(","));
|
||||
List<MtbAart> mtbAartList = mtbAartRepository.findByCodMartIn(codMarts);
|
||||
|
||||
return new ServiceRestResponse(EsitoType.OK, null, mtbAartList);
|
||||
}
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_POPOLA_TABELLA_RIASSEGNAZIONE, method = RequestMethod.POST)
|
||||
public ServiceRestResponse popolaTabellaRiassegnazione(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
||||
|
||||
5
ems-engine/src/main/resources/configs/jpa.properties
Normal file
5
ems-engine/src/main/resources/configs/jpa.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
|
||||
hibernate.show_sql=false
|
||||
hibernate.format_sql=false
|
||||
hibernate.hbm2ddl.auto=none
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
|
||||
<context:component-scan base-package="it.integry"/>
|
||||
|
||||
<import resource="hibernate-context.xml"/>
|
||||
|
||||
<bean id="ppConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="ignoreUnresolvablePlaceholders" value="false"/>
|
||||
<property name="locations">
|
||||
|
||||
54
ems-engine/src/main/resources/spring/hibernate-context.xml
Normal file
54
ems-engine/src/main/resources/spring/hibernate-context.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa
|
||||
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<!-- MultiTenant DataSource -->
|
||||
<bean id="multiTenantDataSource" class="it.integry.ems.jpa.MultiTenantDataSource">
|
||||
<constructor-arg ref="basicConnectionPool"/>
|
||||
<constructor-arg ref="settingsModel"/>
|
||||
</bean>
|
||||
|
||||
<!-- JPA EntityManagerFactory -->
|
||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
||||
<property name="dataSource" ref="multiTenantDataSource"/>
|
||||
<property name="packagesToScan">
|
||||
<list>
|
||||
<value>it.integry.ems_model.entity</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="jpaVendorAdapter">
|
||||
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
||||
<property name="showSql" value="false"/>
|
||||
<property name="generateDdl" value="false"/> <!-- Disabilitato per sicurezza su DB esistenti -->
|
||||
</bean>
|
||||
</property>
|
||||
<property name="jpaProperties">
|
||||
<props>
|
||||
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
|
||||
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop> <!-- Per startup più veloce -->
|
||||
<prop key="hibernate.jdbc.lob.non_contextual_creation">true</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Transaction Manager -->
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
</bean>
|
||||
|
||||
<!-- Abilita i repository JPA -->
|
||||
<jpa:repositories base-package="it.integry.ems.jpa.repository"/>
|
||||
|
||||
<!-- Abilita la gestione delle transazioni tramite annotazioni -->
|
||||
<tx:annotation-driven transaction-manager="transactionManager"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user