Gestito update gest setup e cancellazione da stb_gest_setup_depo e wtb_gest_setup_user nelle migration
This commit is contained in:
@@ -330,17 +330,46 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
}
|
||||
|
||||
protected void updateSetupValue(String gestName, String section, String keySection, String newValue) throws Exception {
|
||||
this.updateSetupValue(gestName, section, keySection, newValue, null, null, null,
|
||||
null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
protected void updateSetupValue(String gestName, String section, String keySection, String newValue, String description, Boolean flagSync,
|
||||
String codQuery, Boolean flagUserView, Boolean flagSetupDepo, Boolean flagSetupUserWeb,
|
||||
Boolean flagTipoJson, Boolean flagTipoColore, String tipoSetup, Boolean flagMultiValue) throws Exception {
|
||||
this.updateSetupValue(gestName, section, keySection, newValue, description, flagSync, codQuery, flagUserView, flagSetupDepo,
|
||||
flagSetupUserWeb, flagTipoJson, flagTipoColore, tipoSetup, flagMultiValue, null);
|
||||
}
|
||||
|
||||
protected void updateSetupValue(String gestName, String section, String keySection, String newValue, String description, Boolean flagSync,
|
||||
String codQuery, Boolean flagUserView, Boolean flagSetupDepo, Boolean flagSetupUserWeb,
|
||||
Boolean flagTipoJson, Boolean flagTipoColore, String tipoSetup, Boolean flagMultiValue,
|
||||
String query) throws Exception {
|
||||
if (!UtilityString.isNullOrEmpty(query) && UtilityString.isNullOrEmpty(codQuery)) {
|
||||
codQuery = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(advancedDataSource.getConnection(),
|
||||
Query.format("SELECT cod_query FROM stb_gest_setup_query WHERE query_default = %s", query));
|
||||
}
|
||||
|
||||
StbGestSetup stbGestSetup = new StbGestSetup()
|
||||
.setGestName(gestName)
|
||||
.setSection(section)
|
||||
.setKeySection(keySection)
|
||||
.setValue(newValue);
|
||||
.setValue(newValue)
|
||||
.setDescription(description)
|
||||
.setFlagSync(flagSync ? "S" : "N")
|
||||
.setCodQuery(codQuery)
|
||||
.setFlagUserView(flagUserView ? "S" : "N")
|
||||
.setFlagSetupDepo(flagSetupDepo ? "S" : "N")
|
||||
.setFlagSetupUserWeb(flagSetupUserWeb ? "S" : "N")
|
||||
.setFlagTipoJson(flagTipoJson ? "S" : "N")
|
||||
.setFlagTipoColore(flagTipoColore ? "S" : "N")
|
||||
.setTipoSetup(tipoSetup)
|
||||
.setFlagMultiValue(flagMultiValue);
|
||||
|
||||
stbGestSetup.setOperation(OperationType.UPDATE);
|
||||
stbGestSetup.manageWithParentConnection(advancedDataSource.getConnection());
|
||||
}
|
||||
|
||||
|
||||
protected void addAutomatedOperation(BaseScheduledOperationDTO operation) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
||||
@@ -7,6 +7,8 @@ import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.system.dto.SqlObjectDTO;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.entity.StbGestSetup;
|
||||
import it.integry.ems_model.entity.StbGestSetupDepo;
|
||||
import it.integry.ems_model.entity.WtbGestSetupUser;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -97,60 +99,119 @@ public class SystemMigrationService {
|
||||
" public void up() throws Exception {\n" +
|
||||
" if (isHistoryDB())\n" +
|
||||
" return;\n" +
|
||||
"\n" +
|
||||
"\n");
|
||||
|
||||
|
||||
for (StbGestSetup setup:entityBaseList){
|
||||
|
||||
for (StbGestSetup setup : entityBaseList) {
|
||||
String operation;
|
||||
|
||||
if (setup.getOperation() == OperationType.DELETE) {
|
||||
operation = formatSetup("deleteSetup(%s, %s, %s);", setup.getGestName(), setup.getSection(), setup.getKeySection());
|
||||
operation = this.deleteFromGestSetupTableOperation(
|
||||
StbGestSetupDepo.ENTITY,
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection()
|
||||
);
|
||||
|
||||
classBuilder.append("\t\t" + operation)
|
||||
classBuilder.append("\n").append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
} if (setup.getOperation() == OperationType.UPDATE) {
|
||||
operation = formatSetup("updateSetupValue(%s, %s, %s, %s);", setup.getGestName(), setup.getSection(), setup.getKeySection(), setup.getValue());
|
||||
|
||||
classBuilder.append("\t\t" + operation)
|
||||
operation = this.deleteFromGestSetupTableOperation(
|
||||
WtbGestSetupUser.ENTITY,
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection()
|
||||
);
|
||||
|
||||
classBuilder.append("\n").append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
|
||||
operation = formatSetup("\ndeleteSetup(%s, %s, %s);", setup.getGestName(), setup.getSection(), setup.getKeySection());
|
||||
|
||||
classBuilder.append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
} else if (setup.getOperation() == OperationType.UPDATE) {
|
||||
operation = formatSetup(
|
||||
"updateSetupValue(%s, %s, %s, %s,\n%s, %s, %s, %s, %s, %s,\n%s, %s, %s, %s, %s);",
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection(),
|
||||
setup.getValue(),
|
||||
setup.getDescription(),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSync(), "S"),
|
||||
setup.getCodQuery(),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagUserView(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSetupDepo(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSetupUserWeb(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagTipoJson(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagTipoColore(), "S"),
|
||||
setup.getTipoSetup(),
|
||||
setup.getFlagMultiValue() != null && setup.getFlagMultiValue(),
|
||||
setup.getQueryDefault()
|
||||
);
|
||||
|
||||
classBuilder.append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
|
||||
if (setup.getFlagSetupDepo().equalsIgnoreCase("N")) {
|
||||
operation = this.deleteFromGestSetupTableOperation(
|
||||
StbGestSetupDepo.ENTITY,
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection()
|
||||
);
|
||||
|
||||
classBuilder.append("\n").append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
}
|
||||
|
||||
if (setup.getFlagSetupUserWeb().equalsIgnoreCase("N")) {
|
||||
operation = this.deleteFromGestSetupTableOperation(
|
||||
WtbGestSetupUser.ENTITY,
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection()
|
||||
);
|
||||
|
||||
classBuilder.append("\n").append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
}
|
||||
} else {
|
||||
if (setup.getOperation() == OperationType.DELETE_THEN_INSERT) {
|
||||
String keySection = UtilityHashMap.getValueIfExists(setup.getOldPk(), "key_section");
|
||||
operation = formatSetup("deleteSetup(%s, %s, %s);", setup.getGestName(), setup.getSection(), keySection);
|
||||
|
||||
classBuilder.append("\t\t" + operation)
|
||||
classBuilder.append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
}
|
||||
if (!UtilityString.isNullOrEmpty(setup.getQueryDefault())){
|
||||
if (!UtilityString.isNullOrEmpty(setup.getQueryDefault())) {
|
||||
operation =
|
||||
formatSetup(
|
||||
"createSetupQuery(%s, %s, %s);",
|
||||
setup.getCodQuery(),setup.getCodQuery(),setup.getQueryDefault());
|
||||
classBuilder.append("\t\t" + operation)
|
||||
setup.getCodQuery(), setup.getCodQuery(), setup.getQueryDefault());
|
||||
classBuilder.append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
}
|
||||
|
||||
operation =
|
||||
formatSetup(
|
||||
"createSetup(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
|
||||
"createSetup(%s, %s, %s, %s,\n%s, %s, %s, %s, %s,\n%s, %s, %s, %s, %s, %s);",
|
||||
setup.getGestName(),
|
||||
setup.getSection(),
|
||||
setup.getKeySection(),
|
||||
setup.getValue(),
|
||||
setup.getDescription(),
|
||||
setup.getFlagSync().equalsIgnoreCase("S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSync(), "S"),
|
||||
setup.getCodQuery(),
|
||||
setup.getFlagUserView().equalsIgnoreCase("S"),
|
||||
setup.getFlagSetupDepo().equalsIgnoreCase("S"),
|
||||
setup.getFlagSetupUserWeb().equalsIgnoreCase("S"),
|
||||
setup.getFlagTipoJson().equalsIgnoreCase("S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagTipoColore(),"S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagUserView(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSetupDepo(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagSetupUserWeb(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagTipoJson(), "S"),
|
||||
UtilityString.equalsIgnoreCase(setup.getFlagTipoColore(), "S"),
|
||||
setup.getTipoSetup(),
|
||||
setup.getFlagMultiValue()==null?false:setup.getFlagMultiValue(),
|
||||
setup.getQueryDefault() );
|
||||
setup.getFlagMultiValue() != null && setup.getFlagMultiValue(),
|
||||
setup.getQueryDefault());
|
||||
|
||||
classBuilder.append("\t\t" + operation)
|
||||
classBuilder.append(" ").append(operation)
|
||||
.append("\r\n");
|
||||
}
|
||||
}
|
||||
@@ -171,11 +232,13 @@ public class SystemMigrationService {
|
||||
final String migrationsJavaPath = baseProjectPath + "java\\it\\integry\\ems\\migration\\model\\";
|
||||
final String migrationsJavaFile = migrationsJavaPath + migrationClassName + ".java";
|
||||
writeContentToFile(migrationsJavaFile, classBuilder.toString(), true);
|
||||
|
||||
logger.info(String.format("Created migration file: %s", migrationClassName));
|
||||
}
|
||||
|
||||
private static String formatSetup(String string, Object... params) {
|
||||
String[] formattedParams = new String[params.length];
|
||||
for(int i = 0; i < params.length; i++) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (params[i] == null || params[i].equals(EmsRestConstants.NULL)) {
|
||||
formattedParams[i] = "null";
|
||||
} else {
|
||||
@@ -230,8 +293,6 @@ public class SystemMigrationService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void createMigrationFileFromSqlObjects(List<SqlObjectDTO> sqlObjects) throws IOException {
|
||||
|
||||
String migrationClassName = "Migration_" + CommonConstants.TIMESTAMP_FORMATTER.format(UtilityLocalDate.getNowTime());
|
||||
@@ -258,10 +319,10 @@ public class SystemMigrationService {
|
||||
String definition = sqlObject.getDefinition().trim();
|
||||
definition = definition
|
||||
.replace("\r\n", "\n")
|
||||
.replace("\n", "\\n\" + \n\t\t\t\t\"");
|
||||
.replace("\n", "\\n\" + \n \"");
|
||||
|
||||
|
||||
classBuilder.append("\t\tcreateOrUpdate")
|
||||
classBuilder.append(" createOrUpdate")
|
||||
.append(typeName)
|
||||
.append("(\"").append(sqlObject.getName()).append("\"").append(", ")
|
||||
.append("\"").append(definition).append("\");")
|
||||
@@ -279,9 +340,6 @@ public class SystemMigrationService {
|
||||
"}\n");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
String executionPath = new File(BaseMigration.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();
|
||||
final String baseProjectPath = executionPath.substring(0, executionPath.indexOf("ems-engine\\target")) + "ems-core\\src\\main\\";
|
||||
final String migrationsJavaPath = baseProjectPath + "java\\it\\integry\\ems\\migration\\model\\";
|
||||
@@ -291,9 +349,21 @@ public class SystemMigrationService {
|
||||
logger.info(String.format("Created migration file: %s", migrationClassName));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String deleteFromGestSetupTableOperation(String table, String gestName, String section, String keySection) {
|
||||
return String.format(
|
||||
"executeStatement(%s);",
|
||||
Query.format(
|
||||
"\"DELETE\\n\" +\n" +
|
||||
"\"FROM " + table + "\\n\" +\n" +
|
||||
"\"WHERE gest_name = %s\\n\" +\n" +
|
||||
"\" AND section = %s\\n\" +\n" +
|
||||
"\" AND key_section = %s\"\n",
|
||||
gestName,
|
||||
section,
|
||||
keySection
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static void writeContentToFile(String filePath, String content, boolean overwrite) throws IOException {
|
||||
File f = new File(filePath);
|
||||
|
||||
Reference in New Issue
Block a user