Skip to content

Commit

Permalink
readability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Moinat committed Dec 24, 2019
1 parent b1b1c73 commit faaeb76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,34 +271,36 @@ 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);
sourceDatabaseField.setEnabled(sourceIsDatabase);
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: '<host>/<sid>', '<host>:<port>/<sid>', '<host>/<service name>', or '<host>:<port>/<service name>'");
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 (<host>/<database>)");
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 <domain>/<user> (e.g. 'MyDomain/Joe')");
} else {
sourceUserField.setToolTipText("The user used to log in to the server");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private List<FieldInfo> processCsvFile(String filename) {
fieldInfos.get(i).processValue(row.get(i));
}
}
if (sampleSize != -1 && lineNr == sampleSize)
if (lineNr == sampleSize)
break;
}
for (FieldInfo fieldInfo : fieldInfos)
Expand All @@ -403,28 +403,24 @@ private List<FieldInfo> processSasFile(String filename) {
StringUtilities.outputWithTime("Scanning table " + filename);
List<FieldInfo> 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();
Expand Down

0 comments on commit faaeb76

Please sign in to comment.