Skip to content

Commit

Permalink
Now can run WhiteRabbit from command prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Nov 1, 2016
1 parent 049274d commit 543eae7
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 52 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features
- Can scan databases in SQL Server, Oracle, PostgreSQL, MySQL, MS Access, Amazon RedShift, and CSV files
- The scan report contains information on tables, fields, and frequency distributions of values
- Cutoff on the minimum frequency of values to protect patient privacy
- WhiteRabbit can be run with a graphical user interface or from the command prompt
- Interactive tool (Rabbit in a Hat) for designing the ETL using the scan report as basis
- Rabbit in a Hat generates ETL specification document according to OMOP template

Expand Down Expand Up @@ -48,6 +49,7 @@ WhiteRabbit
1. Under the [Releases](https://github.com/OHDSI/WhiteRabbit/releases) tab, download WhiteRabbit*.zip
2. Unzip the download
3. Double-click on WhiteRabbit.jar to start White Rabbit.
(See the Wiki for details on how to run from the command prompt instead)

Rabbit-In-A-Hat

Expand All @@ -66,5 +68,7 @@ WhiteRabbit is licensed under Apache License 2.0
Development
===========
White Rabbit and Rabbit in a Hat are being developed in Eclipse. Contributions are welcome.

###Development status
Beta testing - We invite everyone to try the software, and report any issues they may find.

Production. This program is being used by many people.
12 changes: 12 additions & 0 deletions iniFileExamples/WhiteRabbit.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WORKING_FOLDER = /users/joe # Path to the folder where all output will be written
DATA_TYPE = PostgreSQL # "Delimited text files", "MySQL", "Oracle", "SQL Server", "PostgreSQL", "MS Access", or "Redshift"
SERVER_LOCATION = 127.0.0.1 # Name or address of the server. For Postgres, add the database name
USER_NAME = joe # User name for the database
PASSWORD = supersecret # Password for the database
DATABASE_NAME = my_database # Name of the data schema used
DELIMITER = , # The delimiter that separates values
TABLES_TO_SCAN = * # Comma-delimited list of table names to scan. Use "*" (asterix) to include all tables in the database
SCAN_FIELD_VALUES = yes # Include a frequency count of field values in the scan report? "yes" or "no"
MIN_CELL_COUNT = 5 # Minimum frequency for a field value to be included in the report
MAX_DISTINCT_VALUES = 1000 # Maximum number of distinct values per field to be reported
ROWS_PER_TABLE = 100000 # Maximum number of rows per table to be scanned for field values
2 changes: 1 addition & 1 deletion src/org/ohdsi/utilities/WhiteRabbitLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) throws Exception {

float heapSizeMegs = (Runtime.getRuntime().maxMemory() / 1024) / 1024;

if (heapSizeMegs > MIN_HEAP) {
if (heapSizeMegs > MIN_HEAP || args.length > 0) {
System.out.println("Launching with current VM");
WhiteRabbitMain.main(args);
} else {
Expand Down
46 changes: 46 additions & 0 deletions src/org/ohdsi/utilities/files/IniFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright 2016 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.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.ohdsi.utilities.files;

import java.util.HashMap;
import java.util.Map;

public class IniFile {
private Map<String, String> settings = new HashMap<String, String>();

public IniFile(String filename){
for (String line : new ReadTextFile(filename)){
int indexOfHash = line.lastIndexOf('#');
if (indexOfHash != -1)
line = line.substring(0,indexOfHash);

int indexOfEqualsSigns = line.indexOf('=');

if (indexOfEqualsSigns != -1)
settings.put(line.substring(0,indexOfEqualsSigns).trim().toLowerCase(), line.substring(indexOfEqualsSigns+1).trim());
}
}

public String get(String fieldName){
String value = settings.get(fieldName.toLowerCase());
if (value == null)
return "";
else
return value;
}
}
127 changes: 77 additions & 50 deletions src/org/ohdsi/whiteRabbit/WhiteRabbitMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.ohdsi.databases.RichConnection;
import org.ohdsi.utilities.DirectoryUtilities;
import org.ohdsi.utilities.StringUtilities;
import org.ohdsi.utilities.files.IniFile;
import org.ohdsi.whiteRabbit.fakeDataGenerator.FakeDataGenerator;
import org.ohdsi.whiteRabbit.scan.SourceDataScan;

Expand Down Expand Up @@ -119,27 +120,86 @@ public static void main(String[] args) {
}

public WhiteRabbitMain(String[] args) {
frame = new JFrame("White Rabbit");
if (args.length == 2 && args[0].equalsIgnoreCase("-ini"))
launchCommandLine(args[1]);
else {
frame = new JFrame("White Rabbit");

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setLayout(new BorderLayout());
frame.setJMenuBar(createMenuBar());

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setLayout(new BorderLayout());
frame.setJMenuBar(createMenuBar());
JComponent tabsPanel = createTabsPanel();
JComponent consolePanel = createConsolePanel();

JComponent tabsPanel = createTabsPanel();
JComponent consolePanel = createConsolePanel();
frame.add(consolePanel, BorderLayout.CENTER);
frame.add(tabsPanel, BorderLayout.NORTH);

frame.add(consolePanel, BorderLayout.CENTER);
frame.add(tabsPanel, BorderLayout.NORTH);
loadIcons(frame);
frame.pack();
frame.setVisible(true);
ObjectExchange.frame = frame;
}
}

loadIcons(frame);
frame.pack();
frame.setVisible(true);
ObjectExchange.frame = frame;
executeParameters(args);
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;
if (iniFile.get("DELIMITER").equalsIgnoreCase("tab"))
dbSettings.delimiter = '\t';
else
dbSettings.delimiter = iniFile.get("DELIMITER").charAt(0);
} else {
dbSettings.dataType = DbSettings.DATABASE;
dbSettings.user = iniFile.get("USER_NAME");
dbSettings.password = iniFile.get("PASSWORD");
dbSettings.server = iniFile.get("SERVER_LOCATION");
dbSettings.database = iniFile.get("DATABASE_NAME");
if (iniFile.get("DATA_TYPE").equalsIgnoreCase("MySQL"))
dbSettings.dbType = DbType.MYSQL;
else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("Oracle"))
dbSettings.dbType = DbType.ORACLE;
else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("PostgreSQL"))
dbSettings.dbType = DbType.POSTGRESQL;
else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("Redshift"))
dbSettings.dbType = DbType.REDSHIFT;
else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("SQL Server")) {
dbSettings.dbType = DbType.MSSQL;
if (iniFile.get("USER_NAME").length() != 0) { // Not using windows authentication
String[] parts = iniFile.get("USER_NAME").split("/");
if (parts.length == 2) {
dbSettings.user = parts[1];
dbSettings.domain = parts[0];
}
}
} else if (iniFile.get("DATA_TYPE").equalsIgnoreCase("MS Access"))
dbSettings.dbType = DbType.MSACCESS;
}
if (iniFile.get("TABLES_TO_SCAN").equalsIgnoreCase("*")) {
RichConnection connection = new RichConnection(dbSettings.server, dbSettings.domain, dbSettings.user, dbSettings.password, dbSettings.dbType);
for (String table : connection.getTableNames(dbSettings.database))
dbSettings.tables.add(table);
connection.close();
} else {
for (String table : iniFile.get("TABLES_TO_SCAN").split(",")) {
if (dbSettings.dataType == DbSettings.CSVFILES)
table = iniFile.get("WORKING_FOLDER") + "/" + table;
dbSettings.tables.add(table);
}
}

