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 Oct 3, 2024
1 parent fb2764f commit 1ebdf52
Show file tree
Hide file tree
Showing 194 changed files with 5,985 additions and 4,865 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
5 changes: 4 additions & 1 deletion assignment/api/src/resources/assignment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ gen.resub = Re-submitted
gen.retu = Return
gen.backtolist = Back to list
gen.reorder = Reorder
gen.review = Review
gen.peerreview.subm4 = Peer Review Submitted
gen.peerreview.todo = Peer Review ({0}) Due {1}
gen.reviewer.who = Reviewer: {0} ({1})
Expand Down Expand Up @@ -674,6 +673,9 @@ range.allgroups = site

group = Group
groups = Groups
group.sitegradebook.items.error=Selected groups must have a gradebook item associated with them
group.sitegradebook.nopermission=Assignments for the entire site cannot be created when using group based gradebooks.
group.sitegradebook.categories.error=The selected categories must be associated with their corresponding group.
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 Expand Up @@ -1163,6 +1165,7 @@ settings.access.checkFailure=Check failed, no response from server.

selected.group = Selected Group
selected.groups = Selected Groups
selected.groups.without.gradebook = You have made a selection for a group that doesn't have a gradebook.

submission.inline=Inline Submission
grade.type.unknown=Unknown Grade Type
Expand Down
4 changes: 4 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,9 @@ range.allgroups=tot l\u2019espai

group=Grup
groups=Grups
group.sitegradebook.items.error=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.sitegradebook.categories.error=Les categories seleccionades han d'estar associades al seu grup corresponent.
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 Expand Up @@ -1135,6 +1138,7 @@ settings.access.checkFailure=La comprovaci\u00f3 ha fallat, no hi ha hagut respo

selected.group=Grup seleccionat
selected.groups=Grups seleccionats
selected.groups.without.gradebook = Heu seleccionat grups sense un llibre de qualificacions existent, verifiqueu-ne la configuraci\u00f3.

submission.inline=Lliurament
grade.type.unknown=Tipus de qualificaci\u00f3 desconegut
Expand Down
4 changes: 4 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,9 @@ range.allgroups=sitio

group=Grupo
groups=Grupos
group.sitegradebook.items.error=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.sitegradebook.categories.error=Las categorías seleccionadas deben estar asociadas a su grupo correspondiente.
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 Expand Up @@ -1162,6 +1165,7 @@ settings.access.checkFailure=Comprobaci\u00f3n fallida, no hay respuesta del ser

selected.group=Grupo seleccionado
selected.groups=Grupo(s) seleccionado(s)
selected.groups.without.gradebook = Has seleccionado grupos sin gradebook existente, por favor revisa la configuración.

submission.inline=Respuesta enviada
grade.type.unknown=Tipo de nota desconocido
Expand Down
3 changes: 2 additions & 1 deletion assignment/api/src/resources/assignment_eu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ settings.access.checkError=Ikasle hauek zenbait talde hautatutako partaide dira
settings.access.checkFailure=Egiaztapenak huts egin du\: zerbitzariak ez du erantzun.

selected.group=Talde hautatua
selected.groups=Talde hautatuak
selected.groups=Talde hautatuak
selected.groups.without.gradebook = Lehendik dagoen kalifikazio-libururik gabeko taldeak hautatu dituzu, egiaztatu zure ezarpenak.

submission.inline=Inline bidalketa
grade.type.unknown=Ez dago horrelako kalifikazio motarik
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 1ebdf52

Please sign in to comment.