Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Catch missing configuration row for external choices
  • Loading branch information
grzesiek2010 committed Sep 26, 2025
commit 376f1f6f457e9c429f31b73ec354fab34a409345
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ public static ArrayList<SelectChoice> populateExternalChoices(FormEntryPrompt fo
XPathFuncExpr xpathfuncexpr, FormController formController) throws FileNotFoundException {
try {
List<SelectChoice> selectChoices = formEntryPrompt.getSelectChoices();
if (containsConfigurationChoice(selectChoices)) {
String filePath = getFilePath(xpathfuncexpr, formController);
throw new FileNotFoundException(filePath);
}
ArrayList<SelectChoice> returnedChoices = new ArrayList<>();
for (SelectChoice selectChoice : selectChoices) {
String value = selectChoice.getValue();
Expand Down Expand Up @@ -212,14 +216,7 @@ public static ArrayList<SelectChoice> populateExternalChoices(FormEntryPrompt fo
}
return returnedChoices;
} catch (Exception e) {
String fileName = String.valueOf(xpathfuncexpr.args[0].eval(null, null));
if (!fileName.endsWith(".csv")) {
fileName = fileName + ".csv";
}
String filePath = fileName;
if (formController != null) {
filePath = formController.getMediaFolder() + File.separator + fileName;
}
String filePath = getFilePath(xpathfuncexpr, formController);
if (!new File(filePath).exists()) {
throw new FileNotFoundException(filePath);
}
Expand Down Expand Up @@ -345,4 +342,30 @@ public static boolean isAnInteger(String value) {
return false;
}
}

/**
* The config row is a special row in the choices worksheet that defines how
* choices are mapped from an external .csv file with list_name, name and label,
* where these correspond to columns in the .csv file.
*/
private static boolean containsConfigurationChoice(List<SelectChoice> selectChoices) {
for (SelectChoice choice : selectChoices) {
if (!isAnInteger(choice.getValue())) {
return false;
}
}
return true;
}

private static String getFilePath(XPathFuncExpr xpathfuncexpr, FormController formController) {
String fileName = String.valueOf(xpathfuncexpr.args[0].eval(null, null));
if (!fileName.endsWith(".csv")) {
fileName = fileName + ".csv";
}
String filePath = fileName;
if (formController != null) {
filePath = formController.getMediaFolder() + File.separator + fileName;
}
return filePath;
}
}