SourceDataScan sourceDataScan = new SourceDataScan();
int maxRows = Integer.parseInt(iniFile.get("ROWS_PER_TABLE"));
boolean scanValues = iniFile.get("SCAN_FIELD_VALUES").equalsIgnoreCase("yes");
int minCellCount = Integer.parseInt(iniFile.get("MIN_CELL_COUNT"));
int maxValues = Integer.parseInt(iniFile.get("MAX_DISTINCT_VALUES"));
sourceDataScan.process(dbSettings, maxRows, scanValues, minCellCount, maxValues, iniFile.get("WORKING_FOLDER") + "/ScanReport.xlsx");
}

private JComponent createTabsPanel() {
Expand Down Expand Up @@ -567,39 +627,6 @@ private Image loadIcon(String name, JFrame f) {
return null;
}

private void executeParameters(String[] args) {
String mode = null;
for (String arg : args) {
if (arg.startsWith("-")) {
mode = arg.toLowerCase();
} else {
if (mode.equals("-folder"))
folderField.setText(arg);
if (mode.equals("-targetpassword"))
targetPasswordField.setText(arg);
if (mode.equals("-targetserver"))
targetServerField.setText(arg);
if (mode.equals("-targettype"))
targetType.setSelectedItem(arg);
if (mode.equals("-targetdatabase"))
targetDatabaseField.setText(arg);
if (mode.equals("-targetuser"))
targetUserField.setText(arg);
if (mode.equals("-sourceserver"))
sourceServerField.setText(arg);
if (mode.equals("-sourcetype"))
sourceType.setSelectedItem(arg);
if (mode.equals("-sourcedatabase"))
sourceDatabaseField.setText(arg);
if (mode.equals("-sourceuser"))
sourceUserField.setText(arg);
if (mode.equals("-sourcepassword"))
sourcePasswordField.setText(arg);
mode = null;
}
}
}

private void pickFolder() {
JFileChooser fileChooser = new JFileChooser(new File(folderField.getText()));
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Expand Down

0 comments on commit 543eae7

Please sign in to comment.