Creato sistema di aggiornamento dei menu automatico

This commit is contained in:
2024-02-23 12:08:23 +01:00
parent 02ac9d1559
commit 9f1489a9c8
17 changed files with 904 additions and 50 deletions

View File

@@ -35,6 +35,12 @@ public class CommonConstants {
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(CommonConstants.TIME_FORMAT)
.withZone(ZoneId.systemDefault());
public static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
.withZone(ZoneId.systemDefault());
public static final DateTimeFormatter DATESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyMMdd")
.withZone(ZoneId.systemDefault());
public static final DateTimeFormatter DATE_YMD_DASHED_FORMATTER = DateTimeFormatter.ofPattern(CommonConstants.DATE_FORMAT_YMD)
.withZone(ZoneId.systemDefault());

View File

@@ -2,6 +2,7 @@ package it.integry.ems.dto;
import it.integry.ems_model.base.EntityBase;
import java.lang.reflect.Field;
import java.util.List;
public class EntityHierarchyDTO {
@@ -9,6 +10,7 @@ public class EntityHierarchyDTO {
private Class<? extends EntityBase> clazz;
private String entityName;
private String tableName;
private Field field;
private List<EntityHierarchyDTO> children;
public Class<? extends EntityBase> getClazz() {
@@ -36,6 +38,15 @@ public class EntityHierarchyDTO {
this.tableName = tableName;
}
public Field getField() {
return field;
}
public EntityHierarchyDTO setField(Field field) {
this.field = field;
return this;
}
public List<EntityHierarchyDTO> getChildren() {
return children;
}

View File

@@ -0,0 +1,70 @@
package it.integry.ems.menu;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.integry.common.var.CommonConstants;
import it.integry.ems.menu.dto.MenuConfigDTO;
import it.integry.ems.menu.dto.StbMenuDTO;
import it.integry.ems.menu.dto.StbMenuOpzDTO;
import it.integry.ems.menu.dto.StbTipoAziendaDTO;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityLocalDate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class MenuStaticCreator {
public static void main(String[] args) throws Exception {
System.out.println("Running the Menu UPDATE");
String connectionString = String.format("jdbc:sqlserver://%s;databaseName=%s;applicationName=%s", "SERVERDB2019", "studioml", "IntelliJ Connection");
String username = "sa";
String password = "sa";
Connection connection = DriverManager.getConnection(connectionString, username, password);
connection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_UNCOMMITTED);
connection.setAutoCommit(false);
final String baseProjectPath = new File("").getAbsolutePath() + "\\ems-core\\src\\main\\";
final String menuJsonResourceFolder = baseProjectPath + "resources\\menus\\";
ObjectMapper jsonObjectMapper = new ObjectMapper();
final List<StbMenuOpzDTO> stbMenuOpzs = UtilityDB.executeSimpleQueryDTO(connection, "SELECT * FROM stb_menu_opz", StbMenuOpzDTO.class);
final List<StbTipoAziendaDTO> stbTipoAziendas = UtilityDB.executeSimpleQueryDTO(connection, "SELECT * FROM stb_tipo_azienda", StbTipoAziendaDTO.class);
final List<StbMenuDTO> stbMenus = UtilityDB.executeSimpleQueryDTO(connection, "SELECT * FROM stb_menu", StbMenuDTO.class);
final Map<String, List<StbMenuDTO>> menusByAzienda = stbMenus.stream().collect(Collectors.groupingBy(StbMenuDTO::getTipoAzienda));
MenuConfigDTO menuConfigDTO = new MenuConfigDTO(Integer.parseInt(CommonConstants.DATESTAMP_FORMATTER.format(UtilityLocalDate.getNow())))
.setStbMenuOpz(stbMenuOpzs)
.setStbTipoAzienda(stbTipoAziendas)
.setMenusByAzienda(menusByAzienda);
writeContentToFile(menuJsonResourceFolder + "menu_config.json", jsonObjectMapper.writeValueAsString(menuConfigDTO), true);
connection.close();
}
private static void writeContentToFile(String filePath, String content, boolean overwrite) throws IOException {
File f = new File(filePath);
if (overwrite && f.exists()) f.delete();
FileOutputStream outputStream = new FileOutputStream(filePath);
byte[] strToBytes = content.getBytes();
outputStream.write(strToBytes);
outputStream.close();
}
}

View File

@@ -0,0 +1,33 @@
package it.integry.ems.menu.controller;
import it.integry.common.var.CommonConstants;
import it.integry.ems.menu.service.MenuConfigurationService;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
@RestController
@Scope("request")
@RequestMapping("system/menu")
public class MenuConfigurationController {
private final Logger logger = LogManager.getLogger();
@Autowired
private MenuConfigurationService menuConfigurationService;
@Autowired
private MultiDBTransactionManager multiDBTransactionManager;
@RequestMapping(value = "refresh", method = RequestMethod.POST)
public @ResponseBody
ServiceRestResponse refresh(@RequestParam(CommonConstants.PROFILE_DB) String profileDB) throws Exception {
menuConfigurationService.refresh(multiDBTransactionManager.getPrimaryConnection());
return ServiceRestResponse.createPositiveResponse();
}
}

View File

@@ -0,0 +1,55 @@
package it.integry.ems.menu.dto;
import java.util.List;
import java.util.Map;
public class MenuConfigDTO {
private int version;
private List<StbMenuOpzDTO> stbMenuOpz;
private List<StbTipoAziendaDTO> stbTipoAzienda;
private Map<String, List<StbMenuDTO>> menusByAzienda;
public MenuConfigDTO() {
}
public MenuConfigDTO(int version) {
this.version = version;
}
public int getVersion() {
return version;
}
public MenuConfigDTO setVersion(int version) {
this.version = version;
return this;
}
public List<StbMenuOpzDTO> getStbMenuOpz() {
return stbMenuOpz;
}
public MenuConfigDTO setStbMenuOpz(List<StbMenuOpzDTO> stbMenuOpz) {
this.stbMenuOpz = stbMenuOpz;
return this;
}
public List<StbTipoAziendaDTO> getStbTipoAzienda() {
return stbTipoAzienda;
}
public MenuConfigDTO setStbTipoAzienda(List<StbTipoAziendaDTO> stbTipoAzienda) {
this.stbTipoAzienda = stbTipoAzienda;
return this;
}
public Map<String, List<StbMenuDTO>> getMenusByAzienda() {
return menusByAzienda;
}
public MenuConfigDTO setMenusByAzienda(Map<String, List<StbMenuDTO>> menusByAzienda) {
this.menusByAzienda = menusByAzienda;
return this;
}
}

View File

@@ -0,0 +1,282 @@
package it.integry.ems.menu.dto;
import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.entity.StbMenu;
public class StbMenuDTO {
private String type = "stb_menu";
@SqlField(value = "cod_opz", maxLength = 5, nullable = false)
private String codOpz;
@SqlField(value = "cod_parent", maxLength = 5, nullable = false)
private String codParent;
@SqlField(value = "tipo_azienda", maxLength = 40, nullable = false)
private String tipoAzienda;
@SqlField(value = "descrizione", maxLength = 255, nullable = true)
private String descrizione;
@SqlField(value = "descrizione_estesa", maxLength = 8000, nullable = true)
private String descrizioneEstesa;
@SqlField(value = "entity_name", maxLength = 40, nullable = true)
private String entityName;
@SqlField(value = "flag_attivo", maxLength = 1, nullable = true, defaultObjectValue = "S")
private String flagAttivo;
@SqlField(value = "flag_printer_setup", maxLength = 1, nullable = true, defaultObjectValue = "N")
private String flagPrinterSetup;
@SqlField(value = "gest_name", maxLength = 40, nullable = true)
private String gestName;
@SqlField(value = "note", maxLength = 255, nullable = true)
private String note;
@SqlField(value = "object_type", maxLength = 5, nullable = true)
private String objectType;
@SqlField(value = "open_type", maxLength = 1, nullable = true)
private String openType;
@SqlField(value = "parameter", maxLength = 255, nullable = true)
private String parameter;
@SqlField(value = "picture_menu", maxLength = 1024, nullable = true)
private String pictureMenu;
@SqlField(value = "picture_select", maxLength = 1024, nullable = true)
private String pictureSelect;
@SqlField(value = "pos", nullable = true)
private Integer pos;
@SqlField(value = "pos_cliente", nullable = true)
private Integer posCliente;
@SqlField(value = "pos_tipo_azienda", nullable = true)
private Integer posTipoAzienda;
@SqlField(value = "type", maxLength = -1, nullable = true, defaultObjectValue = "F")
private String menuType;
@SqlField(value = "url_descrizione", maxLength = 1024, nullable = true)
private String urlDescrizione;
public String getType() {
return type;
}
public StbMenuDTO setType(String type) {
this.type = type;
return this;
}
public String getCodOpz() {
return codOpz;
}
public StbMenuDTO setCodOpz(String codOpz) {
this.codOpz = codOpz;
return this;
}
public String getCodParent() {
return codParent;
}
public StbMenuDTO setCodParent(String codParent) {
this.codParent = codParent;
return this;
}
public String getTipoAzienda() {
return tipoAzienda;
}
public StbMenuDTO setTipoAzienda(String tipoAzienda) {
this.tipoAzienda = tipoAzienda;
return this;
}
public String getDescrizione() {
return descrizione;
}
public StbMenuDTO setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
public String getDescrizioneEstesa() {
return descrizioneEstesa;
}
public StbMenuDTO setDescrizioneEstesa(String descrizioneEstesa) {
this.descrizioneEstesa = descrizioneEstesa;
return this;
}
public String getEntityName() {
return entityName;
}
public StbMenuDTO setEntityName(String entityName) {
this.entityName = entityName;
return this;
}
public String getFlagAttivo() {
return flagAttivo;
}
public StbMenuDTO setFlagAttivo(String flagAttivo) {
this.flagAttivo = flagAttivo;
return this;
}
public String getFlagPrinterSetup() {
return flagPrinterSetup;
}
public StbMenuDTO setFlagPrinterSetup(String flagPrinterSetup) {
this.flagPrinterSetup = flagPrinterSetup;
return this;
}
public String getGestName() {
return gestName;
}
public StbMenuDTO setGestName(String gestName) {
this.gestName = gestName;
return this;
}
public String getNote() {
return note;
}
public StbMenuDTO setNote(String note) {
this.note = note;
return this;
}
public String getObjectType() {
return objectType;
}
public StbMenuDTO setObjectType(String objectType) {
this.objectType = objectType;
return this;
}
public String getOpenType() {
return openType;
}
public StbMenuDTO setOpenType(String openType) {
this.openType = openType;
return this;
}
public String getParameter() {
return parameter;
}
public StbMenuDTO setParameter(String parameter) {
this.parameter = parameter;
return this;
}
public String getPictureMenu() {
return pictureMenu;
}
public StbMenuDTO setPictureMenu(String pictureMenu) {
this.pictureMenu = pictureMenu;
return this;
}
public String getPictureSelect() {
return pictureSelect;
}
public StbMenuDTO setPictureSelect(String pictureSelect) {
this.pictureSelect = pictureSelect;
return this;
}
public Integer getPos() {
return pos;
}
public StbMenuDTO setPos(Integer pos) {
this.pos = pos;
return this;
}
public Integer getPosCliente() {
return posCliente;
}
public StbMenuDTO setPosCliente(Integer posCliente) {
this.posCliente = posCliente;
return this;
}
public Integer getPosTipoAzienda() {
return posTipoAzienda;
}
public StbMenuDTO setPosTipoAzienda(Integer posTipoAzienda) {
this.posTipoAzienda = posTipoAzienda;
return this;
}
public String getMenuType() {
return menuType;
}
public StbMenuDTO setMenuType(String menuType) {
this.menuType = menuType;
return this;
}
public String getUrlDescrizione() {
return urlDescrizione;
}
public StbMenuDTO setUrlDescrizione(String urlDescrizione) {
this.urlDescrizione = urlDescrizione;
return this;
}
public StbMenu toEntity() {
return new StbMenu()
.setCodOpz(getCodOpz())
.setCodParent(getCodParent())
.setTipoAzienda(getTipoAzienda())
.setDescrizione(getDescrizione())
.setDescrizioneEstesa(getDescrizioneEstesa())
.setEntityName(getEntityName())
.setFlagAttivo(getFlagAttivo())
.setFlagPrinterSetup(getFlagPrinterSetup())
.setGestName(getGestName())
.setNote(getNote())
.setObjectType(getObjectType())
.setOpenType(getOpenType())
.setParameter(getParameter())
.setPictureMenu(getPictureMenu())
.setPictureSelect(getPictureSelect())
.setPos(getPos())
.setPosCliente(getPosCliente())
.setPosTipoAzienda(getPosTipoAzienda())
.setMenuType(getMenuType())
.setUrlDescrizione(getUrlDescrizione());
}
}

View File

@@ -0,0 +1,179 @@
package it.integry.ems.menu.dto;
import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.entity.StbMenuOpz;
public class StbMenuOpzDTO {
private String type = "stb_menu_opz";
@SqlField(value = "cod_opz", maxLength = 5, nullable = false)
private String codOpz;
@SqlField(value = "descrizione", maxLength = 255, nullable = false)
private String descrizione;
@SqlField(value = "entity_name", maxLength = 40, nullable = true)
private String entityName;
@SqlField(value = "flag_printer_setup", maxLength = 1, nullable = true, defaultObjectValue = "N")
private String flagPrinterSetup;
@SqlField(value = "gest_name", maxLength = 40, nullable = true)
private String gestName;
@SqlField(value = "is_deprecated", maxLength = 1, nullable = false, defaultObjectValue = "N")
private String isDeprecated;
@SqlField(value = "note", maxLength = 255, nullable = true)
private String note;
@SqlField(value = "object_type", maxLength = 5, nullable = true)
private String objectType;
@SqlField(value = "open_type", maxLength = 1, nullable = true)
private String openType;
@SqlField(value = "parameter", maxLength = 255, nullable = true)
private String parameter;
@SqlField(value = "picture_menu", maxLength = 1024, nullable = true)
private String pictureMenu;
@SqlField(value = "picture_select", maxLength = 1024, nullable = true)
private String pictureSelect;
public String getType() {
return type;
}
public StbMenuOpzDTO setType(String type) {
this.type = type;
return this;
}
public String getCodOpz() {
return codOpz;
}
public StbMenuOpzDTO setCodOpz(String codOpz) {
this.codOpz = codOpz;
return this;
}
public String getDescrizione() {
return descrizione;
}
public StbMenuOpzDTO setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
public String getEntityName() {
return entityName;
}
public StbMenuOpzDTO setEntityName(String entityName) {
this.entityName = entityName;
return this;
}
public String getFlagPrinterSetup() {
return flagPrinterSetup;
}
public StbMenuOpzDTO setFlagPrinterSetup(String flagPrinterSetup) {
this.flagPrinterSetup = flagPrinterSetup;
return this;
}
public String getGestName() {
return gestName;
}
public StbMenuOpzDTO setGestName(String gestName) {
this.gestName = gestName;
return this;
}
public String getIsDeprecated() {
return isDeprecated;
}
public StbMenuOpzDTO setIsDeprecated(String isDeprecated) {
this.isDeprecated = isDeprecated;
return this;
}
public String getNote() {
return note;
}
public StbMenuOpzDTO setNote(String note) {
this.note = note;
return this;
}
public String getObjectType() {
return objectType;
}
public StbMenuOpzDTO setObjectType(String objectType) {
this.objectType = objectType;
return this;
}
public String getOpenType() {
return openType;
}
public StbMenuOpzDTO setOpenType(String openType) {
this.openType = openType;
return this;
}
public String getParameter() {
return parameter;
}
public StbMenuOpzDTO setParameter(String parameter) {
this.parameter = parameter;
return this;
}
public String getPictureMenu() {
return pictureMenu;
}
public StbMenuOpzDTO setPictureMenu(String pictureMenu) {
this.pictureMenu = pictureMenu;
return this;
}
public String getPictureSelect() {
return pictureSelect;
}
public StbMenuOpzDTO setPictureSelect(String pictureSelect) {
this.pictureSelect = pictureSelect;
return this;
}
public StbMenuOpz toEntity() {
return new StbMenuOpz()
.setCodOpz(getCodOpz())
.setDescrizione(getDescrizione())
.setEntityName(getEntityName())
.setFlagPrinterSetup(getFlagPrinterSetup())
.setGestName(getGestName())
.setIsDeprecated(getIsDeprecated())
.setNote(getNote())
.setObjectType(getObjectType())
.setOpenType(getOpenType())
.setParameter(getParameter())
.setPictureMenu(getPictureMenu())
.setPictureSelect(getPictureSelect());
}
}

View File

@@ -0,0 +1,49 @@
package it.integry.ems.menu.dto;
import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.entity.StbTipoAzienda;
public class StbTipoAziendaDTO {
private String type = "stb_tipo_azienda";
@SqlField(value = "tipo_azienda", maxLength = 40, nullable = false)
private String tipoAzienda;
@SqlField(value = "descrizione", maxLength = 1024)
private String descrizione;
public String getType() {
return type;
}
public StbTipoAziendaDTO setType(String type) {
this.type = type;
return this;
}
public String getTipoAzienda() {
return tipoAzienda;
}
public StbTipoAziendaDTO setTipoAzienda(String tipoAzienda) {
this.tipoAzienda = tipoAzienda;
return this;
}
public String getDescrizione() {
return descrizione;
}
public StbTipoAziendaDTO setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
public StbTipoAzienda toEntity() {
return new StbTipoAzienda()
.setTipoAzienda(getTipoAzienda())
.setDescrizione(getDescrizione());
}
}

View File

@@ -0,0 +1,122 @@
package it.integry.ems.menu.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.integry.annotations.PostContextAutowired;
import it.integry.annotations.PostContextConstruct;
import it.integry.ems.menu.dto.MenuConfigDTO;
import it.integry.ems.menu.dto.StbMenuDTO;
import it.integry.ems.menu.dto.StbMenuOpzDTO;
import it.integry.ems.menu.dto.StbTipoAziendaDTO;
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.entity.Azienda;
import it.integry.ems_model.entity.StbMenu;
import it.integry.ems_model.entity.StbMenuOpz;
import it.integry.ems_model.entity.StbTipoAzienda;
import it.integry.ems_model.types.OperationType;
import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityLocalDate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import static it.integry.ems_model.utility.UtilityDB.executeStatement;
@Service
public class MenuConfigurationService {
private final Logger logger = LogManager.getLogger();
@PostContextAutowired
private MultiDBTransactionManager multiDBTransactionManager;
@PostContextConstruct(priority = 5)
public void init() throws Exception {
logger.debug(MenuConfigurationService.class.getSimpleName() + ": Refresh menu");
final MenuConfigDTO menuConfig = loadMenuData();
for (AdvancedDataSource advancedDataSource : multiDBTransactionManager.getActiveConnections()) {
LocalDateTime startTime = UtilityLocalDate.getNowTime();
internalRefresh(advancedDataSource.getConnection(), menuConfig);
logger.debug("Menu refresh time: " + ChronoUnit.SECONDS.between(startTime, UtilityLocalDate.getNowTime()));
}
}
public void refresh(Connection connection) throws Exception {
final MenuConfigDTO menuConfig = loadMenuData();
internalRefresh(connection, menuConfig);
}
private MenuConfigDTO loadMenuData() throws IOException {
ObjectMapper jsonObjectMapper = new ObjectMapper();
ClassLoader classLoader = getClass().getClassLoader();
final URL resourceMenuConfigURL = classLoader.getResource("menus/menu_config.json");
final MenuConfigDTO menuConfig = jsonObjectMapper.readValue(resourceMenuConfigURL, MenuConfigDTO.class);
return menuConfig;
}
private void internalRefresh(Connection connection, MenuConfigDTO menuConfig) throws Exception {
final Azienda azienda = Azienda.getDefaultAzienda(connection);
int lastMenuUpd = Integer.parseInt(azienda.getLastUpgDbMenu().replace("QM", ""));
if (menuConfig.getVersion() <= lastMenuUpd)
return;
executeStatement(connection, "DELETE FROM stb_menu",
"EXECUTE dbo.DropForeignKey 'azienda', 'stb_tipo_azienda'",
"DELETE FROM stb_tipo_azienda",
"DELETE FROM stb_menu_opz");
for (StbMenuOpzDTO stbMenuOpzDto : menuConfig.getStbMenuOpz()) {
StbMenuOpz stbMenuOpz = stbMenuOpzDto.toEntity();
stbMenuOpz.setOperation(OperationType.INSERT);
stbMenuOpz.manageWithParentConnection(connection);
}
for (StbTipoAziendaDTO stbTipoAziendaDto : menuConfig.getStbTipoAzienda()) {
StbTipoAzienda stbTipoAzienda = stbTipoAziendaDto.toEntity();
stbTipoAzienda.setOperation(OperationType.INSERT);
stbTipoAzienda.manageWithParentConnection(connection);
}
List<StbMenuDTO> stbMenus = menuConfig.getMenusByAzienda().get(azienda.getTipoAzienda().toUpperCase());
for (StbMenuDTO stbMenuDto : stbMenus) {
StbMenu stbMenu = stbMenuDto.toEntity();
stbMenu.setOperation(OperationType.INSERT);
stbMenu.manageWithParentConnection(connection);
}
executeStatement(connection, "ALTER TABLE azienda ADD CONSTRAINT FK_azienda_stb_tipo_azienda FOREIGN KEY (tipo_azienda) REFERENCES stb_tipo_azienda ( tipo_azienda )",
"DELETE FROM stb_abil WHERE cod_opz not in (select cod_opz from stb_menu_opz )",
"INSERT INTO stb_Abil SELECT opz2Abil.cod_parent AS cod_opz, opz2Abil.user_name, 'S' flag_Abil, NULL gest_name\n" +
"FROM (SELECT DISTINCT opz.cod_parent, abil.user_name\n" +
" FROM stb_menu opz\n" +
" LEFT OUTER JOIN stb_menu root ON opz.cod_parent = root.cod_opz,\n" +
" stb_abil Abil,\n" +
" azienda\n" +
" WHERE opz.cod_parent <> 'ROOT'\n" +
" AND ISNULL(root.cod_parent, '') <> 'WM002'\n" +
" AND opz.cod_opz = abil.cod_opz\n" +
" AND opz.tipo_azienda = azienda.tipo_azienda\n" +
" AND abil.flag_Abil <> 'N') Opz2Abil\n" +
" LEFT OUTER JOIN stb_Abil ON stb_Abil.cod_opz = Opz2Abil.cod_parent AND stb_abil.user_name = Opz2Abil.user_name\n" +
"WHERE stb_abil.cod_opz IS NULL",
"UPDATE azienda SET last_upg_db_menu = " + UtilityDB.valueToString("QM" + menuConfig.getVersion()));
connection.commit();
}
}

View File

@@ -98,7 +98,10 @@ public class MigrationService {
continue;
try {
//LocalDateTime startTime = UtilityLocalDate.getNowTime();
executeMigration(migrationClass, advancedDataSource, settingsController, settingsModel, droolsDataCompleting);
//logger.debug("MIGRATION TIME: " + ChronoUnit.SECONDS.between(startTime, UtilityLocalDate.getNowTime()));
updateLastMigrationIntoDB(advancedDataSource, migrationNumber);
advancedDataSource.getConnection().commit();

View File

@@ -131,19 +131,20 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
this.type = null;
}
List<Field> fields = getEntityHolder().getFields(this.getClass());
for (Field field : fields) {
if (field.getAnnotation(EntityChild.class) != null) {
field.setAccessible(true);
try {
Object object = field.get(this);
if (object == null && field.getType().isAssignableFrom(List.class)) {
object = new ArrayList();
field.set(this, object);
}
} catch (IllegalAccessException ex) {
logger.error(ex);
List<Field> entityChildFields = getEntityHolder().getEntityChildFields(this.getClass());
if (entityChildFields == null) return;
for (Field field : entityChildFields) {
field.setAccessible(true);
try {
Object object = field.get(this);
if (object == null && field.getType().isAssignableFrom(List.class)) {
object = new ArrayList();
field.set(this, object);
}
} catch (IllegalAccessException ex) {
logger.error(ex);
}
}
}

View File

@@ -206,42 +206,16 @@ public class EntityPropertyHolder {
}
}
public Field getEntityChildField(Class<? extends EntityBase> parentClazz, Class<? extends EntityBase> childClass) {
final List<Field> entityChildField = getEntityChildField(parentClazz);
final Field foundField = entityChildField.stream()
.filter(x -> {
if(x.getType().isAssignableFrom(childClass)) return true;
if(x.getType().isAssignableFrom(List.class)) {
ParameterizedType type = (ParameterizedType)x.getGenericType();
Class listItemType = type.getActualTypeArguments().length > 0 ? (Class<?>) type.getActualTypeArguments()[0] : null;
if(listItemType == null) return false;
return listItemType.isAssignableFrom(childClass);
}
return false;
})
.findFirst()
.orElse(null);
return foundField;
public List<Field> getEntityChildFields(Class<? extends EntityBase> clazz) {
return this.entityHierarchyMap.stream()
.filter(x -> x.getClazz().equals(clazz))
.map(EntityHierarchyDTO::getChildren)
.flatMap(Collection::stream)
.map(EntityHierarchyDTO::getField)
.collect(Collectors.toList());
}
public Boolean isEntityChild(Class<? extends EntityBase> clazz, String childName) {
Boolean isChild = false;
List<Field> children = getEntityChildField(clazz);
for (Field child : children) {
if (child.getName().equals(childName)) {
isChild = true;
break;
}
}
return isChild;
}
public List<EntityBase> getEntityChain(List<? extends EntityBase> entityList, Connection conn, EntityBase testata) throws Exception {
List<EntityBase> chain = new ArrayList<EntityBase>();
@@ -536,6 +510,7 @@ public class EntityPropertyHolder {
dto.setEntityName(childEntity.getSimpleName());
dto.setTableName(childEntity.getAnnotation(Table.class).value());
dto.setChildren(getEntityChildren(childEntity));
dto.setField(field);
children.add(dto);
}
}

View File

@@ -7,14 +7,16 @@ import it.integry.ems_model.annotation.PK;
import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.annotation.Table;
import it.integry.ems_model.base.EntityBase;
import it.integry.ems_model.db.ResultSetMapper;
import it.integry.ems_model.utility.UtilityDB;
import org.kie.api.definition.type.PropertyReactive;
import java.math.BigDecimal;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.HashMap;
import it.integry.ems_model.annotation.FK;
@Master
@PropertyReactive
@@ -123,6 +125,9 @@ public class Azienda extends EntityBase {
@SqlField(value = "last_upg_sp", maxLength = 40, nullable = true)
private String lastUpgSp;
@SqlField(value = "last_upg_db_menu", maxLength = 10, nullable = false)
private String lastUpgDbMenu;
@SqlField(value = "sito_web", maxLength = 255, nullable = true)
private String sitoWeb;
@@ -559,6 +564,15 @@ public class Azienda extends EntityBase {
this.lastUpgSp = lastUpgSp;
}
public String getLastUpgDbMenu() {
return lastUpgDbMenu;
}
public Azienda setLastUpgDbMenu(String lastUpgDbMenu) {
this.lastUpgDbMenu = lastUpgDbMenu;
return this;
}
public String getSitoWeb() {
return sitoWeb;
}

View File

@@ -6,7 +6,6 @@ import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.annotation.Table;
import it.integry.ems_model.base.EntityBase;
import org.kie.api.definition.type.PropertyReactive;
import it.integry.ems_model.annotation.FK;
@PropertyReactive
@Table(StbMenuOpz.ENTITY)
@@ -30,7 +29,7 @@ public class StbMenuOpz extends EntityBase {
@SqlField(value = "flag_printer_setup", maxLength = 1, nullable = true, defaultObjectValue = "N")
private String flagPrinterSetup;
@SqlField(value = "gest_name", maxLength = 40, nullable = true)
@SqlField(value = "gest_name", maxLength = 80, nullable = true)
private String gestName;
@SqlField(value = "is_deprecated", maxLength = 1, nullable = false, defaultObjectValue = "N")

View File

@@ -0,0 +1,44 @@
package it.integry.ems_model.entity;
import com.fasterxml.jackson.annotation.JsonTypeName;
import it.integry.ems_model.annotation.Master;
import it.integry.ems_model.annotation.PK;
import it.integry.ems_model.annotation.SqlField;
import it.integry.ems_model.annotation.Table;
import it.integry.ems_model.base.EntityBase;
import org.kie.api.definition.type.PropertyReactive;
@Master
@PropertyReactive
@Table(StbTipoAzienda.ENTITY)
@JsonTypeName(StbTipoAzienda.ENTITY)
public class StbTipoAzienda extends EntityBase {
public static final String ENTITY = "stb_tipo_azienda";
private static final long serialVerionUID = 1L;
@PK
@SqlField(value = "tipo_azienda", maxLength = 40, nullable = false)
private String tipoAzienda;
@SqlField(value = "descrizione", maxLength = 1024)
private String descrizione;
public String getTipoAzienda() {
return tipoAzienda;
}
public StbTipoAzienda setTipoAzienda(String tipoAzienda) {
this.tipoAzienda = tipoAzienda;
return this;
}
public String getDescrizione() {
return descrizione;
}
public StbTipoAzienda setDescrizione(String descrizione) {
this.descrizione = descrizione;
return this;
}
}

View File

@@ -459,6 +459,16 @@ public class UtilityDB {
return stringXML;
}
public static void executeStatement(Connection connection, String... sqls) throws SQLException {
Statement statement = connection.createStatement();
for (String sql : sqls) {
statement.execute(sql);
}
statement.close();
}
@NotNull
public static List<HashMap<String, Object>> executeSimpleQuery(Connection conn, String querySql) throws SQLException {
try (PreparedStatement ps = conn.prepareStatement(querySql);

File diff suppressed because one or more lines are too long