Skip to content

Commit

Permalink
S2U-26 getGradeableUsers refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bgarciaentornos committed Jun 10, 2024
1 parent 33e858c commit 59f86a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getGradeableUsers(final String gradebookUid, final String siteId, final GbGroup groupFilter) {
public List<String> getGradeableUsers(final String gradebookUid, final String siteId, final String groupFilter) {

try {

Expand All @@ -207,17 +207,14 @@ public List<String> getGradeableUsers(final String gradebookUid, final String si
final Set<String> 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<String> groupMembers = new HashSet<>();

if (groupFilter.getType() == GbGroup.Type.GROUP) {
final Set<Member> members = site.getGroup(groupFilter.getId())
.getMembers();
for (final Member m : members) {
if (userUuids.contains(m.getUserId())) {
groupMembers.add(m.getUserId());
}
final Set<Member> members = site.getGroup(groupId).getMembers();
for (final Member m : members) {
if (userUuids.contains(m.getUserId())) {
groupMembers.add(m.getUserId());
}
}

Expand Down Expand Up @@ -886,7 +883,7 @@ public List<GbStudentGradeInfo> buildGradeMatrix(final String gradebookUid, fina
* @param groupFilter
* @return
*/
public List<GbStudentGradeInfo> buildGradeMatrixForImportExport(final String gradebookUid, final String siteId, final List<Assignment> assignments, GbGroup groupFilter) throws GbException {
public List<GbStudentGradeInfo> buildGradeMatrixForImportExport(final String gradebookUid, final String siteId, final List<Assignment> assignments, String groupFilter) throws GbException {
// ------------- Initialization -------------
final GbStopWatch stopwatch = new GbStopWatch();
stopwatch.start();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<Double> getCategoryAssignmentTotals(String gradebookUid, String siteId, CategoryDefinition category, GbGroup group){
public List<Double> getCategoryAssignmentTotals(String gradebookUid, String siteId, CategoryDefinition category, String group){
final List<Double> allAssignmentGrades = new ArrayList<>();
final List<String> groupUsers = getGradeableUsers(gradebookUid, siteId, group);
final List<String> studentUUIDs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class GbGroup implements Comparable<GbGroup>, Serializable {
* Type of group
*/
public enum Type {
SECTION,
GROUP,
ALL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ public String getIdValue(final GbGroup g, final int index) {
}

final List<Assignment> assignments = this.businessService.getGradebookAssignments(gradebookUid, siteId, sortBy);
final List<String> students = this.businessService.getGradeableUsers(gradebookUid, siteId, settings.getGroupFilter());
String selectedGroup = settings.getGroupFilter() != null ? settings.getGroupFilter().getId() : null;
final List<String> students = this.businessService.getGradeableUsers(gradebookUid, siteId, selectedGroup);

this.hasGradebookItems = !assignments.isEmpty();
this.hasStudents = !students.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private File buildFile(final boolean isCustomExport) {
}

// get the grade matrix
final List<GbStudentGradeInfo> grades = this.businessService.buildGradeMatrixForImportExport(currentGradebookUid, currentSiteId, assignments, group);
final List<GbStudentGradeInfo> grades = this.businessService.buildGradeMatrixForImportExport(currentGradebookUid, currentSiteId, assignments, group.getId());

// add grades
grades.forEach(studentGradeInfo -> {
Expand Down

0 comments on commit 59f86a2

Please sign in to comment.