Skip to content

Commit

Permalink
Merge pull request #226 from thehyve/version
Browse files Browse the repository at this point in the history
Show current version in WR and RiaH UI
  • Loading branch information
Maxim Moinat authored May 17, 2020
2 parents 25f0818 + 22d47e9 commit 363e443
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 75 deletions.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.ohdsi</groupId>
<artifactId>leporidae</artifactId>
<packaging>pom</packaging>
<version>0.9.0</version>
<version>0.10.0-SNAPSHOT</version>
<modules>
<module>rabbitinahat</module>
<module>whiterabbit</module>
Expand Down Expand Up @@ -129,5 +129,13 @@
</configuration>
</plugin>
</plugins>

<resources>
<!-- Resource filtering to make version information available. From https://stackoverflow.com/a/26573884 -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
2 changes: 1 addition & 1 deletion rabbit-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>leporidae</artifactId>
<groupId>org.ohdsi</groupId>
<version>0.9.0</version>
<version>0.10.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
17 changes: 17 additions & 0 deletions rabbit-core/src/main/java/org/ohdsi/utilities/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ohdsi.utilities;

import java.io.IOException;
import java.util.Properties;

public class Version {

public static String getVersion(Class c) {
final Properties properties = new Properties();
try {
properties.load(c.getClassLoader().getResourceAsStream("project.properties"));
} catch (IOException e) {
e.printStackTrace();
}
return properties.getProperty("version");
}
}
2 changes: 2 additions & 0 deletions rabbit-core/src/main/resources/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=${project.version}
artifactId=${project.artifactId}
2 changes: 1 addition & 1 deletion rabbitinahat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>leporidae</artifactId>
<groupId>org.ohdsi</groupId>
<version>0.9.0</version>
<version>0.10.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.ohdsi.rabbitInAHat.dataModel.MappableItem;
import org.ohdsi.rabbitInAHat.dataModel.StemTableFactory;
import org.ohdsi.rabbitInAHat.dataModel.Table;
import org.ohdsi.utilities.Version;
import org.ohdsi.utilities.collections.Pair;

