Finish PermMES
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,100 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.IntegryCustomer;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import it.integry.ems_model.entity.StbEditLimit;
|
||||||
|
import it.integry.ems_model.entity.StbUser;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
|
import it.integry.ems_model.utility.UtilityList;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class Migration_20250520110003 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
private static final List<String> permessiMES = Collections.singletonList(
|
||||||
|
"btnPauseProd"
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (isCustomer(IntegryCustomer.RossoGargano)
|
||||||
|
|| isCustomer(IntegryCustomer.Biolevante)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, List<String>> permissionsHashMap = new HashMap<>();
|
||||||
|
|
||||||
|
String sql = (
|
||||||
|
"SELECT DISTINCT stb_abil.user_name\n" +
|
||||||
|
"FROM stb_abil\n" +
|
||||||
|
" INNER JOIN stb_user su ON stb_abil.user_name = su.user_name\n" +
|
||||||
|
" AND su.key_group <> 1\n" +
|
||||||
|
"WHERE cod_opz = 'WG069'\n" +
|
||||||
|
" AND flag_abil = 'S'"
|
||||||
|
);
|
||||||
|
|
||||||
|
List<String> stbAbilMES = UtilityDB.executeSimpleQueryOnlyFirstColumn(advancedDataSource.getConnection(), sql);
|
||||||
|
|
||||||
|
if (!UtilityList.isNullOrEmpty(stbAbilMES)) {
|
||||||
|
for (String userName : stbAbilMES) {
|
||||||
|
permissionsHashMap.put(userName, permessiMES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permissionsHashMap.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<EntityBase> entitiesToSave = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<String>> userPermissions : permissionsHashMap.entrySet()) {
|
||||||
|
List<StbEditLimit> stbEditLimits = userPermissions.getValue().stream()
|
||||||
|
.distinct()
|
||||||
|
.map(permission -> {
|
||||||
|
StbEditLimit stbEditLimit = new StbEditLimit()
|
||||||
|
.setUserName(userPermissions.getKey())
|
||||||
|
.setGestName("PVM")
|
||||||
|
.setDwName("monitoraggio_linee_v2")
|
||||||
|
.setDwColname(permission)
|
||||||
|
.setEnabled("S")
|
||||||
|
.setVisible("S");
|
||||||
|
|
||||||
|
stbEditLimit.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
|
|
||||||
|
return stbEditLimit;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
StbUser stbUser = entitiesToSave.stream()
|
||||||
|
.map(entityBase -> (StbUser) entityBase)
|
||||||
|
.filter(stbUser1 -> stbUser1.getUserName().equalsIgnoreCase(userPermissions.getKey()))
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> {
|
||||||
|
StbUser newStbUser = new StbUser()
|
||||||
|
.setUserName(userPermissions.getKey());
|
||||||
|
|
||||||
|
newStbUser.setOperation(OperationType.NO_OP);
|
||||||
|
|
||||||
|
entitiesToSave.add(newStbUser);
|
||||||
|
|
||||||
|
return newStbUser;
|
||||||
|
});
|
||||||
|
|
||||||
|
stbUser.setStbEditLimit(stbEditLimits);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EntityBase entity : entitiesToSave) {
|
||||||
|
entity.manageWithParentConnection(advancedDataSource.getConnection());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user