From ea0ba2fa73fd350ea8cfd77ec169d35727308820 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Wed, 9 Jan 2019 17:57:16 +0100 Subject: [PATCH] OO-3804: double check if exported item doesn't exist (deleted or else) --- .../modules/qpool/manager/QuestionPoolServiceImpl.java | 2 +- .../modules/qpool/ui/AbstractItemListController.java | 3 +++ .../org/olat/modules/qpool/ui/QuestionItemDataModel.java | 9 +++++++++ .../olat/modules/qpool/ui/wizard/Export_1_TypeStep.java | 3 +-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java b/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java index 7e0ca593a85..fd0677313c1 100644 --- a/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java +++ b/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java @@ -389,7 +389,7 @@ public class QuestionPoolServiceImpl implements QPoolService { @Override public Set<ExportFormatOptions> getExportFormatOptions(List<QuestionItemShort> items, Outcome outcome) { return items.stream() - .filter(item -> StringHelper.containsNonWhitespace(item.getFormat())) + .filter(item -> item != null && StringHelper.containsNonWhitespace(item.getFormat())) .map(QuestionItemShort::getFormat) .map(qpoolModule::getQuestionPoolProvider) .map(QPoolSPI::getTestExportFormats) diff --git a/src/main/java/org/olat/modules/qpool/ui/AbstractItemListController.java b/src/main/java/org/olat/modules/qpool/ui/AbstractItemListController.java index 2d36eded338..fc14d62a39f 100644 --- a/src/main/java/org/olat/modules/qpool/ui/AbstractItemListController.java +++ b/src/main/java/org/olat/modules/qpool/ui/AbstractItemListController.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -370,7 +371,9 @@ public abstract class AbstractItemListController extends FormBasicController public List<QuestionItemShort> getSelectedShortItems() { return getItemsTable().getMultiSelectedIndex().stream() + .filter(index -> getModel().ensureLoaded(index.intValue(), itemsTable)) .map(index -> getModel().getObject(index.intValue())) + .filter(Objects::nonNull) .collect(Collectors.toList()); } diff --git a/src/main/java/org/olat/modules/qpool/ui/QuestionItemDataModel.java b/src/main/java/org/olat/modules/qpool/ui/QuestionItemDataModel.java index ff18faa835f..7de91532f9e 100644 --- a/src/main/java/org/olat/modules/qpool/ui/QuestionItemDataModel.java +++ b/src/main/java/org/olat/modules/qpool/ui/QuestionItemDataModel.java @@ -22,6 +22,7 @@ package org.olat.modules.qpool.ui; import java.text.DecimalFormat; import java.util.List; +import org.olat.core.gui.components.form.flexible.elements.FlexiTableElement; import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableDataSourceModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataSourceDelegate; @@ -55,6 +56,14 @@ public class QuestionItemDataModel extends DefaultFlexiTableDataSourceModel<Item return null; } + public boolean ensureLoaded(int row, FlexiTableElement tableEl) { + if(isRowLoaded(row) ) { + return true; + } + tableEl.preloadPageOfObjectIndex(row - 1); + return isRowLoaded(row); + } + @Override public QuestionItemDataModel createCopyWithEmptyList() { return new QuestionItemDataModel(getTableColumnModel(), getSourceDelegate(), translator); diff --git a/src/main/java/org/olat/modules/qpool/ui/wizard/Export_1_TypeStep.java b/src/main/java/org/olat/modules/qpool/ui/wizard/Export_1_TypeStep.java index 7806c7c06cd..45cb6a32e77 100644 --- a/src/main/java/org/olat/modules/qpool/ui/wizard/Export_1_TypeStep.java +++ b/src/main/java/org/olat/modules/qpool/ui/wizard/Export_1_TypeStep.java @@ -55,7 +55,6 @@ public class Export_1_TypeStep extends BasicStep { @Override public StepFormController getStepController(UserRequest ureq, WindowControl wControl, StepsRunContext runContext, Form form) { runContext.put("items", items); - ExportTypeController controller = new ExportTypeController(ureq, wControl, form, runContext, items); - return controller; + return new ExportTypeController(ureq, wControl, form, runContext, items); } } -- GitLab