Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AIS - improved error handling for bulk import #29

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Category assignments without a selected replacement are being discarded.</entry>
<entry key="Ais.Project.Export.Html">HTML File</entry>
<entry key="Ais.Project.Export.Ods">Spreadsheet (only Results)</entry>
<entry key="Ais.Project.Import.Interviews.Ods">Import Interviews (from Spreadsheet)</entry>
<entry key="Ais.Project.Import.Interviews.Ods.InvalidSpreadsheet">An import spreadsheet should have at least one sheet and at least two columns and rows on that sheet.
<entry key="Ais.Project.Import.Interviews.Ods.InvalidSpreadsheet">An import spreadsheet should be an *.ods (OpenDocument Spreadsheet) file.
It should also have at least one sheet and at least two columns and rows on that sheet.

One column is expected to contain the Participant IDs and another column should contain the associated interview texts.</entry>
<entry key="Ais.Project.Import.Interviews.Ods.Preview.Participant">Participant ID</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Zugeordnete Kategorien ohne Entsprechung im neuen Modell werden verworfen!</entr
<entry key="Ais.Project.Export.Html">HTML-Datei</entry>
<entry key="Ais.Project.Export.Ods">ODS-Datei (Ergebnistabellen)</entry>
<entry key="Ais.Project.Import.Interviews.Ods">Importiere Interviews (aus ODS-Spreadsheet)</entry>
<entry key="Ais.Project.Import.Interviews.Ods.InvalidSpreadsheet">Ein Spreadsheet kann nur für den Import verwendet werden, wenn es mindesten ein Tabellenblatt enthält, mit mindestens zwei Spalten und zwei Zeilen.
<entry key="Ais.Project.Import.Interviews.Ods.InvalidSpreadsheet">Ein Import-Spreadsheet sollte vom Typ *.ods (OpenDocument Spreadsheet) sein.
Darüber hinaus sollte es mindestens ein Tabellenblatt enthalten, mit mindestens zwei Spalten und zwei Zeilen.

Eine Spalte sollte den Bezeichner der Studienteilnehmer enthalten und die andere Spalte die Interview-Mitschrift.</entry>
<entry key="Ais.Project.Import.Interviews.Ods.Preview.Participant">Teilnehmer</entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.IntStream;
import javax.swing.SwingUtilities;
import org.hmx.scitos.ais.core.AisModelHandler;
import org.hmx.scitos.ais.core.i18n.AisMessage;
Expand Down Expand Up @@ -224,8 +225,16 @@ public void importInterviewsFromOds() {
return;
}
try {
final SpreadSheet importFile = SpreadSheet.createFromFile(path);
if (importFile.getSheetCount() == 0) {
final SpreadSheet importFile;
try {
importFile = SpreadSheet.createFromFile(path);
} catch (NullPointerException ex) {
throw new HmxException(AisMessage.PROJECT_IMPORT_INTERVIEWS_INVALID_SPREADSHEET, ex);
}
if (IntStream.range(0, importFile.getSheetCount())
.mapToObj(importFile::getSheet)
.filter(sheet -> sheet.getColumnCount() > 1 && sheet.getRowCount() > 1)
.noneMatch(sheet -> !sheet.getImmutableCellAt(0, 0).isEmpty() && !sheet.getImmutableCellAt(1, 0).isEmpty())) {
throw new HmxException(AisMessage.PROJECT_IMPORT_INTERVIEWS_INVALID_SPREADSHEET);
}
new SpreadsheetInterviewImportDialog(this.modelHandler, importFile).setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public SpreadsheetInterviewImportDialog(final AisModelHandler modelHandler, fina
this.sheetSelection = new JComboBox<>(IntStream.range(0, spreadsheet.getSheetCount())
.mapToObj(spreadsheet::getSheet)
.filter(sheet -> sheet.getColumnCount() > 1 && sheet.getRowCount() > 1)
.filter(sheet -> !sheet.getImmutableCellAt(0, 0).isEmpty() && !sheet.getImmutableCellAt(1, 0).isEmpty())
.map(SheetComboBoxItem::new)
.toArray(SheetComboBoxItem[]::new));
contentPane.add(this.createSelectionForm(), BorderLayout.NORTH);
Expand Down