Skip to content

Commit

Permalink
S2U-26 Gradebook: support for group instances
Browse files Browse the repository at this point in the history
Co-authored-by: jumarub <[email protected]>
Co-authored-by: JuanDavid102 <[email protected]>
  • Loading branch information
3 people committed Sep 6, 2024
1 parent 9c66d92 commit 68be104
Show file tree
Hide file tree
Showing 184 changed files with 5,085 additions and 4,524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,14 @@ public String getDeepLinkWithPermissions(String context, String assignmentId, bo
public List<ContentResource> getAllAcceptableAttachments(AssignmentSubmission submission);

/**
* Get an assignment that is linked with a gradebook item
* Get assignments that are linked with a gradebook item
* @param context the context (site id)
* @param linkId the link id of the gradebook item, usually the gradebook item name or id
* @return the matching assignment if found or empty if none
* @return the matching assignments if found or null if none
* @throws IdUnusedException if the assignment doesn't exist
* @throws PermissionException if the current user is not allowed to access the assignment
*/
Optional<Assignment> getAssignmentForGradebookLink(String context, String linkId) throws IdUnusedException, PermissionException;
List<Assignment> getAssignmentsForGradebookLink(String context, String linkId) throws IdUnusedException, PermissionException;

/**
* Returns a list of users that belong to multiple groups, if the user is considered a "student" in the group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ AssignmentSubmission newSubmission(String assignmentId,
void resetAssignment(Assignment assignment);

/**
* Find an assignment that is linked with to a gradebook item
* Find assignments that are linked with to a gradebook item
* @param context the context the assignment is in
* @param linkId the linked id or name of the gradebook item
* @return the assignment id or empty if none is found
*/
Optional<String> findAssignmentIdForGradebookLink(String context, String linkId);
List<Assignment> findAssignmentsForGradebookLink(String context, String linkId);

Collection<String> findGroupsForAssignmentById(String assignmentId);

Expand Down
2 changes: 2 additions & 0 deletions assignment/api/src/resources/assignment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ range.allgroups = site

group = Group
groups = Groups
group.sitegradebook.noitem.selected=Selected groups must have a gradebook item associated with them
group.sitegradebook.nopermission=Site assignments cannot be created when there are group gradebooks.
group.editsite.nopermission = Cannot edit the group state due to site permissions.
group.list.summary = Table contains list of groups. First will contain checkboxes, second will contain the group name, third the group description. Header links can be used to sort
group.list.descr = Description
Expand Down
2 changes: 2 additions & 0 deletions assignment/api/src/resources/assignment_ca.properties
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ range.allgroups=tot l\u2019espai

group=Grup
groups=Grups
group.sitegradebook.noitem.selected=Els grups seleccionats han de tindre associat un ítem del llibre de qualificacions
group.sitegradebook.nopermission=No es poden crear tasques de lloc en tindre qualificacions de grup.
group.editsite.nopermission=No teniu els permisos corresponents en aquest espai per editar l\u2019estat del grup
group.list.summary=La taula cont\u00e9 una llista de grups. La primera columna contindr\u00e0 caselles de selecci\u00f3; la segona, el nom del grup; la tercera, la descripci\u00f3 del grup. Els enlla\u00e7os de l\u2019encap\u00e7alament es poden utilitzar per ordenar
group.list.descr=Descripci\u00f3
Expand Down
2 changes: 2 additions & 0 deletions assignment/api/src/resources/assignment_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ range.allgroups=sitio

group=Grupo
groups=Grupos
group.sitegradebook.noitem.selected=Los grupos seleccionados deben tener asociado un item del libro de calificaciones
group.sitegradebook.nopermission=No se pueden crear tareas de sitio al tener calificaciones de grupo.
group.editsite.nopermission=No se puede editar el estado del grupo debido a los permisos del sitio.
group.list.summary=Lista de grupos. La primera columna contiene casillas de selecci\u00f3n, la segunda el nombre del grupo y la tercera su descripci\u00f3n. Los enlaces de la cabecera de la tabla permiten ordenar sus entradas.
group.list.descr=Descripci\u00f3n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Observable;
import java.util.Observer;
import java.util.Optional;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -65,69 +66,69 @@ public void update(Observable o, Object arg) {
String[] parts = StringUtils.split(event.getResource(), '/');
if (parts.length >= 5) {
final String source = parts[0];
final String gradebookId = parts[1];
final String gradebookUid = parts[1];
final String itemId = parts[2];
final String studentId = parts[3];
final String score = parts[4];
log.debug("Updating score for user {} for item {} with score {} in gradebook {} by {}", studentId, itemId, score, gradebookId, source);
log.debug("Updating score for user {} for item {} with score {} in gradebook {} by {}", studentId, itemId, score, gradebookUid, source);

if ("gradebookng".equals(source)) {
Optional<Assignment> assignment = Optional.empty();
List<Assignment> assignments = null;
Optional<AssignmentSubmission> submission = Optional.empty();
// Assignments stores the gradebook item name and not the id :(, so we need to look it up
try {
org.sakaiproject.grading.api.Assignment gradebookAssignment = gradingService.getAssignmentByNameOrId(event.getContext(), itemId);
assignment = assignmentService.getAssignmentForGradebookLink(event.getContext(), gradebookAssignment.getName());
if (assignment.isPresent()) {
final Assignment a = assignment.get();
final User user = userDirectoryService.getUser(studentId);
submission = Optional.ofNullable(assignmentService.getSubmission(a.getId(), user.getId()));
submission = Optional.ofNullable(submission.orElseGet(() -> {
try {
return assignmentService.addSubmission(a.getId(), assignmentService.getSubmitterIdForAssignment(a, user.getId()));
} catch (PermissionException e) {
log.warn("Can't access submission for assignment {} and user {}, {}", a.getId(), user.getId(), e.getMessage());
}
return null;
}));
org.sakaiproject.grading.api.Assignment gradebookAssignment = gradingService.getAssignmentByNameOrId(gradebookUid, event.getContext(), itemId);
assignments = assignmentService.getAssignmentsForGradebookLink(event.getContext(), gradebookAssignment.getName());
if (assignments != null) {
for (Assignment a : assignments) {
final User user = userDirectoryService.getUser(studentId);
submission = Optional.ofNullable(assignmentService.getSubmission(a.getId(), user.getId()));
submission = Optional.ofNullable(submission.orElseGet(() -> {
try {
return assignmentService.addSubmission(a.getId(), assignmentService.getSubmitterIdForAssignment(a, user.getId()));
} catch (PermissionException e) {
log.warn("Can't access submission for assignment {} and user {}, {}", a.getId(), user.getId(), e.getMessage());
}
return null;
}));

if (submission.isPresent()) {
AssignmentSubmission s = submission.get();
final String grade;
if (Assignment.GradeType.SCORE_GRADE_TYPE.equals(a.getTypeOfGrade())) {
int dec = (int) Math.log10(a.getScaleFactor());
StringBuilder scaledScore = new StringBuilder(score);
IntStream.range(0, dec).forEach(i -> scaledScore.append("0"));
grade = scaledScore.toString();
} else {
grade = score;
}
if (a.getIsGroup()) {
// grades will show up as overrides for group assignments
Set<AssignmentSubmissionSubmitter> submitters = s.getSubmitters();
submitters.stream().filter(u -> studentId.equals(u.getSubmitter())).findAny().ifPresent(u -> u.setGrade(grade));
if (submission.isPresent()) {
AssignmentSubmission s = submission.get();
final String grade;
if (Assignment.GradeType.SCORE_GRADE_TYPE.equals(a.getTypeOfGrade())) {
int dec = (int) Math.log10(a.getScaleFactor());
StringBuilder scaledScore = new StringBuilder(score);
IntStream.range(0, dec).forEach(i -> scaledScore.append("0"));
grade = scaledScore.toString();
} else {
grade = score;
}
if (a.getIsGroup()) {
// grades will show up as overrides for group assignments
Set<AssignmentSubmissionSubmitter> submitters = s.getSubmitters();
submitters.stream().filter(u -> studentId.equals(u.getSubmitter())).findAny().ifPresent(u -> u.setGrade(grade));
} else {
s.setGrade(grade);
}
s.setGraded(true);
s.setGradedBy(event.getUserId());
assignmentService.updateSubmission(s);
log.debug("Updated score for user {} for submission {} with score {}", studentId, s.getId(), score);
} else {
s.setGrade(grade);
log.warn("Submission not found for assignment {} and student {}, ", itemId, studentId);
}
s.setGraded(true);
s.setGradedBy(event.getUserId());
assignmentService.updateSubmission(s);
log.debug("Updated score for user {} for submission {} with score {}", studentId, s.getId(), score);
} else {
log.warn("Submission not found for assignment {} and student {}, ", itemId, studentId);
}
} else {
log.debug("No matching assignment found with gradebook item id, {}", itemId);
}
} catch (IdUnusedException | PermissionException e) {
if (!assignment.isPresent()) {
log.warn("Can't retrieve assignment for gradebook item id {}, {}", itemId, e.getMessage());
} else if (!submission.isPresent()) {
log.warn("Can't retrieve submission for user {} for assignment {}, {}", studentId, assignment.get().getId(), e.getMessage());
if (!submission.isPresent()) {
log.warn("Can't retrieve submission for user {} for assignment {}, {}", studentId, itemId, e.getMessage());
} else {
log.warn("Can't update submission for user {}, {}", studentId, e.getMessage());
}
} catch (AssessmentNotFoundException anfe) {
log.warn("Can't retrieve gradebook assignment for gradebook {} and item {}, {}", gradebookId, itemId, anfe.getMessage());
log.debug("Can't retrieve gradebook assignment for gradebook {} and item {}, {}", gradebookUid, itemId, anfe.getMessage());
} catch (UserNotDefinedException e) {
log.warn("Can't retrieve user {}, {}", studentId, e.getMessage());
}
Expand Down
Loading

0 comments on commit 68be104

Please sign in to comment.