Cambiato caricamento iniziale del SettingsModel e di BasicConnectionPool
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:
@@ -56,6 +56,7 @@ public class EmsCoreDBLoader {
|
|||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
this.settingsController.addOnConfigUpdated(() -> {
|
this.settingsController.addOnConfigUpdated(() -> {
|
||||||
try {
|
try {
|
||||||
|
connectionPool.init();
|
||||||
load(null);
|
load(null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -64,8 +65,6 @@ public class EmsCoreDBLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load(final RunnableArgsThrowable<MultiDBTransactionManager> onComplete) throws Exception {
|
public void load(final RunnableArgsThrowable<MultiDBTransactionManager> onComplete) throws Exception {
|
||||||
connectionPool.init();
|
|
||||||
|
|
||||||
taskExecutorService.executeTask(() -> {
|
taskExecutorService.executeTask(() -> {
|
||||||
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionPool)){
|
try (MultiDBTransactionManager multiDBTransactionManager = new MultiDBTransactionManager(connectionPool)){
|
||||||
discoverAllConnections(multiDBTransactionManager);
|
discoverAllConnections(multiDBTransactionManager);
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ public class DataSource extends BasicDataSource {
|
|||||||
public synchronized void initialize(AvailableConnectionsModel connectionModel) throws Exception {
|
public synchronized void initialize(AvailableConnectionsModel connectionModel) throws Exception {
|
||||||
this.connectionModel = connectionModel;
|
this.connectionModel = connectionModel;
|
||||||
|
|
||||||
|
this.setDriverClassName(connectionModel.getDriverClassName());
|
||||||
|
|
||||||
this.setUrl(connectionModel.getDbConnectionString("EMS Connection"));
|
this.setUrl(connectionModel.getDbConnectionString("EMS Connection"));
|
||||||
this.setUsername(connectionModel.getUsername());
|
this.setUsername(connectionModel.getUsername());
|
||||||
this.setPassword(connectionModel.getPasswordDecrypted());
|
this.setPassword(connectionModel.getPasswordDecrypted());
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
package it.integry.ems.settings.Model;
|
package it.integry.ems.settings.Model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import it.integry.ems.expansion.ObservableArrayList;
|
import it.integry.ems.expansion.ObservableArrayList;
|
||||||
import it.integry.ems.expansion.ObservableField;
|
import it.integry.ems.expansion.ObservableField;
|
||||||
|
import it.integry.ems_model.utility.UtilityReflection;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.List;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SettingsModel implements InitializingBean {
|
public class SettingsModel implements InitializingBean {
|
||||||
|
|
||||||
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
private transient final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
private transient final Object sync = new Object();
|
||||||
|
|
||||||
|
private transient File configurationFile;
|
||||||
|
|
||||||
private static SettingsModel instance;
|
private static SettingsModel instance;
|
||||||
|
|
||||||
private int accessTokenExpireMinutes = 30;
|
private int accessTokenExpireMinutes = 30;
|
||||||
@@ -109,8 +120,8 @@ public class SettingsModel implements InitializingBean {
|
|||||||
|
|
||||||
public List<AvailableConnectionsModel> getAvailableConnectionsWithoutDuplicatedProfiles(boolean onlyInternal) {
|
public List<AvailableConnectionsModel> getAvailableConnectionsWithoutDuplicatedProfiles(boolean onlyInternal) {
|
||||||
Map<String, List<AvailableConnectionsModel>> databases = getAvailableConnections(onlyInternal)
|
Map<String, List<AvailableConnectionsModel>> databases = getAvailableConnections(onlyInternal)
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(AvailableConnectionsModel::getDbName));
|
.collect(Collectors.groupingBy(AvailableConnectionsModel::getDbName));
|
||||||
|
|
||||||
return databases.keySet().stream()
|
return databases.keySet().stream()
|
||||||
.map(key -> databases.get(key).get(0))
|
.map(key -> databases.get(key).get(0))
|
||||||
@@ -125,10 +136,6 @@ public class SettingsModel implements InitializingBean {
|
|||||||
this.availableConnections.set(availableConnections);
|
this.availableConnections.set(availableConnections);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAvailableConnections(ArrayList<AvailableConnectionsModel> availableConnections, boolean forceRefresh) {
|
|
||||||
this.availableConnections.set(availableConnections, forceRefresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValidConnection(String profileName) {
|
public boolean isValidConnection(String profileName) {
|
||||||
return this.isValidConnection(profileName, false);
|
return this.isValidConnection(profileName, false);
|
||||||
}
|
}
|
||||||
@@ -218,4 +225,67 @@ public class SettingsModel implements InitializingBean {
|
|||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
try {
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
|
String confPath = System.getProperties().getProperty("catalina.home");
|
||||||
|
String emsSettingsJsonFileName = "ems_settings.json";
|
||||||
|
|
||||||
|
configurationFile = new File(String.format("%s/conf/integry/%s", confPath, emsSettingsJsonFileName));
|
||||||
|
|
||||||
|
SettingsModel newSettingsModel = objectMapper.readValue(configurationFile, SettingsModel.class);
|
||||||
|
|
||||||
|
UtilityReflection.copyFields(newSettingsModel, this);
|
||||||
|
|
||||||
|
if (getMinioConfiguration() == null || UtilityString.isNullOrEmpty(getMinioConfiguration().getHost()))
|
||||||
|
setMinioConfiguration(MinIOSettingsModel.getDefault());
|
||||||
|
|
||||||
|
if (getMinioConfiguration().getExcludedEntities() == null)
|
||||||
|
getMinioConfiguration().setExcludedEntities(new ArrayList<>());
|
||||||
|
|
||||||
|
this.saveOnFile();
|
||||||
|
|
||||||
|
String availableProfiles = System.getenv("AVAILABLE_PROFILES");
|
||||||
|
|
||||||
|
if (!UtilityString.isNullOrEmpty(availableProfiles)) {
|
||||||
|
ArrayList<String> availableConnections = new ArrayList<>(Arrays.asList(availableProfiles.split(",")));
|
||||||
|
|
||||||
|
logger.info("Impostando connessioni a: " + availableProfiles);
|
||||||
|
|
||||||
|
if (availableConnections.stream().noneMatch(s -> s.equalsIgnoreCase(this.getDefaultProfile()))) {
|
||||||
|
availableConnections.add(this.getDefaultProfile());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AvailableConnectionsModel> availableConnectionsModels = this.getAvailableConnections()
|
||||||
|
.stream()
|
||||||
|
.filter(availableConnectionsModel ->
|
||||||
|
availableConnections.stream().anyMatch(s -> s.equalsIgnoreCase(availableConnectionsModel.getProfileName())))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
this.setAvailableConnections(new ArrayList<>(availableConnectionsModels));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Settings Initalization", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public File getConfigurationFile() {
|
||||||
|
return configurationFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveOnFile() {
|
||||||
|
try {
|
||||||
|
synchronized (sync) {
|
||||||
|
objectMapper.writerWithDefaultPrettyPrinter().writeValue(configurationFile, this);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("SettingsModel", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
package it.integry.ems.settings;
|
package it.integry.ems.settings;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import it.integry.ems.expansion.ObservableArrayList;
|
import it.integry.ems.expansion.ObservableArrayList;
|
||||||
import it.integry.ems.expansion.ObservableField;
|
import it.integry.ems.expansion.ObservableField;
|
||||||
import it.integry.ems.properties.EmsProperties;
|
import it.integry.ems.properties.EmsProperties;
|
||||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||||
import it.integry.ems.settings.Model.LoggerConfigurationModel;
|
|
||||||
import it.integry.ems.settings.Model.MinIOSettingsModel;
|
|
||||||
import it.integry.ems.settings.Model.SettingsModel;
|
import it.integry.ems.settings.Model.SettingsModel;
|
||||||
import it.integry.ems.utility.UtilityDebug;
|
import it.integry.ems.utility.UtilityDebug;
|
||||||
import it.integry.ems.utility.UtilityFile;
|
|
||||||
import it.integry.ems.watching.FileWatcher;
|
import it.integry.ems.watching.FileWatcher;
|
||||||
import it.integry.ems.watching.IFileWatcherEvents;
|
import it.integry.ems.watching.IFileWatcherEvents;
|
||||||
import it.integry.ems_model.utility.UtilityReflection;
|
import it.integry.ems_model.utility.UtilityReflection;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -23,8 +18,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SettingsController implements IFileWatcherEvents {
|
public class SettingsController implements IFileWatcherEvents {
|
||||||
@@ -43,7 +41,6 @@ public class SettingsController implements IFileWatcherEvents {
|
|||||||
|
|
||||||
private final ArrayList<Runnable> mOnConfigUpdated = new ArrayList<>();
|
private final ArrayList<Runnable> mOnConfigUpdated = new ArrayList<>();
|
||||||
|
|
||||||
private File configurationFile;
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
@@ -52,143 +49,8 @@ public class SettingsController implements IFileWatcherEvents {
|
|||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
try {
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
|
|
||||||
String confPath = System.getProperties().getProperty("catalina.home");
|
FileWatcher fileWatcher = new FileWatcher(settingsModel.getConfigurationFile());
|
||||||
configurationFile = new File(String.format("%s/conf/integry/%s", confPath, RESOURCE_FILEPATH));
|
|
||||||
|
|
||||||
boolean shouldUpdateConfig = false;
|
|
||||||
|
|
||||||
//Cancello la config
|
|
||||||
if (configurationFile.exists()) {
|
|
||||||
File connectDb = new File(emsProperties.getGlobalConnectionIniPath());
|
|
||||||
if (connectDb.exists()) {
|
|
||||||
shouldUpdateConfig = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//File blockUpdate = new File(String.format("%s/conf/integry/%s", confPath, "_blockUpdate.txt"));
|
|
||||||
//if (!blockUpdate.exists()) {
|
|
||||||
if (!configurationFile.exists() || shouldUpdateConfig) {
|
|
||||||
|
|
||||||
if (!shouldUpdateConfig) UtilityFile.createFile(configurationFile.getPath());
|
|
||||||
else {
|
|
||||||
SettingsModel newSettingsModel = objectMapper.readValue(configurationFile, SettingsModel.class);
|
|
||||||
UtilityReflection.copyFields(newSettingsModel, settingsModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (UtilityDebug.isDebugExecution()) {
|
|
||||||
// settingsModel.setAvailableConnections(null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (UtilityString.isNullOrEmpty(settingsModel.getDefaultProfile())) {
|
|
||||||
String profileDbToSave = settingsConverter.getConvertedDefaultDB();
|
|
||||||
if (settingsModel.getAvailableConnections() != null) {
|
|
||||||
String finalProfileDbToSave = profileDbToSave;
|
|
||||||
Optional<AvailableConnectionsModel> defaultConnection = settingsModel.getAvailableConnections().stream()
|
|
||||||
.filter(x -> x.getDbName().equalsIgnoreCase(finalProfileDbToSave) || x.getProfileName().equalsIgnoreCase(finalProfileDbToSave))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
profileDbToSave = defaultConnection.isPresent() ? defaultConnection.get().getProfileName() : profileDbToSave;
|
|
||||||
}
|
|
||||||
settingsModel.setDefaultProfile(profileDbToSave);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (settingsModel.getAvailableConnections() == null)
|
|
||||||
// settingsModel.setAvailableConnections(settingsConverter.getConvertedAvailableConnections());
|
|
||||||
|
|
||||||
// if(settingsModel.getDefaultMailConfiguration() == null || UtilityString.isNullOrEmpty(settingsModel.getDefaultMailConfiguration().getSmtp()))
|
|
||||||
// settingsModel.setDefaultMailConfiguration(settingsConverter.getConvertedMailConfiguration());
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration() == null
|
|
||||||
|| settingsModel.getLoggerConfiguration().getLevel() == null
|
|
||||||
|| settingsModel.getLoggerConfiguration().getDeleteDays() == null
|
|
||||||
|| settingsModel.getLoggerConfiguration().getDbDeleteDays() == null
|
|
||||||
|| UtilityString.isNullOrEmpty(settingsModel.getLoggerConfiguration().getDbMaxSize())
|
|
||||||
) {
|
|
||||||
LoggerConfigurationModel loggerConfigurationModel = settingsConverter.getConvertedLoggerConfiguration();
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration().getLevel() != null) {
|
|
||||||
loggerConfigurationModel.setLogLevelEnum(settingsModel.getLoggerConfiguration().getLevelEnum());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration().getDeleteDays() != null) {
|
|
||||||
loggerConfigurationModel.setDeleteDays(settingsModel.getLoggerConfiguration().getDeleteDays());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration().getDbDeleteDays() != null) {
|
|
||||||
loggerConfigurationModel.setDbDeleteDays(settingsModel.getLoggerConfiguration().getDbDeleteDays());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration().getDbMaxSize() != null) {
|
|
||||||
loggerConfigurationModel.setDbMaxSize(settingsModel.getLoggerConfiguration().getDbMaxSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
settingsModel.setLoggerConfiguration(loggerConfigurationModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settingsModel.getMinioConfiguration() == null || UtilityString.isNullOrEmpty(settingsModel.getMinioConfiguration().getHost()))
|
|
||||||
settingsModel.setMinioConfiguration(MinIOSettingsModel.getDefault());
|
|
||||||
|
|
||||||
if (settingsModel.getMinioConfiguration().getExcludedEntities() == null)
|
|
||||||
settingsModel.getMinioConfiguration().setExcludedEntities(new ArrayList<>());
|
|
||||||
} else {
|
|
||||||
SettingsModel newSettingsModel = objectMapper.readValue(configurationFile, SettingsModel.class);
|
|
||||||
|
|
||||||
UtilityReflection.copyFields(newSettingsModel, settingsModel);
|
|
||||||
|
|
||||||
if (UtilityString.isNullOrEmpty(settingsModel.getDefaultProfile())) {
|
|
||||||
String profileDbToSave = settingsConverter.getConvertedDefaultDB();
|
|
||||||
if (settingsModel.getAvailableConnections() != null) {
|
|
||||||
String finalProfileDbToSave = profileDbToSave;
|
|
||||||
Optional<AvailableConnectionsModel> defaultConnection = settingsModel.getAvailableConnections().stream()
|
|
||||||
.filter(x -> x.getDbName().equalsIgnoreCase(finalProfileDbToSave) || x.getProfileName().equalsIgnoreCase(finalProfileDbToSave))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
profileDbToSave = defaultConnection.isPresent() ? defaultConnection.get().getProfileName() : profileDbToSave;
|
|
||||||
}
|
|
||||||
settingsModel.setDefaultProfile(profileDbToSave);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (settingsModel.getAvailableConnections() == null)
|
|
||||||
// settingsModel.setAvailableConnections(settingsConverter.getConvertedAvailableConnections());
|
|
||||||
|
|
||||||
// if(settingsModel.getDefaultMailConfiguration() == null || UtilityString.isNullOrEmpty(settingsModel.getDefaultMailConfiguration().getSmtp()))
|
|
||||||
// settingsModel.setDefaultMailConfiguration(settingsConverter.getConvertedMailConfiguration());
|
|
||||||
|
|
||||||
if (settingsModel.getLoggerConfiguration() == null)
|
|
||||||
settingsModel.setLoggerConfiguration(settingsConverter.getConvertedLoggerConfiguration());
|
|
||||||
|
|
||||||
if (settingsModel.getMinioConfiguration() == null || UtilityString.isNullOrEmpty(settingsModel.getMinioConfiguration().getHost()))
|
|
||||||
settingsModel.setMinioConfiguration(MinIOSettingsModel.getDefault());
|
|
||||||
|
|
||||||
if (settingsModel.getMinioConfiguration().getExcludedEntities() == null)
|
|
||||||
settingsModel.getMinioConfiguration().setExcludedEntities(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.save();
|
|
||||||
|
|
||||||
String availableProfiles = System.getenv("AVAILABLE_PROFILES");
|
|
||||||
|
|
||||||
if (!UtilityString.isNullOrEmpty(availableProfiles)) {
|
|
||||||
ArrayList<String> availableConnections = new ArrayList<>(Arrays.asList(availableProfiles.split(",")));
|
|
||||||
|
|
||||||
logger.info("Impostando connessioni a: " + availableProfiles);
|
|
||||||
|
|
||||||
if (availableConnections.stream().noneMatch(s -> s.equalsIgnoreCase(this.settingsModel.getDefaultProfile()))) {
|
|
||||||
availableConnections.add(this.settingsModel.getDefaultProfile());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AvailableConnectionsModel> availableConnectionsModels = this.settingsModel.getAvailableConnections()
|
|
||||||
.stream()
|
|
||||||
.filter(availableConnectionsModel ->
|
|
||||||
availableConnections.stream().anyMatch(s -> s.equalsIgnoreCase(availableConnectionsModel.getProfileName())))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
this.settingsModel.setAvailableConnections(new ArrayList<>(availableConnectionsModels));
|
|
||||||
}
|
|
||||||
|
|
||||||
FileWatcher fileWatcher = new FileWatcher(configurationFile);
|
|
||||||
fileWatcher.setFileWatcherEvents(this);
|
fileWatcher.setFileWatcherEvents(this);
|
||||||
fileWatcher.start();
|
fileWatcher.start();
|
||||||
|
|
||||||
@@ -224,7 +86,7 @@ public class SettingsController implements IFileWatcherEvents {
|
|||||||
} else if (!(obj instanceof ArrayList)) {
|
} else if (!(obj instanceof ArrayList)) {
|
||||||
try {
|
try {
|
||||||
for (Field field : klazz.getDeclaredFields()) {
|
for (Field field : klazz.getDeclaredFields()) {
|
||||||
if (!field.getType().equals(klazz)) {
|
if (!field.getType().equals(klazz) && !Modifier.isTransient(field.getModifiers())) {
|
||||||
|
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object f = field.get(obj);
|
Object f = field.get(obj);
|
||||||
@@ -254,7 +116,7 @@ public class SettingsController implements IFileWatcherEvents {
|
|||||||
@Override
|
@Override
|
||||||
public void onChange(File file) {
|
public void onChange(File file) {
|
||||||
try {
|
try {
|
||||||
SettingsModel newSettingsModel = objectMapper.readValue(configurationFile, SettingsModel.class);
|
SettingsModel newSettingsModel = objectMapper.readValue(settingsModel.getConfigurationFile(), SettingsModel.class);
|
||||||
UtilityReflection.copyFields(newSettingsModel, settingsModel);
|
UtilityReflection.copyFields(newSettingsModel, settingsModel);
|
||||||
|
|
||||||
SettingsHelper.updateEMSSettings(settingsModel);
|
SettingsHelper.updateEMSSettings(settingsModel);
|
||||||
@@ -272,7 +134,7 @@ public class SettingsController implements IFileWatcherEvents {
|
|||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
synchronized (sync) {
|
synchronized (sync) {
|
||||||
objectMapper.writerWithDefaultPrettyPrinter().writeValue(configurationFile, settingsModel);
|
settingsModel.saveOnFile();
|
||||||
SettingsHelper.updateEMSSettings(settingsModel);
|
SettingsHelper.updateEMSSettings(settingsModel);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ public class BasicConnectionPool {
|
|||||||
|
|
||||||
private final ReentrantLock poolLock = new ReentrantLock();
|
private final ReentrantLock poolLock = new ReentrantLock();
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
poolLock.lock();
|
poolLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -65,19 +68,6 @@ public class BasicConnectionPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private int calculatePoolSize() {
|
|
||||||
// int poolSize = UtilityDebug.isIntegryServerMaster() ? 1 :
|
|
||||||
// UtilityDebug.isIntegryServerDev() ? 2 :
|
|
||||||
// UtilityDebug.isDebugExecution() ? 1 :
|
|
||||||
// Runtime.getRuntime().availableProcessors();
|
|
||||||
//
|
|
||||||
// if (!settingsModel.isPrimaryInstance()) {
|
|
||||||
// poolSize = 1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Math.min(poolSize, 8);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void initializeConnections() throws Exception {
|
private void initializeConnections() throws Exception {
|
||||||
final List<AvailableConnectionsModel> availableConnections =
|
final List<AvailableConnectionsModel> availableConnections =
|
||||||
settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(false);
|
settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(false);
|
||||||
@@ -114,4 +104,8 @@ public class BasicConnectionPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, DataSource> getRegisteredDataSources() {
|
||||||
|
return registeredDatasources;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,11 @@ import it.integry.ems_model.annotation.SqlField;
|
|||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class UtilityReflection {
|
public class UtilityReflection {
|
||||||
|
|
||||||
@@ -34,16 +36,21 @@ public class UtilityReflection {
|
|||||||
|
|
||||||
|
|
||||||
public static <T extends Object, Y extends Object> void copyFields(T from, Y too) {
|
public static <T extends Object, Y extends Object> void copyFields(T from, Y too) {
|
||||||
|
// Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
Class<?> fromClass = from.getClass();
|
Class<?> fromClass = from.getClass();
|
||||||
Field[] fromFields = fromClass.getDeclaredFields();
|
List<Field> fromFields = Arrays.stream(fromClass.getDeclaredFields())
|
||||||
|
.filter(x -> !Modifier.isTransient(x.getModifiers()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Class<?> tooClass = too.getClass();
|
Class<?> tooClass = too.getClass();
|
||||||
Field[] tooFields = tooClass.getDeclaredFields();
|
List<Field> tooFields = Arrays.stream(tooClass.getDeclaredFields())
|
||||||
|
.filter(x -> !Modifier.isTransient(x.getModifiers()))
|
||||||
|
.collect(Collectors.toList());;
|
||||||
|
|
||||||
if (fromFields != null && tooFields != null) {
|
if (fromFields != null && tooFields != null) {
|
||||||
for (Field tooF : tooFields) {
|
for (Field tooF : tooFields) {
|
||||||
//logger.debug("toofield name #0 and type #1", tooF.getName(), tooF.getType().toString());
|
// logger.debug(String.format("toofield name %s and type %s", tooF.getName(), tooF.getType()));
|
||||||
try {
|
try {
|
||||||
// Check if that fields exists in the other method
|
// Check if that fields exists in the other method
|
||||||
Field fromF = fromClass.getDeclaredField(tooF.getName());
|
Field fromF = fromClass.getDeclaredField(tooF.getName());
|
||||||
|
|||||||
Reference in New Issue
Block a user