/**
Expand Down Expand Up @@ -81,7 +82,7 @@ public class RabbitInAHatMain implements ResizeListener {
public final static String ACTION_SET_TARGET_V530 = "CDM v5.3.0";
public final static String ACTION_SET_TARGET_V531 = "CDM v5.3.1";
public final static String ACTION_SET_TARGET_V60 = "CDM v6.0";
public final static String ACTION_SET_TARGET_V60_O = "CDM v6.0 + Oncology";
public final static String ACTION_SET_TARGET_V60_O = "CDM v6.0 + Oncology";
public final static String ACTION_ADD_STEM_TABLE = "Add stem table";
public final static String ACTION_REMOVE_STEM_TABLE = "Remove stem table";
public final static String ACTION_SET_TARGET_CUSTOM = "Load Custom...";
Expand Down Expand Up @@ -300,22 +301,26 @@ private JMenuBar createMenuBar() {

JMenu helpMenu = new JMenu("Help");
menuBar.add(helpMenu);
addMenuItem(helpMenu, "Rabbit in a Hat v" + Version.getVersion(this.getClass()), null).setEnabled(false);
addMenuItem(helpMenu, ACTION_HELP, evt -> this.doOpenDocumentation());

return menuBar;
}

public void addMenuItem(JMenu menu, String description, ActionListener actionListener) {
addMenuItem(menu, description, actionListener, null);
public JMenuItem addMenuItem(JMenu menu, String description, ActionListener actionListener) {
return addMenuItem(menu, description, actionListener, null);
}

public void addMenuItem(JMenu menu, String description, ActionListener actionListener, Integer keyEvent) {
public JMenuItem addMenuItem(JMenu menu, String description, ActionListener actionListener, Integer keyEvent) {
JMenuItem menuItem = new JMenuItem(description);
menuItem.addActionListener(actionListener);
if (actionListener != null) {
menuItem.addActionListener(actionListener);
}
if (keyEvent != null) {
menuItem.setAccelerator(KeyStroke.getKeyStroke(keyEvent, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
}
menu.add(menuItem);
return menuItem;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion whiterabbit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>leporidae</artifactId>
<groupId>org.ohdsi</groupId>
<version>0.9.0</version>
<version>0.10.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
42 changes: 21 additions & 21 deletions whiterabbit/src/main/java/org/ohdsi/whiteRabbit/DbSettings.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
* Copyright 2019 Observational Health Data Sciences and Informatics
*
*
* This file is part of WhiteRabbit
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -24,22 +24,22 @@
import org.ohdsi.databases.DbType;

public class DbSettings {
public static int DATABASE = 1;
public static int CSVFILES = 2;
public static int SASFILES = 3;
public enum SourceType {
DATABASE, CSV_FILES, SAS_FILES
}

public int dataType;
public List<String> tables = new ArrayList<String>();
// Database settings
public DbType dbType;
public String user;
public String password;
public String database;
public String server;
public String domain;
// CSV file settings
public char delimiter = ',';
public CSVFormat csvFormat = CSVFormat.RFC4180;
public SourceType sourceType;
public List<String> tables = new ArrayList<>();

// Database settings
public DbType dbType;
public String user;
public String password;
public String database;
public String server;
public String domain;

// CSV file settings
public char delimiter = ',';
public CSVFormat csvFormat = CSVFormat.RFC4180;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.ohdsi.databases.RichConnection;
import org.ohdsi.utilities.DirectoryUtilities;
import org.ohdsi.utilities.StringUtilities;
import org.ohdsi.utilities.Version;
import org.ohdsi.utilities.files.IniFile;
import org.ohdsi.whiteRabbit.fakeDataGenerator.FakeDataGenerator;
import org.ohdsi.whiteRabbit.scan.SourceDataScan;
Expand Down Expand Up @@ -152,15 +153,15 @@ private void launchCommandLine(String iniFileName) {
IniFile iniFile = new IniFile(iniFileName);
DbSettings dbSettings = new DbSettings();
if (iniFile.get("DATA_TYPE").equalsIgnoreCase("Delimited text files")) {
dbSettings.dataType = DbSettings.CSVFILES;
dbSettings.sourceType = DbSettings.SourceType.CSV_FILES;
if (iniFile.get("DELIMITER").equalsIgnoreCase("tab"))
dbSettings.delimiter = '\t';
else
dbSettings.delimiter = iniFile.get("DELIMITER").charAt(0);
} else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("SAS7bdat")) {
dbSettings.dataType = DbSettings.SASFILES;
dbSettings.sourceType = DbSettings.SourceType.SAS_FILES;
} else {
dbSettings.dataType = DbSettings.DATABASE;
dbSettings.sourceType = DbSettings.SourceType.DATABASE;
dbSettings.user = iniFile.get("USER_NAME");
dbSettings.password = iniFile.get("PASSWORD");
dbSettings.server = iniFile.get("SERVER_LOCATION");
Expand Down Expand Up @@ -216,7 +217,7 @@ else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("BigQuery")) {
}
} else {
for (String table : iniFile.get("TABLES_TO_SCAN").split(",")) {
if (dbSettings.dataType == DbSettings.CSVFILES)
if (dbSettings.sourceType == DbSettings.SourceType.CSV_FILES)
table = iniFile.get("WORKING_FOLDER") + "/" + table;
dbSettings.tables.add(table);
}
Expand Down Expand Up @@ -507,7 +508,6 @@ public void actionPerformed(ActionEvent e) {
}

private JPanel createFakeDataPanel() {
// TODO: add sas7bdat as target for fake data.
JPanel panel = new JPanel();

panel.setLayout(new GridBagLayout());
Expand Down Expand Up @@ -541,7 +541,6 @@ public void actionPerformed(ActionEvent e) {
targetPanel.setBorder(BorderFactory.createTitledBorder("Target data location"));
targetPanel.add(new JLabel("Data type"));
targetType = new JComboBox<String>(new String[] { "Delimited text files", "MySQL", "Oracle", "SQL Server", "PostgreSQL" });
// targetType = new JComboBox(new String[] { "Delimited text files", "MySQL" });
targetType.setToolTipText("Select the type of source data available");
targetType.addItemListener(new ItemListener() {

Expand Down Expand Up @@ -733,14 +732,14 @@ private void addAllTables() {
private void pickTables() {
DbSettings sourceDbSettings = getSourceDbSettings();
if (sourceDbSettings != null) {
if (sourceDbSettings.dataType == DbSettings.CSVFILES || sourceDbSettings.dataType == DbSettings.SASFILES) {
if (sourceDbSettings.sourceType == DbSettings.SourceType.CSV_FILES || sourceDbSettings.sourceType == DbSettings.SourceType.SAS_FILES) {
JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

if (sourceDbSettings.dataType == DbSettings.CSVFILES) {
if (sourceDbSettings.sourceType == DbSettings.SourceType.CSV_FILES) {
fileChooser.setFileFilter(new FileNameExtensionFilter("Delimited text files", "csv", "txt"));
} else if (sourceDbSettings.dataType == DbSettings.SASFILES) {
} else if (sourceDbSettings.sourceType == DbSettings.SourceType.SAS_FILES) {
fileChooser.setFileFilter(new FileNameExtensionFilter("SAS Data Files", "sas7bdat"));
}

Expand All @@ -754,7 +753,7 @@ private void pickTables() {
}

}
} else if (sourceDbSettings.dataType == DbSettings.DATABASE) {
} else if (sourceDbSettings.sourceType == DbSettings.SourceType.DATABASE) {
RichConnection connection = new RichConnection(sourceDbSettings.server, sourceDbSettings.domain, sourceDbSettings.user,
sourceDbSettings.password, sourceDbSettings.dbType);
String tableNames = StringUtilities.join(connection.getTableNames(sourceDbSettings.database), "\t");
Expand All @@ -779,7 +778,7 @@ private void pickTables() {
private DbSettings getSourceDbSettings() {
DbSettings dbSettings = new DbSettings();
if (sourceType.getSelectedItem().equals("Delimited text files")) {
dbSettings.dataType = DbSettings.CSVFILES;
dbSettings.sourceType = DbSettings.SourceType.CSV_FILES;
if (sourceDelimiterField.getText().length() == 0) {
JOptionPane.showMessageDialog(frame, "Delimiter field cannot be empty for source database", "Error connecting to server",
JOptionPane.ERROR_MESSAGE);
Expand All @@ -790,9 +789,9 @@ private DbSettings getSourceDbSettings() {
else
dbSettings.delimiter = sourceDelimiterField.getText().charAt(0);
} else if (sourceType.getSelectedItem().equals("SAS7bdat")) {
dbSettings.dataType = DbSettings.SASFILES;
dbSettings.sourceType = DbSettings.SourceType.SAS_FILES;
} else {
dbSettings.dataType = DbSettings.DATABASE;
dbSettings.sourceType = DbSettings.SourceType.DATABASE;
dbSettings.user = sourceUserField.getText();
dbSettings.password = sourcePasswordField.getText();
dbSettings.server = sourceServerField.getText();
Expand Down Expand Up @@ -838,7 +837,7 @@ else if (sourceType.getSelectedItem().toString().equals("Azure")) {
}

private void testConnection(DbSettings dbSettings) {
if (dbSettings.dataType == DbSettings.CSVFILES || dbSettings.dataType == DbSettings.SASFILES) {
if (dbSettings.sourceType == DbSettings.SourceType.CSV_FILES || dbSettings.sourceType == DbSettings.SourceType.SAS_FILES) {
if (new File(folderField.getText()).exists()) {
String message = "Folder " + folderField.getText() + " found";
JOptionPane.showMessageDialog(frame, StringUtilities.wordWrap(message, 80), "Working folder found", JOptionPane.INFORMATION_MESSAGE);
Expand Down Expand Up @@ -886,7 +885,7 @@ private void testConnection(DbSettings dbSettings) {
private DbSettings getTargetDbSettings() {
DbSettings dbSettings = new DbSettings();
if (targetType.getSelectedItem().equals("Delimited text files")) {
dbSettings.dataType = DbSettings.CSVFILES;
dbSettings.sourceType = DbSettings.SourceType.CSV_FILES;

switch((String) targetCSVFormat.getSelectedItem()) {
case "Default (comma, CRLF)":
Expand All @@ -909,7 +908,7 @@ private DbSettings getTargetDbSettings() {
}

} else {
dbSettings.dataType = DbSettings.DATABASE;
dbSettings.sourceType = DbSettings.SourceType.DATABASE;
dbSettings.user = targetUserField.getText();
dbSettings.password = targetPasswordField.getText();
dbSettings.server = targetServerField.getText();
Expand Down Expand Up @@ -1033,7 +1032,7 @@ public void run() {
DbSettings dbSettings = getSourceDbSettings();
if (dbSettings != null) {
for (String table : tables) {
if (dbSettings.dataType == DbSettings.CSVFILES || dbSettings.dataType == DbSettings.SASFILES)
if (dbSettings.sourceType == DbSettings.SourceType.CSV_FILES || dbSettings.sourceType == DbSettings.SourceType.SAS_FILES)
table = folderField.getText() + "/" + table;
dbSettings.tables.add(table);
}
Expand Down Expand Up @@ -1163,6 +1162,11 @@ private void handleError(Exception e) {
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu helpMenu = new JMenu("Help");

JMenuItem versionItem = new JMenuItem("White Rabbit v" + Version.getVersion(this.getClass()));
versionItem.setEnabled(false);
helpMenu.add(versionItem);

menuBar.add(helpMenu);
JMenuItem helpItem = new JMenuItem(ACTION_CMD_HELP);
helpItem.addActionListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class FakeDataGenerator {

private RichConnection connection;
private int targetType;
private DbSettings.SourceType targetType;
private int maxRowsPerTable = 1000;

private static int REGULAR = 0;
Expand All @@ -43,13 +43,13 @@ public class FakeDataGenerator {

public void generateData(DbSettings dbSettings, int maxRowsPerTable, String filename, String folder) {
this.maxRowsPerTable = maxRowsPerTable;
this.targetType = dbSettings.dataType;
this.targetType = dbSettings.sourceType;

StringUtilities.outputWithTime("Starting creation of fake data");
System.out.println("Loading scan report from " + filename);
Database database = Database.generateModelFromScanReport(filename);

if (targetType == DbSettings.DATABASE) {
if (targetType == DbSettings.SourceType.DATABASE) {
connection = new RichConnection(dbSettings.server, dbSettings.domain, dbSettings.user, dbSettings.password, dbSettings.dbType);
connection.use(dbSettings.database);
for (Table table : database.getTables()) {
Expand Down
Loading

0 comments on commit 363e443

Please sign in to comment.