From 59f86a2e7c13b3c7632879d8eb10a3fa88a5843d Mon Sep 17 00:00:00 2001 From: bgarciaentornos Date: Fri, 2 Feb 2024 11:04:08 +0100 Subject: [PATCH] S2U-26 getGradeableUsers refactor --- .../business/GradebookNgBusinessService.java | 25 ++++++++----------- .../gradebookng/business/model/GbGroup.java | 1 - .../tool/model/GbGradeTableData.java | 3 ++- .../gradebookng/tool/pages/GradebookPage.java | 3 ++- .../tool/panels/UpdateUngradedItemsPanel.java | 2 +- .../tool/panels/importExport/ExportPanel.java | 2 +- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java index fd9eda2be1f5..6b978ea99609 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java @@ -192,11 +192,11 @@ public class GradebookNgBusinessService { * Get a list of all users in the given site, filtered by the given group, that can have grades * * @param siteId the id of the site to lookup - * @param groupFilter GbGroupType to filter on + * @param groupFilter Group to filter on * * @return a list of users as uuids or null if none */ - public List getGradeableUsers(final String gradebookUid, final String siteId, final GbGroup groupFilter) { + public List getGradeableUsers(final String gradebookUid, final String siteId, final String groupFilter) { try { @@ -207,17 +207,14 @@ public List getGradeableUsers(final String gradebookUid, final String si final Set userUuids = site.getUsersIsAllowed(GbRole.STUDENT.getValue()); // filter the allowed list based on membership - if (groupFilter != null && groupFilter.getType() != GbGroup.Type.ALL) { - + if (StringUtils.isNotBlank(groupFilter) || !gradebookUid.equals(siteId)) { + String groupId = StringUtils.isNotBlank(groupFilter) ? groupFilter : gradebookUid; final Set groupMembers = new HashSet<>(); - if (groupFilter.getType() == GbGroup.Type.GROUP) { - final Set members = site.getGroup(groupFilter.getId()) - .getMembers(); - for (final Member m : members) { - if (userUuids.contains(m.getUserId())) { - groupMembers.add(m.getUserId()); - } + final Set members = site.getGroup(groupId).getMembers(); + for (final Member m : members) { + if (userUuids.contains(m.getUserId())) { + groupMembers.add(m.getUserId()); } } @@ -886,7 +883,7 @@ public List buildGradeMatrix(final String gradebookUid, fina * @param groupFilter * @return */ - public List buildGradeMatrixForImportExport(final String gradebookUid, final String siteId, final List assignments, GbGroup groupFilter) throws GbException { + public List buildGradeMatrixForImportExport(final String gradebookUid, final String siteId, final List assignments, String groupFilter) throws GbException { // ------------- Initialization ------------- final GbStopWatch stopwatch = new GbStopWatch(); stopwatch.start(); @@ -2002,7 +1999,7 @@ public void updateAssignment(final String gradebookUid, final String siteId, fin * @param group * @return */ - public boolean updateUngradedItems(final String gradebookUid, final String siteId, final long assignmentId, final String grade, final GbGroup group) { + public boolean updateUngradedItems(final String gradebookUid, final String siteId, final long assignmentId, final String grade, final String group) { final Gradebook gradebook = getGradebook(gradebookUid, siteId); final Assignment assignment = getAssignment(gradebookUid, siteId, assignmentId); @@ -2680,7 +2677,7 @@ private String getAttendanceIconClass() { * @param group group of students - apparently never used so far * @return allAssignmentGrades list of assignment averages for a specific group */ - public List getCategoryAssignmentTotals(String gradebookUid, String siteId, CategoryDefinition category, GbGroup group){ + public List getCategoryAssignmentTotals(String gradebookUid, String siteId, CategoryDefinition category, String group){ final List allAssignmentGrades = new ArrayList<>(); final List groupUsers = getGradeableUsers(gradebookUid, siteId, group); final List studentUUIDs = new ArrayList<>(); diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/model/GbGroup.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/model/GbGroup.java index 1667e459fbd7..b6bb8cb0b240 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/model/GbGroup.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/model/GbGroup.java @@ -48,7 +48,6 @@ public class GbGroup implements Comparable, Serializable { * Type of group */ public enum Type { - SECTION, GROUP, ALL; } diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/model/GbGradeTableData.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/model/GbGradeTableData.java index 5f30d97d0f37..3d0ea1f53c1c 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/model/GbGradeTableData.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/model/GbGradeTableData.java @@ -84,9 +84,10 @@ public GbGradeTableData(final String currentGradebookUid, final String currentSi ); stopwatch.time("getGradebookAssignments", stopwatch.getTime()); + String groupFilter = uiSettings.getGroupFilter() != null ? uiSettings.getGroupFilter().getId() : null; grades = businessService.buildGradeMatrix(currentGradebookUid, currentSiteId, assignments, - businessService.getGradeableUsers(currentGradebookUid, currentSiteId, uiSettings.getGroupFilter()), + businessService.getGradeableUsers(currentGradebookUid, currentSiteId, groupFilter), settings); stopwatch.time("buildGradeMatrix", stopwatch.getTime()); diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java index b663656cdd71..0c643cd273a5 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java @@ -276,7 +276,8 @@ public String getIdValue(final GbGroup g, final int index) { } final List assignments = this.businessService.getGradebookAssignments(gradebookUid, siteId, sortBy); - final List students = this.businessService.getGradeableUsers(gradebookUid, siteId, settings.getGroupFilter()); + String selectedGroup = settings.getGroupFilter() != null ? settings.getGroupFilter().getId() : null; + final List students = this.businessService.getGradeableUsers(gradebookUid, siteId, selectedGroup); this.hasGradebookItems = !assignments.isEmpty(); this.hasStudents = !students.isEmpty(); diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/UpdateUngradedItemsPanel.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/UpdateUngradedItemsPanel.java index c4a51b7aa6c4..22374d8f0e86 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/UpdateUngradedItemsPanel.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/UpdateUngradedItemsPanel.java @@ -112,7 +112,7 @@ public void onSubmit(final AjaxRequestTarget target) { target.addChildren(form, FeedbackPanel.class); } - final boolean success = businessService.updateUngradedItems(currentGradebookUid, currentSiteId, assignmentId, override.getGrade(), group); + final boolean success = businessService.updateUngradedItems(currentGradebookUid, currentSiteId, assignmentId, override.getGrade(), group.getId()); if (success) { UpdateUngradedItemsPanel.this.window.close(target); diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/ExportPanel.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/ExportPanel.java index 28fc812f5bbf..26f3e48fd9a1 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/ExportPanel.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/ExportPanel.java @@ -413,7 +413,7 @@ private File buildFile(final boolean isCustomExport) { } // get the grade matrix - final List grades = this.businessService.buildGradeMatrixForImportExport(currentGradebookUid, currentSiteId, assignments, group); + final List grades = this.businessService.buildGradeMatrixForImportExport(currentGradebookUid, currentSiteId, assignments, group.getId()); // add grades grades.forEach(studentGradeInfo -> {