3231 Prevent approving phase two if grades can't be reported

This commit is contained in:
Andreas Svanberg 2023-11-29 13:43:16 +01:00
parent 172ddbe27f
commit 97dec05f34
2 changed files with 31 additions and 25 deletions

@ -147,7 +147,10 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
Project project = approval.getObject().getProject();
try {
for (User author : project.getProjectParticipants()) {
reportGrade(author, project);
if (!reportGrade(author, project)) {
error(getString("error_while_reporting_phase_two_grades"));
return;
}
}
reviewerDecisionService.approve(
approval.getObject(),
@ -249,7 +252,7 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
approval.getObject().getProject().getIdentifier(),
author.getIdentifier(),
examination.id());
return currentResult.isRight() && currentResult.right().isEmpty();
return !currentResult.isRight() || currentResult.right().isEmpty();
}
private List<Examination> getPassFailExaminations(User author) {
@ -262,14 +265,23 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
.toList();
}
private void reportGrade(User author, Project project) {
/**
* @return true if the grades were reported successfully, false otherwise
*/
private boolean reportGrade(User author, Project project) {
List<Examination> examinations = getExaminationsToReport(author);
for (Examination examination : examinations) {
reportGrade(author, project, examination);
if (!reportGrade(author, project, examination)) {
return false;
}
}
return true;
}
private void reportGrade(User author, Project project, Examination examination) {
/**
* @return true if the grade was reported successfully, false otherwise
*/
private boolean reportGrade(User author, Project project, Examination examination) {
Grade passingGrade = getPassingGrade(examination);
Either<ReportGradeError, Void> reported = gradingService.reportGrade(
getSession().getMetaData(OAuth.TOKEN),
@ -279,25 +291,21 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
passingGrade.letter(),
getExaminationDate());
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()));
}
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()));
}
return reported.isRight();
}
private LocalDate getExaminationDate() {

@ -7,7 +7,5 @@ reject=Improvements are needed
examination.Required=Examination for ${label} must be set
report_halfway_explanation=If you choose to approve the rough draft of this project, you will also be reporting \
the appropriate passing grade(s) for the author(s) according to the following.
failed_to_report_phase_two_grade=Could not report all the grades, please contact the supervisor and let them know \
they will have to report it themselves.
error_while_reporting_phase_two_grades=Failed to report the grades to Daisy, so the approval was not accepted, \
please try again later. If the problem persists, contact the support.