Skip to content

Commit

Permalink
Merge pull request #89 from marc-outins/fix_bug_loading_target
Browse files Browse the repository at this point in the history
Fixes bug that caused crash from loading target schema's
  • Loading branch information
schuemie committed Jun 18, 2015
2 parents 28dc2a7 + 6e5841a commit c343f8d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 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 @@ -26,7 +26,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
13 changes: 9 additions & 4 deletions src/org/ohdsi/rabbitInAHat/MappingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class MappingPanel extends JPanel implements MouseListener, MouseMotionLi

private Mapping<?> mapping;
private List<LabeledRectangle> sourceComponents = new ArrayList<LabeledRectangle>();
private List<LabeledRectangle> cdmComponents = new ArrayList<LabeledRectangle>();
private List<LabeledRectangle> cdmComponents = new ArrayList<LabeledRectangle>();
private List<Arrow> arrows = new ArrayList<Arrow>();
private LabeledRectangle dragRectangle = null;
private LabeledRectangle lastSelectedRectangle = null;
Expand All @@ -84,6 +85,8 @@ public class MappingPanel extends JPanel implements MouseListener, MouseMotionLi
private MappingPanel slaveMappingPanel;
private boolean showOnlyConnectedItems = false;

private int shortcutMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

private String lastSourceFilter = "";
private String lastTargetFilter = "";

Expand Down Expand Up @@ -355,8 +358,8 @@ public void mouseClicked(MouseEvent event) {
detailsListener.showDetails(null);
selectedArrow = null;
}
if (!event.isShiftDown() && !event.isControlDown()){

if (!event.isShiftDown() && !( (event.getModifiers() & shortcutMask ) == shortcutMask )){
for( LabeledRectangle component : cdmComponents){
component.setSelected(false);
}
Expand All @@ -370,6 +373,7 @@ public void mouseClicked(MouseEvent event) {
}else if (event.getX() > cdmX && event.getX() < cdmX + ITEM_WIDTH) { // target component
LabeledRectangleClicked(event, getVisibleTargetComponents());
}else if (event.getX() > sourceX + ITEM_WIDTH && event.getX() < cdmX) { // Arrows
lastSelectedRectangle = null;
Arrow clickedArrow = null;
for (HighlightStatus status: HighlightStatus.values()) {
for (Arrow arrow : currentArrowStatus.get(status)) {
Expand Down Expand Up @@ -407,6 +411,7 @@ public void mouseClicked(MouseEvent event) {
detailsListener.showDetails(null);
}
}else{
lastSelectedRectangle = null;
detailsListener.showDetails(null);
}

Expand Down Expand Up @@ -696,7 +701,7 @@ private void LabeledRectangleClicked(MouseEvent event, List<LabeledRectangle> co

if (component.contains(event.getPoint())) {

if(event.isControlDown()){ // Add one at a time
if((event.getModifiers() & shortcutMask ) == shortcutMask ){ // Add one at a time
component.toggleSelected();
}else if(event.isShiftDown()){ // Add in consecutive order

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 c343f8d

Please sign in to comment.