2934 Better handling of failed grade reporting

This commit is contained in:
Andreas Svanberg 2023-09-16 13:21:04 +02:00
parent 59ab4e428b
commit d3d0d689c8
5 changed files with 54 additions and 27 deletions

@ -29,6 +29,7 @@ import se.su.dsv.scipro.forum.panels.threaded.SubmitForumReplyPanel;
import se.su.dsv.scipro.grading.Examination;
import se.su.dsv.scipro.grading.Grade;
import se.su.dsv.scipro.grading.GradingService;
import se.su.dsv.scipro.grading.ReportGradeError;
import se.su.dsv.scipro.oauth.OAuth;
import se.su.dsv.scipro.oauth.OAuthService;
import se.su.dsv.scipro.profile.UserLabel;
@ -42,6 +43,7 @@ import se.su.dsv.scipro.reviewing.ReviewerInteractionService;
import se.su.dsv.scipro.reviewing.RoughDraftApprovalService;
import se.su.dsv.scipro.supervisor.panels.FinalSeminarApprovalProcessPanel;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.util.Either;
import javax.inject.Inject;
import java.time.Instant;
@ -52,6 +54,8 @@ import java.util.function.Predicate;
public class RoughDraftApprovalDecisionPage extends ReviewerPage {
public static final String PAGE_PARAMETER_ID = "id";
private static final System.Logger LOGGER = System.getLogger(RoughDraftApprovalDecisionPage.class.getSimpleName());
@Inject
private ReviewerInteractionService reviewerInteractionService;
@Inject
@ -89,6 +93,7 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
add(new DecisionForm("decision", approval));
add(new EnumLabel<>("title", approval.map(ReviewerApproval::getStep)));
add(new TimelinePanel("timeline", project));
add(new FencedFeedbackPanel("feedback", this));
}
@Override
@ -208,33 +213,57 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
super.onSubmit();
Project project = approval.getObject().getProject();
for (User author : project.getProjectParticipants()) {
Examination examination = selectedExaminations.forAuthor(author);
Grade passingGrade = getPassingGrade(examination);
gradingService.reportGrade(
getSession().getMetaData(OAuth.TOKEN),
project.getIdentifier(),
author.getIdentifier(),
examination.id(),
passingGrade.letter(),
LocalDate.now());
reportGrade(author, project);
}
reviewerDecisionService.approve(
approval.getObject(),
feedback.getModelObject(),
WicketFileUpload.ofOptional(attachment.getFileUpload()));
}
private Grade getPassingGrade(Examination examination) {
Optional<Grade> passingGrade = examination.grades()
.stream()
.filter(g -> g.type() == Grade.Type.PASSING)
.findFirst();
assert passingGrade.isPresent();
return passingGrade.get();
}
});
}
private void reportGrade(User author, Project project) {
Examination examination = selectedExaminations.forAuthor(author);
Grade passingGrade = getPassingGrade(examination);
Either<ReportGradeError, Void> reported = gradingService.reportGrade(
getSession().getMetaData(OAuth.TOKEN),
project.getIdentifier(),
author.getIdentifier(),
examination.id(),
passingGrade.letter(),
LocalDate.now());
if (!reported.isRight()) {
if (reported.left() == ReportGradeError.NO_GRADING_ROLE) {
RoughDraftApprovalDecisionPage.this.error(getString("failed_to_report_phase_two_grade"));
}
else {
LOGGER.log(
System.Logger.Level.WARNING,
"""
Failed to report phase two grade to Daisy: %s, \
author: %s (%d), project: %s (%d), examination: %s (%d)
""".formatted(
reported.left(),
author.getFullName(),
author.getId(),
project.getTitle(),
project.getId(),
examination.name().swedish(),
examination.id()));
}
}
}
private Grade getPassingGrade(Examination examination) {
Optional<Grade> passingGrade = examination.grades()
.stream()
.filter(g -> g.type() == Grade.Type.PASSING)
.findFirst();
assert passingGrade.isPresent();
return passingGrade.get();
}
@Override
protected void onDetach() {
super.onDetach();

@ -1,9 +0,0 @@
reply.link= New message
feedback.Required= Feedback is required
info= Private communication between Reviewer and Supervisor.
interact.with.supervisor= Interact with supervisor
approve=Approve
reject=Improvements are needed
examination.Required=Examination for ${label} must be set
report_halfway_explanation=When approving a project for phase two review you should also report the halfway \
examination. Please select the appropriate examination below for each author before approving.

@ -7,3 +7,5 @@ reject=Improvements are needed
examination.Required=Examination for ${label} must be set
report_halfway_explanation=When approving a project for phase two review you should also report the halfway \
examination. Please select the appropriate examination below for each author before approving.
failed_to_report_phase_two_grade=Could not report the grade, please contact the supervisor and let them know \
they will have to report it themselves.

@ -17,6 +17,7 @@
<div class="col-12 col-xl-6 mb-3">
<h4><span wicket:id="title"></span></h4>
<div wicket:id="details"></div>
<div wicket:id="feedback"></div>
<form wicket:id="decision">
<div wicket:id="feedbackPanel"></div>
<div class="mb-3">

@ -20,6 +20,7 @@ import se.su.dsv.scipro.system.DegreeType;
import se.su.dsv.scipro.system.ProjectType;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.test.DomainObjects;
import se.su.dsv.scipro.util.Either;
import java.net.URISyntaxException;
import java.time.Duration;
@ -29,6 +30,7 @@ import java.util.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.anyString;
@ -55,6 +57,8 @@ public class RoughDraftApprovalDecisionPageTest extends SciProTest {
Examination problemAndMethod = new Examination(614, new Name("Problem", "Problem"), "KX1P", List.of(new Grade(Grade.Type.PASSING, "P")));
lenient().when(gradingService.getExaminations(anyString(), anyLong(), anyLong()))
.thenReturn(List.of(problemAndMethod));
lenient().when(gradingService.reportGrade(any(), anyLong(), anyLong(), anyInt(), any(), any()))
.thenReturn(Either.right(null));
startPage();
}