diff --git a/ashv/src/main/java/config/profile/ConfigProfile.java b/ashv/src/main/java/config/profile/ConfigProfile.java index 35f66b2..4393c19 100644 --- a/ashv/src/main/java/config/profile/ConfigProfile.java +++ b/ashv/src/main/java/config/profile/ConfigProfile.java @@ -1,5 +1,6 @@ package config.profile; +import core.manager.ConstantManager; import lombok.Data; import java.util.List; @@ -9,8 +10,8 @@ public class ConfigProfile { private String configName; private boolean isRunning; - private int rawRetainDays; - private int olapRetainDays; + private int rawRetainDays = ConstantManager.RETAIN_DAYS_MAX; + private int olapRetainDays = ConstantManager.RETAIN_DAYS_MAX; private ConnProfile connProfile; private List sqlColProfileList; diff --git a/ashv/src/main/java/config/yaml/YamlConfig.java b/ashv/src/main/java/config/yaml/YamlConfig.java index 43a8a9f..689dbbb 100644 --- a/ashv/src/main/java/config/yaml/YamlConfig.java +++ b/ashv/src/main/java/config/yaml/YamlConfig.java @@ -2,12 +2,14 @@ import config.FileConfig; import config.profile.ConfigProfile; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.yaml.snakeyaml.Yaml; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -30,30 +32,39 @@ public YamlConfig(FileConfig fileConfig, this.yaml = yaml; this.configList = configList; - this.loadConfigFromFs(); + this.loadConfigsFromFs(); } - public void loadConfigToFile(ConfigProfile configuration) { - try { - yaml.dump(configuration, fileConfig.getFileWriter(FileConfig.CONFIGURATION_DIR, - configuration.getConfigName())); - } catch (IOException e) { - log.error(e.getMessage()); - } + @SneakyThrows + public void saveConfigToFile(ConfigProfile configuration) { + FileWriter fileWriter = fileConfig.getFileWriter(FileConfig.CONFIGURATION_DIR, + configuration.getConfigName()); + yaml.dump(configuration, fileWriter); + + fileWriter.close(); + + loadConfigsFromFs(); } - private void loadConfigFromFs() { + @SneakyThrows + public void deleteConfig(String configName) { + fileConfig.removeFile(FileConfig.CONFIGURATION_DIR + FileConfig.FILE_SEPARATOR + configName); + } + + public void loadConfigsFromFs() { + configList.clear(); + try { - fileConfig.listFilesInDirectory(FileConfig.CONFIGURATION_DIR).forEach(e -> { - try { - this.configList - .put(e.getFileName().normalize().toString(), loadConfigurationFile(e)); - } catch (IOException ex) { - log.error(ex.getMessage()); - } - }); - } catch(IOException ex){ - log.error(ex.getMessage()); + fileConfig.listFilesInDirectory(FileConfig.CONFIGURATION_DIR).forEach(e -> { + try { + this.configList + .put(e.getFileName().normalize().toString(), loadConfigurationFile(e)); + } catch (IOException ex) { + log.error(ex.getMessage()); + } + }); + } catch (IOException ex) { + log.error(ex.getMessage()); } } diff --git a/ashv/src/main/java/core/manager/ConfigurationManager.java b/ashv/src/main/java/core/manager/ConfigurationManager.java index b204b28..830bb62 100644 --- a/ashv/src/main/java/core/manager/ConfigurationManager.java +++ b/ashv/src/main/java/core/manager/ConfigurationManager.java @@ -1,74 +1,77 @@ package core.manager; -import config.Labels; import config.profile.ConfigProfile; import config.profile.ConnProfile; import config.profile.SqlColProfile; import config.yaml.YamlConfig; import core.parameter.ConnectionBuilder; +import excp.SqlColMetadataException; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import profile.*; -import store.StoreManager; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; @Slf4j @Singleton public class ConfigurationManager { - private StoreManager storeManager; private YamlConfig yamlConfig; private HashMap configList; - @Getter @Setter - private ConfigProfile currentConfiguration; - - @Getter @Setter - private String configurationName; - - @Getter @Setter - private String connectionName; - - @Getter @Setter - private IProfile iProfile; + @Getter @Setter private ConfigProfile currentConfiguration; + @Getter @Setter private String configurationName; + @Getter @Setter private IProfile iProfile; @Inject - public ConfigurationManager(StoreManager storeManager, - YamlConfig yamlConfig, + public ConfigurationManager(YamlConfig yamlConfig, @Named("ConfigList") HashMap configList) { - this.storeManager = storeManager; this.yamlConfig = yamlConfig; this.configList = configList; } - public void loadCurrentConfiguration(String configurationName, ConnProfile connection){ - ConfigProfile configProfile = new ConfigProfile(); - configProfile.setConnProfile(connection); - loadProfile(connection.getProfileName()); + public void loadCurrentConfiguration(String configurationName) { + ConfigProfile configProfile = getConnProfileList().stream() + .filter(e -> e.getConfigName().equalsIgnoreCase(configurationName)) + .findAny().get(); - configProfile.setConfigName(configurationName); - setCurrentConfiguration(configProfile); + loadProfile(configProfile.getConnProfile().getProfileName()); - loadConfigToFile(configProfile); + setConfigurationName(configurationName); + setCurrentConfiguration(configProfile); } - public void loadSqlColumnMetadata(List columnPojos){ - getCurrentConfiguration().setSqlColProfileList(columnPojos); - loadConfigToFile(getCurrentConfiguration()); + public void loadSqlColumnMetadata(List profilesDb) throws SqlColMetadataException { + Optional> profileCurr = Optional.ofNullable(getCurrentConfiguration().getSqlColProfileList()); + + if (!profileCurr.isPresent()) { + getCurrentConfiguration().setSqlColProfileList(profilesDb); + loadConfigToFile(getCurrentConfiguration()); + } else { + if (profilesDb.size() != profileCurr.get().size()) { + throw new SqlColMetadataException("ASH sql column metadata changes detected.. " + + "Create the new configuration profile!"); + } + } } public void loadConfigToFile(ConfigProfile configuration) { - yamlConfig.loadConfigToFile(configuration); + yamlConfig.saveConfigToFile(configuration); } - public void loadProfile(String profileName){ + public List getConnProfileList() { + return (List) new ArrayList(configList.values()); + } + + public void deleteConfig(String configurationName) { + yamlConfig.deleteConfig(configurationName); + yamlConfig.loadConfigsFromFs(); + } + + public void loadProfile(String profileName) { switch (profileName) { case "OracleEE": setIProfile(new OracleEE()); @@ -87,113 +90,79 @@ public void loadProfile(String profileName){ } } - /** - * For migration purposes (from BDB store to yaml configs) - * Delete in future release - * @param list - */ - public void unloadConfigFromBdbToFile(List list){ - list.stream().forEach(e -> { - Optional> in = configList.entrySet().stream() - .filter(m -> m.getValue().getConfigName() - .equalsIgnoreCase(e.getConnName())).findFirst(); - - if (!in.isPresent()){ - loadCurrentConfiguration(e.getConnName(), e); - } + public ConnectionBuilder getConnectionParameters(String connName) { + Map.Entry orElseEntry = + new AbstractMap.SimpleImmutableEntry<>(connName, new ConfigProfile()); + orElseEntry.getValue().setConfigName(connName); + orElseEntry.getValue().setConnProfile(new ConnProfile()); - }); - } + Map.Entry cfg = configList.entrySet().stream() + .filter(e -> e.getValue().getConfigName().equalsIgnoreCase(connName)) + .findAny().orElse(orElseEntry); - public ConnectionBuilder getConnectionParameters(String connName){ - connectionName = connName; + ConnProfile connOut = cfg.getValue().getConnProfile(); return new ConnectionBuilder.Builder(connName) - .userName(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.username"))) - .password(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.password"))) - .url(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.url"))) - .jar(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.jar"))) - .profile(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.profile"))) - .rawRetainDays(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.other.raw"))) - .olapRetainDays(this.storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connName, Labels.getLabel("local.sql.metadata.connection.other.olap"))) - .build(); + .userName(connOut.getUserName()) + .password(connOut.getPassword()) + .url(connOut.getUrl()) + .jar(connOut.getJar()) + .profile(connOut.getProfileName()) + .rawRetainDays(String.valueOf(cfg.getValue().getRawRetainDays())) + .olapRetainDays(String.valueOf(cfg.getValue().getOlapRetainDays())) + .build(); } - public void saveConnection(ConnectionBuilder connParameters) { - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.name"), connParameters.getConnectionName()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.username"), connParameters.getUserName()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.password"), connParameters.getPassword()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.url"), connParameters.getUrl()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.jar"), connParameters.getJar()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.profile"), connParameters.getProfile()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.driver"), connParameters.getDriverName()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.other.raw"), connParameters.getRawRetainDays()); - storeManager.getRepositoryDAO().metadataEAVDAO.putMainDataEAVWithCheck( - Labels.getLabel("local.sql.metadata.connection"), connParameters.getConnectionName(), - Labels.getLabel("local.sql.metadata.connection.other.olap"), connParameters.getOlapRetainDays()); - } + public void saveConnection(ConnectionBuilder connIn) { + Map.Entry orElseEntry = new AbstractMap.SimpleImmutableEntry<>("", new ConfigProfile()); + orElseEntry.getValue().setConnProfile(new ConnProfile()); + orElseEntry.getValue().setConfigName(connIn.getConnectionName()); - public int getRawRetainDays(){ - int intDays = ConstantManager.RETAIN_DAYS_MAX; + Map.Entry cfg = configList.entrySet().stream() + .filter(e -> e.getValue().getConfigName().equalsIgnoreCase(connIn.getConnectionName())) + .findAny().orElse(orElseEntry); + ConnProfile connOut = cfg.getValue().getConnProfile(); - String strDays = storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connectionName, Labels.getLabel("local.sql.metadata.connection.other.raw")); + connOut.setConnName(connIn.getConnectionName()); + connOut.setUserName(connIn.getUserName()); + connOut.setPassword(connIn.getPassword()); + connOut.setUrl(connIn.getUrl()); + connOut.setJar(connIn.getJar()); + connOut.setProfileName(connIn.getProfile()); + connOut.setDriver(connIn.getDriverName()); - try { - intDays = Integer.parseInt(strDays); - } catch (NumberFormatException ex) { - log.info("Raw data days retain text field contains char data or empty"); - } + cfg.getValue().setRawRetainDays(getRawRetainDays()); + cfg.getValue().setOlapRetainDays(getOlapRetainDays()); - return intDays; + yamlConfig.saveConfigToFile(cfg.getValue()); } - public int getOlapRetainDays(){ - int intDays = ConstantManager.RETAIN_DAYS_MAX; - - String strDays = storeManager.getRepositoryDAO().getMetaDataAttributeValue( - Labels.getLabel("local.sql.metadata.connection"), - connectionName, Labels.getLabel("local.sql.metadata.connection.other.olap")); - - try { - intDays = Integer.parseInt(strDays); - } catch (NumberFormatException ex) { - log.info("Raw data days retain text field contains char data or empty"); - } + public int getRawRetainDays() { + return ConstantManager.RETAIN_DAYS_MAX; + } - return intDays; + public int getOlapRetainDays() { + return ConstantManager.RETAIN_DAYS_MAX; } + /** + * For migration purposes (from BDB store to yaml configs) + * Delete in future release + * + * @param list + */ + public void unloadConfigFromBdbToFile(List list) { + list.forEach(e -> { + Optional> in = configList.entrySet().stream() + .filter(m -> m.getValue().getConfigName() + .equalsIgnoreCase(e.getConnName())).findFirst(); + if (!in.isPresent()) { + ConfigProfile configProfile = new ConfigProfile(); + configProfile.setConfigName(e.getConnName()); + configProfile.setConnProfile(e); + loadConfigToFile(configProfile); + } + }); + } } diff --git a/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java b/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java index d9399d6..eeed6a0 100644 --- a/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java +++ b/ashv/src/main/java/core/processing/GetFromRemoteAndStore.java @@ -30,6 +30,7 @@ import store.entity.database.SqlPlan; import store.entity.olap.AshAggrMinData; import store.entity.olap.AshUser; +import utility.StackTraceUtil; import utility.Utils; import javax.inject.Inject; @@ -146,7 +147,7 @@ public void loadDataFromRemoteToLocalStore() { this.loadToMainStackedChart(); log.info("Stop loading olap"); - if (!this.isFirstRun) { // resolve the issue with the gap for big data in ASV + if (!this.isFirstRun) { // resolve the issue with the gap for big data in ASH this.isFirstRun = true; this.loadDataToOlap(); this.loadToMainStackedChart(); @@ -290,26 +291,12 @@ private void loadMetadata() { metadataMap.put(modNameSysdateSql, loadSqlMetaData(modNameSysdateSql, iProfile.getSqlTextSysdate())); metadataMap.put(modNameAshSql, loadSqlMetaData(modNameAshSql, iProfile.getSqlTextAshOneRow())); - List metadataMapFromLocalDB = - this.storeManager.getRepositoryDAO().getSqlColDbTypeMetadata(modNameAshSql); - // Store metadata in local config file - configurationManager.loadSqlColumnMetadata(metadataMapFromLocalDB); - - // Store metadata in local store - metadataMap.get(modNameAshSql).forEach(x -> { - - if (metadataMapFromLocalDB.stream().noneMatch(e -> e.getColId() == x.getColId())){ - this.storeManager.getRepositoryDAO().getMetadataEAVDAO().putMainDataEAVWithCheck(modNameAshSql, x.getColName(), - Labels.getLabel("local.sql.metadata.columnId"), String.valueOf(x.getColId())); - this.storeManager.getRepositoryDAO().getMetadataEAVDAO().putMainDataEAVWithCheck(modNameAshSql, x.getColName(), - Labels.getLabel("local.sql.metadata.columnName"), x.getColName().toUpperCase()); // PG bug here resolved :: lower-upper case - this.storeManager.getRepositoryDAO().getMetadataEAVDAO().putMainDataEAVWithCheck(modNameAshSql, x.getColName(), - Labels.getLabel("local.sql.metadata.columnType"), x.getColDbTypeName().toUpperCase()); // PG bug here resolved :: lower-upper case + configurationManager.loadSqlColumnMetadata(loadSqlMetaData(modNameAshSql, iProfile.getSqlTextAshOneRow())); - }}); } catch (Exception e) { log.error(e.getLocalizedMessage()); + log.error(StackTraceUtil.getCustomStackTrace(e)); } } diff --git a/ashv/src/main/java/excp/SqlColMetadataException.java b/ashv/src/main/java/excp/SqlColMetadataException.java new file mode 100644 index 0000000..81b27f8 --- /dev/null +++ b/ashv/src/main/java/excp/SqlColMetadataException.java @@ -0,0 +1,7 @@ +package excp; + +public class SqlColMetadataException extends RuntimeException { + public SqlColMetadataException(String message) { + super(message); + } +} diff --git a/ashv/src/main/java/gui/connect/ConnectToDbArea.java b/ashv/src/main/java/gui/connect/ConnectToDbArea.java index 9bd0805..5edf4d3 100644 --- a/ashv/src/main/java/gui/connect/ConnectToDbArea.java +++ b/ashv/src/main/java/gui/connect/ConnectToDbArea.java @@ -147,6 +147,12 @@ private void init(){ connOtherJPanel = new JPanel(lmConnOther); buttonPanel = new JPanel(lmButtonPanel); + //////////////////////// Delete it in future release /////////////////// + configurationManager.unloadConfigFromBdbToFile( + this.storeManager.getRepositoryDAO() + .getConnProfileList(Labels.getLabel("local.sql.metadata.connection"))); + //////////////////////// Delete it in future release /////////////////// + this.init_gui(); this.add(mainJPanel); @@ -290,7 +296,7 @@ private void init_gui(){ jButtonDeleteConn.setEnabled(false); this.deleteData(); - this.loadDataToMetadataMapping(Labels.getLabel("local.sql.metadata.connection")); + this.loadConfigProfileToGui(); jButtonConnect.setEnabled(true); jButtonNewConn.setEnabled(true); @@ -323,7 +329,7 @@ private void init_gui(){ jButtonCancel.setEnabled(false); this.saveData(); - this.loadDataToMetadataMapping(Labels.getLabel("local.sql.metadata.connection")); + this.loadConfigProfileToGui(); this.setDetailEditable(false); setTextDataDaysRetainTF(rawDataDaysRetainTF, configurationManager.getRawRetainDays()); @@ -342,7 +348,7 @@ private void init_gui(){ jButtonSaveConn.setEnabled(false); jButtonCancel.setEnabled(false); - this.loadDataToMetadataMapping(Labels.getLabel("local.sql.metadata.connection")); + this.loadConfigProfileToGui(); this.setDetailEditable(false); setTextDataDaysRetainTF(rawDataDaysRetainTF, configurationManager.getRawRetainDays()); @@ -351,13 +357,10 @@ private void init_gui(){ /** cancel **/ }); - /******/ this.setDetailEditable(false); - /******/ - this.loadDataToMetadataMapping(Labels.getLabel("local.sql.metadata.connection")); + this.loadConfigProfileToGui(); - /******/ buttonPanel.add(jButtonConnect, "gap 1"); buttonPanel.add(jButtonNewConn, "gap 1"); buttonPanel.add(jButtonCopyConn, "gap 1"); @@ -365,7 +368,6 @@ private void init_gui(){ buttonPanel.add(jButtonEditConn, "gap 1"); buttonPanel.add(jButtonSaveConn, "gap 1"); buttonPanel.add(jButtonCancel, "gap 1"); - /******/ connJTabbedPane.add(connMainJPanel, Labels.getLabel("gui.connection.connection.main")); connJTabbedPane.add(connOtherJPanel, Labels.getLabel("gui.connection.connection.other")); @@ -386,8 +388,8 @@ private void setDetailEditable(boolean bParameter){ profileBox.setEnabled(bParameter); jarTF.setEnabled(bParameter); openFileButton.setEnabled(bParameter); - rawDataDaysRetainTF.setEnabled(bParameter); - olapDataDaysRetainTF.setEnabled(bParameter); + //rawDataDaysRetainTF.setEnabled(bParameter); + //olapDataDaysRetainTF.setEnabled(bParameter); jButtonConnect.setEnabled(!bParameter); jButtonNewConn.setEnabled(!bParameter); @@ -430,16 +432,15 @@ private void selectFromDbAndSetInGui(String connName){ } if (!rawDataDaysRetainTF.isEnabled()) { - setTextDataDaysRetainTF(rawDataDaysRetainTF, configurationManager.getRawRetainDays()); + setTextDataDaysRetainTF(rawDataDaysRetainTF, Integer.parseInt(connParameters.getRawRetainDays())); } if (!olapDataDaysRetainTF.isEnabled()) { - setOlapDataDaysRetainTF(olapDataDaysRetainTF, configurationManager.getOlapRetainDays()); + setOlapDataDaysRetainTF(olapDataDaysRetainTF, Integer.parseInt(connParameters.getOlapRetainDays())); } } private void saveData(){ - //this.loadProfile(String.valueOf((profileBox.getSelectedItem()))); configurationManager.loadProfile(String.valueOf((profileBox.getSelectedItem()))); ConnectionBuilder connParameters = new ConnectionBuilder.Builder(connNameTF.getText()) @@ -454,27 +455,24 @@ private void saveData(){ .build(); configurationManager.saveConnection(connParameters); - - storeManager.syncRepo(); } private void deleteData(){ + configurationManager.deleteConfig(connNameTF.getText()); + + //////////////////////// Delete it in future release /////////////////// this.storeManager.getRepositoryDAO().metadataEAVDAO.deleteMainDataEAVWithCheck( Labels.getLabel("local.sql.metadata.connection"), connNameTF.getText() ); - - storeManager.syncRepo(); } - private void loadDataToMetadataMapping(String moduleName){ + private void loadConfigProfileToGui(){ while (modelConn.getRowCount()>0) modelConn.removeRow(0); - storeManager.getRepositoryDAO() - .getModuleMetadata(moduleName) - .forEach(m -> { - modelConn.addRow(new Object[]{m.getConnName()}); - }); + configurationManager.getConnProfileList().forEach(e -> { + modelConn.addRow(new Object[]{e.getConfigName()}); + }); try { tableConn.setRowSelectionInterval(0, 0); @@ -485,19 +483,11 @@ private void loadDataToMetadataMapping(String moduleName){ private void loadObjectsByConnectionName() { try { - //////////////////////// Delete it in future release /////////////////// - configurationManager.unloadConfigFromBdbToFile( - this.storeManager.getRepositoryDAO() - .getModuleMetadata(Labels.getLabel("local.sql.metadata.connection"))); - //////////////////////// Delete it in future release /////////////////// - - ConnProfile connection = - this.storeManager.getRepositoryDAO() - .getModuleMetadata(Labels.getLabel("local.sql.metadata.connection")) - .stream().filter(k -> k.getConnName().equalsIgnoreCase(connNameTF.getText())) - .findFirst().get(); + ConnProfile connection = configurationManager.getConnProfileList().stream() + .filter(e -> e.getConfigName().equalsIgnoreCase(connNameTF.getText())) + .findAny().get().getConnProfile(); - configurationManager.loadCurrentConfiguration(connNameTF.getText(), connection); + configurationManager.loadCurrentConfiguration(connNameTF.getText()); getFromRemoteAndStore.initConnection(connection); getFromRemoteAndStore.initProfile(configurationManager.getIProfile()); @@ -528,15 +518,11 @@ private void loadObjectsByConnectionName() { private void loadObjectsByConnectionNameOffline(){ try { - ConnProfile connection = - this.storeManager.getRepositoryDAO() - .getModuleMetadata(Labels.getLabel("local.sql.metadata.connection")) - .stream() - .filter(k -> k.getConnName().equalsIgnoreCase(connNameTF.getText())) - .findFirst() - .get(); + ConnProfile connection = configurationManager.getConnProfileList().stream() + .filter(e -> e.getConfigName().equalsIgnoreCase(connNameTF.getText())) + .findAny().get().getConnProfile(); - configurationManager.loadCurrentConfiguration(connNameTF.getText(), connection); + configurationManager.loadCurrentConfiguration(connNameTF.getText()); getFromRemoteAndStore.initProfile(configurationManager.getIProfile()); // @@ -596,6 +582,8 @@ private void setNumForDataDaysRetainTF(JXTextField dataDaysRetainTF) { } else if (dataDaysRetainTF.getText().equalsIgnoreCase(String.valueOf(ConstantManager.RetainData.Always))) { dataDaysRetainTF.setText(String.valueOf(ConstantManager.RETAIN_DAYS_MAX)); } + + dataDaysRetainTF.setEnabled(false); } private void setTextDataDaysRetainTF(JXTextField dataDaysRetainTF, int retainDays){ @@ -604,6 +592,8 @@ private void setTextDataDaysRetainTF(JXTextField dataDaysRetainTF, int retainDay } else if (retainDays >= ConstantManager.RETAIN_DAYS_MAX) { dataDaysRetainTF.setText(String.valueOf(ConstantManager.RetainData.Always)); } + + dataDaysRetainTF.setEnabled(false); } private void setOlapDataDaysRetainTF(JXTextField dataDaysRetainTF, int retainDays){ @@ -611,6 +601,8 @@ private void setOlapDataDaysRetainTF(JXTextField dataDaysRetainTF, int retainDay | (retainDays >= ConstantManager.RETAIN_DAYS_MAX)) { dataDaysRetainTF.setText(String.valueOf(ConstantManager.RetainData.Always)); } + + dataDaysRetainTF.setEnabled(false); } } diff --git a/ashv/src/main/java/gui/table/RawDataTable.java b/ashv/src/main/java/gui/table/RawDataTable.java index dcf5dbd..47b8683 100644 --- a/ashv/src/main/java/gui/table/RawDataTable.java +++ b/ashv/src/main/java/gui/table/RawDataTable.java @@ -201,10 +201,11 @@ private String[] getColumnHeaders(){ String moduleName = "ash" + "_" + iProfile.getProfileName(); AtomicInteger at = new AtomicInteger(0); - String[] out = new String[this.storeManager.getRepositoryDAO().getSqlColDbTypeMetadata(moduleName).size()]; + String[] out = new String[this.storeManager.getConfigurationManager().getCurrentConfiguration().getSqlColProfileList().size()]; - this.storeManager.getRepositoryDAO() - .getSqlColDbTypeMetadata(moduleName) + this.storeManager.getConfigurationManager() + .getCurrentConfiguration() + .getSqlColProfileList() .stream() .sorted((o1, o2) -> o1.getColId() - o2.getColId()) .forEach(e->out[at.getAndIncrement()]= e.getColName()); @@ -218,7 +219,7 @@ private void loadDataToTableModel(DefaultTableModel tableModel, long begin, long this.storeManager.getDatabaseDAO() .getMatrixDataForJTable(begin, end, waitClassColName, waitClassValue, - this.storeManager.getRepositoryDAO().getSqlColDbTypeMetadata(moduleName)) + this.storeManager.getConfigurationManager().getCurrentConfiguration().getSqlColProfileList()) .forEach(e -> { for(int row = 0; row < e.length; row++){ if (e[row][0] != null) { diff --git a/ashv/src/main/java/store/RepositoryDAO.java b/ashv/src/main/java/store/RepositoryDAO.java index 2c8ea5d..82755f4 100644 --- a/ashv/src/main/java/store/RepositoryDAO.java +++ b/ashv/src/main/java/store/RepositoryDAO.java @@ -3,10 +3,9 @@ import com.sleepycat.je.DatabaseException; import com.sleepycat.persist.EntityCursor; import config.Labels; +import config.profile.ConnProfile; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import config.profile.ConnProfile; -import config.profile.SqlColProfile; import store.dao.repository.IMetadataEAVDAO; import store.dao.repository.MetadataEAVDAO; import store.entity.repository.MetadataEAV; @@ -31,7 +30,7 @@ public RepositoryDAO(BerkleyDB berkleyDB) throws DatabaseException { this.metadataEAVDAO = new MetadataEAVDAO(this.berkleyDB.getStore()); } - public List getModuleMetadata(String moduleName){ + public List getConnProfileList(String moduleName){ List out = new ArrayList<>(); Set list = new HashSet<>(); @@ -86,36 +85,4 @@ public String getMetaDataAttributeValue(String moduleName, return out; } - - public List getSqlColDbTypeMetadata(String moduleName){ - List out = new ArrayList<>(); - Set list = new HashSet<>(); - - EntityCursor mainDataEAV = - this.metadataEAVDAO.getModuleSecondaryIndex().subIndex(moduleName).entities(); - - try { - for (MetadataEAV metaEAV : mainDataEAV) { - if (metaEAV.getModuleName().equalsIgnoreCase(moduleName) && - metaEAV.getAttribute().equalsIgnoreCase(Labels.getLabel("local.sql.metadata.columnId"))) { - list.add(metaEAV.getEntity()); - } - } - } finally { - mainDataEAV.close(); - } - - list.forEach(e -> { - - SqlColProfile sqlColProfile = new SqlColProfile(); - sqlColProfile.setColId(Integer.parseInt(this.getMetaDataAttributeValue(moduleName, e, Labels.getLabel("local.sql.metadata.columnId")))); sqlColProfile.setColName(e); - sqlColProfile.setColDbTypeName(this.getMetaDataAttributeValue(moduleName, e, Labels.getLabel("local.sql.metadata.columnType"))); - - out.add(sqlColProfile); - }); - - return out; - } - - } diff --git a/ashv/src/main/java/store/StoreManager.java b/ashv/src/main/java/store/StoreManager.java index 3d75229..1413792 100644 --- a/ashv/src/main/java/store/StoreManager.java +++ b/ashv/src/main/java/store/StoreManager.java @@ -2,6 +2,7 @@ import com.sleepycat.je.DatabaseException; import config.FileConfig; +import core.manager.ConfigurationManager; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -22,6 +23,7 @@ public class StoreManager { @Getter private DatabaseDAO databaseDAO; @Getter private OlapCacheManager olapCacheManager; + @Getter private ConfigurationManager configurationManager; @Getter @Setter private long lastLoadTimeMark; @@ -29,12 +31,14 @@ public class StoreManager { public StoreManager(FileConfig fileConfig, BerkleyDB berkleyRepo, RepositoryDAO repositoryDAO, - OlapCacheManager olapCacheManager) { + OlapCacheManager olapCacheManager, + ConfigurationManager configurationManager) { try { this.fileConfig = fileConfig; this.berkleyRepo = berkleyRepo; this.repositoryDAO = repositoryDAO; this.olapCacheManager = olapCacheManager; + this.configurationManager = configurationManager; } catch (DatabaseException e) { e.printStackTrace(); System.exit(-1); @@ -51,7 +55,6 @@ public void setUpBDBAndDAO(String connName) throws IOException { databaseDAO = new DatabaseDAO(berkleyDB); } - public void syncRepo(){ this.berkleyRepo.getStore().sync(); } diff --git a/ashv/src/main/resources/messages.properties b/ashv/src/main/resources/messages.properties index 58968e6..dfed045 100644 --- a/ashv/src/main/resources/messages.properties +++ b/ashv/src/main/resources/messages.properties @@ -35,8 +35,8 @@ gui.connection.offline=Offline gui.connection.retain=Retain data (days) gui.connection.retain.raw=Raw gui.connection.retain.olap=Olap -gui.connection.retain.raw.tooltip=More than 100 - always store raw data, less than 1 - raw data not stored anymore -gui.connection.retain.olap.tooltip=More than 100 and less than 1 - always store OLAP data +gui.connection.retain.raw.tooltip=Feature under development +gui.connection.retain.olap.tooltip=Feature under development gui.connection.button.connect=Connect gui.connection.button.new=New