diff --git a/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/WhiteRabbitMain.java b/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/WhiteRabbitMain.java index c661400b..66ad57dd 100644 --- a/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/WhiteRabbitMain.java +++ b/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/WhiteRabbitMain.java @@ -271,9 +271,11 @@ public void actionPerformed(ActionEvent e) { sourceType = new JComboBox<>(new String[] { "Delimited text files", "SAS7bdat", "MySQL", "Oracle", "SQL Server", "PostgreSQL", "MS Access", "PDW", "Redshift", "Teradata", "BigQuery" }); sourceType.setToolTipText("Select the type of source data available"); sourceType.addItemListener(itemEvent -> { - sourceIsFiles = itemEvent.getItem().toString().equals("Delimited text files"); - sourceIsSas = itemEvent.getItem().toString().equals("SAS7bdat"); + String selectedSourceType = itemEvent.getItem().toString(); + sourceIsFiles = selectedSourceType.equals("Delimited text files"); + sourceIsSas = selectedSourceType.equals("SAS7bdat"); boolean sourceIsDatabase = !(sourceIsFiles || sourceIsSas); + sourceServerField.setEnabled(sourceIsDatabase); sourceUserField.setEnabled(sourceIsDatabase); sourcePasswordField.setEnabled(sourceIsDatabase); @@ -281,24 +283,24 @@ public void actionPerformed(ActionEvent e) { sourceDelimiterField.setEnabled(sourceIsFiles); addAllButton.setEnabled(sourceIsDatabase); - if (sourceIsDatabase && itemEvent.getItem().toString().equals("Oracle")) { + if (sourceIsDatabase && selectedSourceType.equals("Oracle")) { sourceServerField.setToolTipText("For Oracle servers this field contains the SID, servicename, and optionally the port: '/', ':/', '/', or ':/'"); sourceUserField.setToolTipText("For Oracle servers this field contains the name of the user used to log in"); sourcePasswordField.setToolTipText("For Oracle servers this field contains the password corresponding to the user"); sourceDatabaseField.setToolTipText("For Oracle servers this field contains the schema (i.e. 'user' in Oracle terms) containing the source tables"); - } else if (sourceIsDatabase && itemEvent.getItem().toString().equals("PostgreSQL")) { + } else if (sourceIsDatabase && selectedSourceType.equals("PostgreSQL")) { sourceServerField.setToolTipText("For PostgreSQL servers this field contains the host name and database name (/)"); sourceUserField.setToolTipText("The user used to log in to the server"); sourcePasswordField.setToolTipText("The password used to log in to the server"); sourceDatabaseField.setToolTipText("For PostgreSQL servers this field contains the schema containing the source tables"); - } else if (sourceIsDatabase && itemEvent.getItem().toString().equals("BigQuery")) { + } else if (sourceIsDatabase && selectedSourceType.equals("BigQuery")) { sourceServerField.setToolTipText("GBQ SA & UA: ProjectID"); sourceUserField.setToolTipText("GBQ SA only: OAuthServiceAccountEMAIL"); sourcePasswordField.setToolTipText("GBQ SA only: OAuthPvtKeyPath"); sourceDatabaseField.setToolTipText("GBQ SA & UA: Data Set within ProjectID"); } else if (sourceIsDatabase) { sourceServerField.setToolTipText("This field contains the name or IP address of the database server"); - if (itemEvent.getItem().toString().equals("SQL Server")) { + if (selectedSourceType.equals("SQL Server")) { sourceUserField.setToolTipText("The user used to log in to the server. Optionally, the domain can be specified as / (e.g. 'MyDomain/Joe')"); } else { sourceUserField.setToolTipText("The user used to log in to the server"); diff --git a/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/scan/SourceDataScan.java b/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/scan/SourceDataScan.java index e1126bf6..7d6a4d2a 100644 --- a/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/scan/SourceDataScan.java +++ b/whiterabbit/src/main/java/org/ohdsi/whiteRabbit/scan/SourceDataScan.java @@ -390,7 +390,7 @@ private List processCsvFile(String filename) { fieldInfos.get(i).processValue(row.get(i)); } } - if (sampleSize != -1 && lineNr == sampleSize) + if (lineNr == sampleSize) break; } for (FieldInfo fieldInfo : fieldInfos) @@ -403,28 +403,24 @@ private List processSasFile(String filename) { StringUtilities.outputWithTime("Scanning table " + filename); List fieldInfos = new ArrayList<>(); - // TODO: try with resources and print warning on exception - FileInputStream inputStream; - try { - inputStream = new FileInputStream(new File(filename)); - + try(FileInputStream inputStream = new FileInputStream(new File(filename))) { SasFileReader sasFileReader = new SasFileReaderImpl(inputStream); - // TODO: retrieve more information from the sasFileProperties, like data type and length. + // It is possible to retrieve more information from the sasFileProperties, like data type and length. SasFileProperties sasFileProperties = sasFileReader.getSasFileProperties(); for (Column column : sasFileReader.getColumns()) { fieldInfos.add(new FieldInfo(column.getName())); } - for (int i = 0; i < sasFileProperties.getRowCount(); i++) { + for (int lineNr = 0; lineNr < sasFileProperties.getRowCount(); lineNr++) { Object[] row = sasFileReader.readNext(); if (row.length == fieldInfos.size()) { // Else there appears to be a formatting error, so skip - for (int j = 0; j < row.length; j++) { - fieldInfos.get(j).processValue(row[j] == null ? "" : row[j].toString()); + for (int i = 0; i < row.length; i++) { + fieldInfos.get(i).processValue(row[i] == null ? "" : row[i].toString()); } } - if (sampleSize != -1 && i == sampleSize) + if (lineNr == sampleSize) break; } inputStream.close();