From f6e236b8b50b6ff2f7d086cf9e874fa15aba9839 Mon Sep 17 00:00:00 2001 From: Carsten Wickner Date: Mon, 9 Mar 2020 22:39:49 +0100 Subject: [PATCH] fix: AIS - improved error handling for bulk import --- .../org/hmx/scitos/ais/core/i18n/AisMessage.xml | 3 ++- .../org/hmx/scitos/ais/core/i18n/AisMessage_de.xml | 3 ++- .../hmx/scitos/ais/view/swing/AisViewProject.java | 13 +++++++++++-- .../SpreadsheetInterviewImportDialog.java | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage.xml b/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage.xml index 3f1992d..c84cec2 100644 --- a/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage.xml +++ b/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage.xml @@ -73,7 +73,8 @@ Category assignments without a selected replacement are being discarded. HTML File Spreadsheet (only Results) Import Interviews (from Spreadsheet) - An import spreadsheet should have at least one sheet and at least two columns and rows on that sheet. + 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. Participant ID diff --git a/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage_de.xml b/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage_de.xml index 0a15beb..6f08178 100644 --- a/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage_de.xml +++ b/scitos.ais/scitos.ais.core/src/main/resources/org/hmx/scitos/ais/core/i18n/AisMessage_de.xml @@ -76,7 +76,8 @@ Zugeordnete Kategorien ohne Entsprechung im neuen Modell werden verworfen!HTML-Datei ODS-Datei (Ergebnistabellen) Importiere Interviews (aus ODS-Spreadsheet) - Ein Spreadsheet kann nur für den Import verwendet werden, wenn es mindesten ein Tabellenblatt enthält, mit mindestens zwei Spalten und zwei Zeilen. + 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. Teilnehmer diff --git a/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/AisViewProject.java b/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/AisViewProject.java index 27c4926..3019e2b 100644 --- a/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/AisViewProject.java +++ b/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/AisViewProject.java @@ -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; @@ -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); diff --git a/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/components/SpreadsheetInterviewImportDialog.java b/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/components/SpreadsheetInterviewImportDialog.java index 1b2f69c..eb0bd1a 100644 --- a/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/components/SpreadsheetInterviewImportDialog.java +++ b/scitos.ais/scitos.ais.view/src/main/java/org/hmx/scitos/ais/view/swing/components/SpreadsheetInterviewImportDialog.java @@ -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);