diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModel.java b/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModel.java index 3fcc24cef2c26088ac3d6159282088a8fdfcb86f..404c1be33ae8592173826396aa07b03c248be2db 100644 --- a/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModel.java +++ b/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModel.java @@ -22,11 +22,13 @@ package org.olat.modules.lecture.ui.coach; import java.util.List; import java.util.Locale; +import org.apache.logging.log4j.Logger; import org.olat.core.commons.persistence.SortKey; import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableDataModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiSortableColumnDef; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.SortableFlexiTableDataModel; +import org.olat.core.logging.Tracing; import org.olat.modules.lecture.model.LectureReportRow; /** @@ -38,6 +40,8 @@ import org.olat.modules.lecture.model.LectureReportRow; public class LecturesReportTableModel extends DefaultFlexiTableDataModel<LectureReportRow> implements SortableFlexiTableDataModel<LectureReportRow> { + private static final Logger log = Tracing.createLoggerFor(LecturesReportTableModel.class); + private final Locale locale; public LecturesReportTableModel(FlexiTableColumnModel columnsModel, Locale locale) { @@ -48,8 +52,12 @@ implements SortableFlexiTableDataModel<LectureReportRow> { @Override public void sort(SortKey orderBy) { if(orderBy != null) { - List<LectureReportRow> rows = new LecturesReportTableModelSortDelegate(orderBy, this, locale).sort(); - setObjects(rows); + try { + List<LectureReportRow> rows = new LecturesReportTableModelSortDelegate(orderBy, this, locale).sort(); + setObjects(rows); + } catch (Exception e) { + log.error("", e); + } } } diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModelSortDelegate.java b/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModelSortDelegate.java index c8e6ac3876b0d34277ab7c6a77a89adb9d24b0cb..f45f9db11f6c577a5fa748cb1e0523d34b82f30c 100644 --- a/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModelSortDelegate.java +++ b/src/main/java/org/olat/modules/lecture/ui/coach/LecturesReportTableModelSortDelegate.java @@ -30,6 +30,7 @@ import org.olat.core.id.Identity; import org.olat.modules.lecture.LectureRollCallStatus; import org.olat.modules.lecture.model.LectureReportRow; import org.olat.modules.lecture.ui.coach.LecturesReportTableModel.ReportCols; +import org.olat.modules.lecture.ui.component.IdentityComparator; /** * @@ -39,8 +40,11 @@ import org.olat.modules.lecture.ui.coach.LecturesReportTableModel.ReportCols; */ public class LecturesReportTableModelSortDelegate extends SortableFlexiTableModelDelegate<LectureReportRow> { + private final Locale locale; + public LecturesReportTableModelSortDelegate(SortKey orderBy, LecturesReportTableModel tableModel, Locale locale) { super(orderBy, tableModel, locale); + this.locale = locale; } @Override @@ -85,7 +89,17 @@ public class LecturesReportTableModelSortDelegate extends SortableFlexiTableMode c = 1; } else if(i1.isEmpty() && !i2.isEmpty()) { c = -1; + } else if(i1.size() == 1 && i2.size() == 1) { + c = compareIdentity(i1.get(0), i2.get(0)); } else { + // make sure the order are the same + if(i1.size() > 1) { + Collections.sort(i1, new IdentityComparator(locale)); + } + if(i2.size() > 1) { + Collections.sort(i2, new IdentityComparator(locale)); + } + int max = Math.min(i1.size(), i2.size()); for(int i=0; i<max && c == 0; i++) { c = compareIdentity(i1.get(i), i2.get(i)); @@ -99,7 +113,7 @@ public class LecturesReportTableModelSortDelegate extends SortableFlexiTableMode return compareNullObjects(i1, i2); } - int c = compareString(i1.getUser().getLastName(), i2.getUser().getLastName()); + int c = compareString(i1.getUser().getLastName(), i1.getUser().getLastName()); if(c == 0) { c = compareString(i1.getUser().getFirstName(), i2.getUser().getFirstName()); }