Fix su deposito reale dell'utente: è stato aggiunto tra gli header il codMdep che indica il deposito REALE su cui si trova l'utente. Utile per capire quali stampanti usare nel WMS o per sapere su che deposito sta effettuando le chiamate l'utente.
This commit is contained in:
@@ -11,6 +11,7 @@ public class CommonConstants {
|
||||
|
||||
public static final String INTEGRY = "integry";
|
||||
public static final String PROFILE_DB = "profileDb";
|
||||
public static final String COD_MDEP = "codMdep";
|
||||
public static final String WHERE_COND = "whereCond";
|
||||
public static final String EMPTY_STRING = "";
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ public class DbmsChangeTrackerComponent {
|
||||
add(StbGestSetup.ENTITY);
|
||||
add(StbGestSetupDepo.ENTITY);
|
||||
add(WtbGestSetupUser.ENTITY);
|
||||
|
||||
add(WtbDepo.ENTITY);
|
||||
}};
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +52,8 @@ public class EntityCacheComponent implements ApplicationListener {
|
||||
put(StbGestSetup.ENTITY, StbGestSetup.class);
|
||||
put(StbGestSetupDepo.ENTITY, StbGestSetupDepo.class);
|
||||
put(WtbGestSetupUser.ENTITY, WtbGestSetupUser.class);
|
||||
|
||||
put(WtbDepo.ENTITY, WtbDepo.class);
|
||||
}};
|
||||
|
||||
public EntityCacheComponent(DbmsChangeTrackerComponent dbmsChangeTrackerComponent, EntityPropertyHolder entityPropertyHolder) {
|
||||
|
||||
@@ -40,6 +40,10 @@ public class RequestDataDTO {
|
||||
private String requestClientIP;
|
||||
|
||||
private String profileDB;
|
||||
|
||||
//Indica il codice deposito reale dell'utente che effettua la richiesta, ovvero la posizione fisica dell'utente
|
||||
private String codMdep;
|
||||
|
||||
private Long deviceId;
|
||||
private String username;
|
||||
private String password;
|
||||
@@ -58,6 +62,10 @@ public class RequestDataDTO {
|
||||
profileDB = request.getHeader(CommonConstants.PROFILE_DB);
|
||||
}
|
||||
|
||||
if (request != null && request.getHeader(CommonConstants.COD_MDEP) != null) {
|
||||
codMdep = request.getHeader(CommonConstants.COD_MDEP);
|
||||
}
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) {
|
||||
readAuthenticationClaims(authentication);
|
||||
@@ -111,6 +119,10 @@ public class RequestDataDTO {
|
||||
return !UtilityString.isNullOrEmpty(profileDB);
|
||||
}
|
||||
|
||||
public boolean isValidCodMdep() {
|
||||
return !UtilityString.isNullOrEmpty(codMdep);
|
||||
}
|
||||
|
||||
public boolean isValidDeviceId() {
|
||||
return deviceId != null;
|
||||
}
|
||||
@@ -141,6 +153,10 @@ public class RequestDataDTO {
|
||||
return profileDB;
|
||||
}
|
||||
|
||||
public String getCodMdep() {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
public IntegryCustomerDB getCustomerDB() {
|
||||
if (UtilityString.isNullOrEmpty(profileDB))
|
||||
return null;
|
||||
|
||||
@@ -168,7 +168,11 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
UtilityDB.cloneTable(connection, sourceTable, newTable, fillNewTable, dropOldTable, renameNewTable);
|
||||
}
|
||||
|
||||
protected void dropIndex(String tableName, String indexName) throws Exception {
|
||||
protected boolean existIndex(String tableName, String indexName) throws SQLException {
|
||||
return UtilityDB.existIndex(connection, tableName, indexName);
|
||||
}
|
||||
|
||||
protected void dropIndex(String tableName, String indexName) throws SQLException {
|
||||
UtilityDB.dropIndex(connection, tableName, indexName);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20251126115627 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
if (!isCustomerDb(IntegryCustomerDB.Carelli_Winact))
|
||||
return;
|
||||
|
||||
boolean existIndex = existIndex("wtb_depo", "ux_wtb_depo_depo_default_utente");
|
||||
|
||||
if(existIndex)
|
||||
dropIndex("wtb_depo", "ux_wtb_depo_depo_default_utente");
|
||||
|
||||
executeStatement("ALTER TABLE dbo.wtb_depo\n" +
|
||||
" ALTER COLUMN user_name VARCHAR(40) NOT NULL",
|
||||
|
||||
"ALTER TABLE dbo.wtb_depo\n" +
|
||||
" ALTER COLUMN cod_mdep VARCHAR(5) NOT NULL",
|
||||
|
||||
"ALTER TABLE dbo.wtb_depo\n" +
|
||||
" ADD CONSTRAINT pk_wtb_depo\n" +
|
||||
" PRIMARY KEY (cod_mdep, user_name)");
|
||||
|
||||
if(existIndex)
|
||||
executeStatement("CREATE unique index ux_wtb_depo_depo_default_utente\n" +
|
||||
" on dbo.wtb_depo (user_name)\n" +
|
||||
" where [default_depo] = 1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.integry.ems.user;
|
||||
|
||||
import it.integry.ems.dynamic_cache.EntityCacheComponent;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
@@ -21,6 +22,9 @@ public class UserSession {
|
||||
private UserDTO currentUser;
|
||||
private MtbDepo currentUserDepo;
|
||||
|
||||
@Autowired
|
||||
private EntityCacheComponent entityCacheComponent;
|
||||
|
||||
@Autowired
|
||||
private MultiDBTransactionManager multiDBTransactionManager;
|
||||
|
||||
@@ -32,6 +36,17 @@ public class UserSession {
|
||||
try {
|
||||
currentUser = UtilityUser.getCurrentUser(multiDBTransactionManager, requestDataDTO.getUsername());
|
||||
|
||||
if (requestDataDTO.isValidCodMdep()) {
|
||||
currentUserDepo = entityCacheComponent.<MtbDepo>getCachedEntitiesStream(multiDBTransactionManager.getPrimaryConnection().getIntegryCustomerDB(),
|
||||
MtbDepo.ENTITY,
|
||||
x -> x.getCodMdep().equals(requestDataDTO.getCodMdep()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if(currentUserDepo != null)
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentUser != null)
|
||||
currentUserDepo = UtilityUser.getDefaultUserDepo(multiDBTransactionManager.getPrimaryConnection().getIntegryCustomerDB(), currentUser);
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
import it.integry.ems_model.entity.WtbDepo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -51,9 +52,6 @@ public class UserDTO implements Cloneable{
|
||||
@SqlField("user_code")
|
||||
private String userCode;
|
||||
|
||||
@SqlField("cod_mdep")
|
||||
private String codMdep;
|
||||
|
||||
@SqlField("is_attivo")
|
||||
private boolean attivo;
|
||||
|
||||
@@ -68,6 +66,8 @@ public class UserDTO implements Cloneable{
|
||||
|
||||
private List<String> availableProfiles;
|
||||
|
||||
private List<WtbDepo> availableDepoList;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@@ -203,18 +203,16 @@ public class UserDTO implements Cloneable{
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodMdep() {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
@JsonProperty("cod_mdep")
|
||||
public String getCodMdepAlias() {
|
||||
return codMdep;
|
||||
}
|
||||
public String getCodMdep() {
|
||||
if(getAvailableDepoList() != null && !getAvailableDepoList().isEmpty()) {
|
||||
return getAvailableDepoList().stream().filter(WtbDepo::getDefaultDepo)
|
||||
.findFirst()
|
||||
.orElse(getAvailableDepoList().get(0))
|
||||
.getCodMdep();
|
||||
}
|
||||
|
||||
public UserDTO setCodMdep(String codMdep) {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAttivo() {
|
||||
@@ -289,6 +287,15 @@ public class UserDTO implements Cloneable{
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<WtbDepo> getAvailableDepoList() {
|
||||
return availableDepoList;
|
||||
}
|
||||
|
||||
public UserDTO setAvailableDepoList(List<WtbDepo> availableDepoList) {
|
||||
this.availableDepoList = availableDepoList;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDTO clone() {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.user.service;
|
||||
|
||||
import it.integry.annotations.PostContextConstruct;
|
||||
import it.integry.ems.dynamic_cache.EntityCacheComponent;
|
||||
import it.integry.ems.model.IntegryApplicationEnum;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
@@ -8,8 +9,8 @@ import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.task.TaskExecutorService;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
import it.integry.ems_model.entity.WtbDepo;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHash;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -33,6 +34,9 @@ public class UserCacheService {
|
||||
@Autowired
|
||||
private TaskExecutorService taskExecutorService;
|
||||
|
||||
@Autowired
|
||||
private EntityCacheComponent entityCacheComponent;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
private final HashMap<String, List<UserDTO>> cachedUsers = new HashMap<>();
|
||||
@@ -43,7 +47,7 @@ public class UserCacheService {
|
||||
|
||||
@PostContextConstruct(priority = 10)
|
||||
private void init() {
|
||||
canStart = !UtilityDebug.isDebugExecution();
|
||||
canStart = true; //!UtilityDebug.isDebugExecution();
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
|
||||
@@ -208,22 +212,26 @@ public class UserCacheService {
|
||||
" DATEDIFF(DAY, su.password_endtime, GETDATE()) > 0 AND su.flag_password_expiring = 'S', 1,\n" +
|
||||
" 0) AS BIT) AS is_password_expired,\n" +
|
||||
" IIF(su.key_group = '3' AND su.user_code IS NULL, wc.cod_anag, su.user_code) AS user_code,\n" +
|
||||
" wd.cod_mdep,\n" +
|
||||
" CAST(IIF(ISNULL(su.flag_attivo, 'N') = 'S', 1, 0) AS BIT) AS is_attivo,\n" +
|
||||
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_dba = 'S', 1, 0) AS BIT) AS is_internal,\n" +
|
||||
" CAST(IIF(su.flag_intra_user = 'S' OR su.flag_extra_user = 'S', 1, 0) AS BIT) AS is_web,\n" +
|
||||
" '" + connection.getProfileName() + "' AS profile_db\n" +
|
||||
"FROM " + StbUser.ENTITY + " su " +
|
||||
" LEFT OUTER JOIN wtb_clie wc ON su.user_name = wc.user_name\n" +
|
||||
" LEFT OUTER JOIN wtb_depo wd ON su.user_name = wd.user_name\n" +
|
||||
" LEFT OUTER JOIN mtb_depo md ON wd.cod_mdep = md.cod_mdep\n" +
|
||||
"WHERE dbo.sys_dcd_pss(su.password) IS NOT NULL";
|
||||
|
||||
|
||||
final List<UserDTO> userDTOS = UtilityDB.executeSimpleQueryDTO(connection, sql, UserDTO.class);
|
||||
|
||||
if (userDTOS != null)
|
||||
userDTOS.forEach(x -> cache(connection.getDbName(), x));
|
||||
userDTOS.forEach(x -> {
|
||||
List<WtbDepo> availableDepoList = entityCacheComponent.getCachedEntitiesList(connection.getIntegryCustomerDB(), WtbDepo.ENTITY,
|
||||
y -> x.getUsername().equalsIgnoreCase(y.getUserName())
|
||||
);
|
||||
x.setAvailableDepoList(availableDepoList);
|
||||
|
||||
cache(connection.getDbName(), x);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
logger.error(String.format("Errore durante la retrieve degli utenti su \"%s\". %s", connection.getProfileName(), ex.getMessage()), ex);
|
||||
}
|
||||
|
||||
@@ -47,14 +47,17 @@ public class UtilityDB {
|
||||
cs.close();
|
||||
}
|
||||
|
||||
public static void dropIndex(Connection conn, String tableName, String indexName ) throws SQLException {
|
||||
|
||||
public static boolean existIndex(Connection conn, String tableName, String indexName ) throws SQLException {
|
||||
String sql = Query.format("SELECT CAST(Count(*) as bit) from sys.sysindexes where name = %s and object_name(id) = %s", indexName, tableName);
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
}
|
||||
|
||||
boolean existIndex = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
public static void dropIndex(Connection conn, String tableName, String indexName ) throws SQLException {
|
||||
boolean existIndex = existIndex(conn, tableName, indexName);
|
||||
|
||||
if (existIndex) {
|
||||
sql = String.format("DROP INDEX %s ON dbo.%s", indexName, tableName);
|
||||
String sql = String.format("DROP INDEX %s ON dbo.%s", indexName, tableName);
|
||||
Statement statement = conn.createStatement();
|
||||
|
||||
statement.execute(sql);
|
||||
|
||||
Reference in New Issue
Block a user