Skip to content

Commit

Permalink
Fixes bug that caused crash from loading target schema's
Browse files Browse the repository at this point in the history
This fixes a bug that caused the program to crash when trying to run outside of eclipse.  Also renames the cdmv4 and cdmv5 csv's so the schema name does not include the word model.
  • Loading branch information
Marc Halperin committed Jun 17, 2015
1 parent d86ca2a commit 6e5841a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/org/ohdsi/rabbitInAHat/DetailsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.text.DecimalFormat;
import java.util.ArrayList;
Expand Down
24 changes: 20 additions & 4 deletions src/org/ohdsi/rabbitInAHat/RabbitInAHatMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileFilter;
Expand Down Expand Up @@ -376,11 +381,22 @@ public void actionPerformed(ActionEvent event) {
}

private void doSetTargetCustom(String fileName) {
ETL etl = new ETL(ObjectExchange.etl.getSourceDatabase(),Database.generateModelFromCSV(fileName));

etl.copyETLMappings(ObjectExchange.etl);
tableMappingPanel.setMapping(etl.getTableToTableMapping());
ObjectExchange.etl = etl;
if( fileName != null ){
File file = new File(fileName);
InputStream stream;

try{
stream = new FileInputStream(file);
ETL etl = new ETL(ObjectExchange.etl.getSourceDatabase(),Database.generateModelFromCSV(stream, file.getName()));

etl.copyETLMappings(ObjectExchange.etl);
tableMappingPanel.setMapping(etl.getTableToTableMapping());
ObjectExchange.etl = etl;
}catch (IOException e) {
//Do nothing if error
}
}

}

Expand Down
23 changes: 10 additions & 13 deletions src/org/ohdsi/rabbitInAHat/dataModel/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
******************************************************************************/
package org.ohdsi.rabbitInAHat.dataModel;

import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -33,15 +33,13 @@
public class Database implements Serializable {

public enum CDMVersion {
CDMV4 ("CDMV4Model.csv", "CDMv4"),
CDMV5 ("CDMv5Model.csv", "CDMv5");
CDMV4 ("CDMV4.csv"),
CDMV5 ("CDMV5.csv");

private final String fileName;
private final String dbName;

CDMVersion(String fileName, String dbName){
CDMVersion(String fileName){
this.fileName = fileName;
this.dbName = dbName;
}
}

Expand All @@ -62,18 +60,16 @@ public String getDbName(){
}

public static Database generateCDMModel(CDMVersion cdmVersion) {
String path = Database.class.getResource(cdmVersion.fileName).getFile();
return Database.generateModelFromCSV(path);
return Database.generateModelFromCSV(Database.class.getResourceAsStream(cdmVersion.fileName), cdmVersion.fileName);
}

public static Database generateModelFromCSV(String fileName) {
public static Database generateModelFromCSV(InputStream stream, String dbName) {
Database database = new Database();

String dbname = new File(fileName).getName();
database.dbName = dbname.substring(0,dbname.lastIndexOf("."));

database.dbName = dbName.substring(0, dbName.lastIndexOf("."));

Map<String, Table> nameToTable = new HashMap<String, Table>();
for (Row row : new ReadCSVFileWithHeader(fileName)) {
for (Row row : new ReadCSVFileWithHeader(stream)) {

Table table = nameToTable.get(row.get("TABLE_NAME").toLowerCase());

Expand Down Expand Up @@ -171,4 +167,5 @@ private static String[][] getValueCounts(QuickAndDirtyXlsxReader workbook, Strin
}
return list.toArray(new String[list.size()][2]);
}

}

0 comments on commit 6e5841a

Please sign in to comment.