Aggiornate migration per nuova MVW
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:
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@@ -2,6 +2,5 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/ts" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -20,7 +20,7 @@ public enum IntegryCustomerDB {
|
|||||||
Auricchio_AuricchioSons("auricchiosons"),
|
Auricchio_AuricchioSons("auricchiosons"),
|
||||||
|
|
||||||
|
|
||||||
Biolevante_Biolevante("biolevante"),
|
Biolevante_Biolevante("biolevante_peppe"),
|
||||||
Biolevante_BiolevanteStorico("biolevante_storico"),
|
Biolevante_BiolevanteStorico("biolevante_storico"),
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class MigrationMvwSitArtUdcDetInventarioDTO {
|
|||||||
|
|
||||||
executeStatement(connection, Query.format(
|
executeStatement(connection, Query.format(
|
||||||
"INSERT INTO mtb_colr (gestione, ser_collo, num_collo, data_collo, riga, cod_mart, cod_col, cod_tagl, partita_mag, gestione_rif, data_collo_rif, ser_collo_rif, num_collo_rif, datetime_row,\n" +
|
"INSERT INTO mtb_colr (gestione, ser_collo, num_collo, data_collo, riga, cod_mart, cod_col, cod_tagl, partita_mag, gestione_rif, data_collo_rif, ser_collo_rif, num_collo_rif, datetime_row,\n" +
|
||||||
" cod_jcom, qta_col, num_cnf, qta_cnf)" +
|
" cod_jcom, qta_col, num_cnf, qta_cnf, barcode_ul_out, cod_mdep_out, posizione_out)" +
|
||||||
" SELECT {} AS gestione,\n" +
|
" SELECT {} AS gestione,\n" +
|
||||||
" {} AS ser_collo,\n" +
|
" {} AS ser_collo,\n" +
|
||||||
" {} AS num_collo,\n" +
|
" {} AS num_collo,\n" +
|
||||||
@@ -104,7 +104,10 @@ public class MigrationMvwSitArtUdcDetInventarioDTO {
|
|||||||
" v.cod_jcom,\n" +
|
" v.cod_jcom,\n" +
|
||||||
" v.qta_col,\n" +
|
" v.qta_col,\n" +
|
||||||
" v.num_cnf,\n" +
|
" v.num_cnf,\n" +
|
||||||
" v.qta_cnf\n" +
|
" v.qta_cnf,\n" +
|
||||||
|
" v.barcode_ul AS barcode_ul_out,\n" +
|
||||||
|
" v.cod_mdep AS cod_mdep_out,\n" +
|
||||||
|
" v.posizione AS posizione_out\n" +
|
||||||
"FROM mvw_sitart_udc_det_inventario v\n" +
|
"FROM mvw_sitart_udc_det_inventario v\n" +
|
||||||
" INNER JOIN (SELECT ser_collo,\n" +
|
" INNER JOIN (SELECT ser_collo,\n" +
|
||||||
" gestione,\n" +
|
" gestione,\n" +
|
||||||
|
|||||||
@@ -72,8 +72,4 @@ public class Migration_20250403174531 extends BaseMigration implements Migration
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,15 @@ import it.integry.ems.migration.dto.common.MigrationMvwSitArtUdcDetInventarioDTO
|
|||||||
|
|
||||||
public class Migration_20250417110238 extends BaseMigration implements MigrationModelInterface {
|
public class Migration_20250417110238 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
//Migration per aggiornare la view mvw_sitart_udc_det_inventario
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void up() throws Exception {
|
public void up() throws Exception {
|
||||||
if (isHistoryDB())
|
if (isHistoryDB())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!isCustomerDb(IntegryCustomerDB.Maggio_MaggioSrl))
|
if (!isCustomerDb(IntegryCustomerDB.Maggio_MaggioSrl) &&
|
||||||
|
!isCustomerDb(IntegryCustomerDB.Biolevante_Biolevante))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Aggiorno la view mvw_mtb_colr_with_giacenza
|
//Aggiorno la view mvw_mtb_colr_with_giacenza
|
||||||
|
|||||||
@@ -126,5 +126,11 @@
|
|||||||
<artifactId>fixedformat4j</artifactId>
|
<artifactId>fixedformat4j</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.datafaker</groupId>
|
||||||
|
<artifactId>datafaker</artifactId>
|
||||||
|
<version>1.9.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package it.integry.ems.system.controller;
|
||||||
|
|
||||||
|
import it.integry.ems.response.ServiceRestResponse;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems.system.service.AnonymizerService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Scope("request")
|
||||||
|
@RequestMapping("anonymizer")
|
||||||
|
public class AnonymizerController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MultiDBTransactionManager multiDBTransactionManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AnonymizerService anonymizerService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("clienti")
|
||||||
|
public ServiceRestResponse anonymizeAnagraficheClienti() throws Exception {
|
||||||
|
anonymizerService.anonymizeAnagraficheClienti(multiDBTransactionManager);
|
||||||
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("fornitori")
|
||||||
|
public ServiceRestResponse anonymizeAnagraficheFornitori() throws Exception {
|
||||||
|
anonymizerService.anonymizeAnagraficheFornitori(multiDBTransactionManager);
|
||||||
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("utenti")
|
||||||
|
public ServiceRestResponse anonymizeAnagraficheUtenti() throws Exception {
|
||||||
|
anonymizerService.anonymizeAnagraficheUtenti(multiDBTransactionManager);
|
||||||
|
return ServiceRestResponse.createPositiveResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package it.integry.ems.system.service;
|
||||||
|
|
||||||
|
import it.integry.ems.datasource.DataSource;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems_model.entity.StbUser;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
|
import it.integry.ems_model.utility.UtilityDB;
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AnonymizerService {
|
||||||
|
|
||||||
|
|
||||||
|
private final Faker faker = new Faker(new Locale("it"));
|
||||||
|
private final Map<String, Map<String, String>> databasesMappingCache = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
public void anonymizeAnagraficheClienti(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void anonymizeAnagraficheFornitori(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
// Implement anonymization logic for suppliers
|
||||||
|
}
|
||||||
|
|
||||||
|
public void anonymizeAnagraficheUtenti(MultiDBTransactionManager multiDBTransactionManager) throws Exception {
|
||||||
|
|
||||||
|
String sqlSelectUtenti = "SELECT * FROM stb_user";
|
||||||
|
List<StbUser> stbUsers = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sqlSelectUtenti, StbUser.class);
|
||||||
|
|
||||||
|
List<StbUser> stbUsersToAnonymize = stbUsers.stream()
|
||||||
|
.filter(user -> !user.getUsername().toLowerCase().startsWith("admin") &&
|
||||||
|
!user.getUsername().equalsIgnoreCase("dba") &&
|
||||||
|
!user.getUsername().equalsIgnoreCase("sa") &&
|
||||||
|
!user.getUsername().equalsIgnoreCase("collector") &&
|
||||||
|
!user.getFullName().toLowerCase().startsWith("responsabile") &&
|
||||||
|
!user.getUserName().toLowerCase().startsWith("maga") &&
|
||||||
|
!user.getUserName().toLowerCase().startsWith("pcpanel") &&
|
||||||
|
!user.getUserName().equalsIgnoreCase("super"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
stbUsersToAnonymize.forEach(stbUser -> {
|
||||||
|
try {
|
||||||
|
String fullName = getConsistentName(multiDBTransactionManager.getPrimaryDatasource(), stbUser.getFullName());
|
||||||
|
|
||||||
|
stbUser.setFullName(fullName);
|
||||||
|
|
||||||
|
String username = "";
|
||||||
|
String[] names = fullName.split(" ");
|
||||||
|
if (names.length > 1) {
|
||||||
|
username = names[0].toUpperCase().charAt(0) + names[names.length-1].toUpperCase();
|
||||||
|
} else {
|
||||||
|
username = names[0].toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
stbUser.setUserName(username);
|
||||||
|
|
||||||
|
stbUser.setOperation(OperationType.UPDATE);
|
||||||
|
|
||||||
|
|
||||||
|
stbUser.manageWithParentConnection(multiDBTransactionManager.getPrimaryConnection());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Mantieni lo stesso nome fake per lo stesso input
|
||||||
|
private String getConsistentName(DataSource datasource, String originalName) {
|
||||||
|
databasesMappingCache.putIfAbsent(datasource.getDbName(), new HashMap<>());
|
||||||
|
|
||||||
|
Map<String, String> mappingCache = databasesMappingCache.get(datasource.getDbName());
|
||||||
|
|
||||||
|
return mappingCache.computeIfAbsent(originalName,
|
||||||
|
k -> faker.name().firstName() + " " + faker.name().lastName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mantieni la stessa email fake per lo stesso input
|
||||||
|
private String getConsistentEmail(DataSource datasource, String originalEmail) {
|
||||||
|
databasesMappingCache.putIfAbsent(datasource.getDbName(), new HashMap<>());
|
||||||
|
|
||||||
|
Map<String, String> mappingCache = databasesMappingCache.get(datasource.getDbName());
|
||||||
|
|
||||||
|
return mappingCache.computeIfAbsent(originalEmail,
|
||||||
|
k -> faker.internet().emailAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user