3273 Do not mark thesis as "Sent to examiner" before it is actually sent

What happened was an empty list was returned if we got a bad response from the grading service. So when the check was performed "is there any examination without a grade" then it was true because there were no examinations to begin with.
This commit is contained in:
Andreas Svanberg 2024-03-27 09:57:09 +01:00
parent 9bcad9df40
commit 139ecd8bbd
6 changed files with 20 additions and 4 deletions

@ -7,6 +7,9 @@ import java.time.LocalDate;
import java.util.*;
public interface GradingService {
/**
* @return the list of examinations for the given project and author, or {@code null} if the request failed
*/
List<Examination> getExaminations(String token, long projectId, long authorId);
Either<GetGradeError, Optional<Result>> getResult(String token, long projectId, long authorId, long examinationId);

@ -46,7 +46,7 @@ public class GradingServiceImpl implements GradingService {
return response.readEntity(EXAMINATION_LIST);
}
else {
return Collections.emptyList();
return null;
}
}

@ -124,6 +124,10 @@ public class SendToExaminer extends GenericPanel<Project> {
String token = getSession().getMetaData(OAuth.TOKEN);
Project project = getModelObject();
List<Examination> examinations = gradingService.getExaminations(token, project.getIdentifier(), author.getIdentifier());
if (examinations == null) {
// if we can't tell assume it is not sent
return true;
}
for (Examination examination : examinations) {
if (examination.hasManyPassingGrades()) {
Either<GetGradeError, Optional<Result>> result = gradingService.getResult(token, project.getIdentifier(), author.getIdentifier(), examination.id());
@ -148,6 +152,10 @@ public class SendToExaminer extends GenericPanel<Project> {
return;
}
List<Examination> examinations = gradingService.getExaminations(token, project.getIdentifier(), author.getIdentifier());
if (examinations == null) {
getSession().error("Failed to get the examination setup for " + author.getFullName());
return;
}
List<Examination> gradedExaminations = examinations
.stream()
.filter(Examination::hasManyPassingGrades)

@ -56,7 +56,8 @@ public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage
@Override
protected void populateItem(final ListItem<User> item) {
item.add(new UserLabel("authorName", item.getModel()));
final IModel<List<Examination>> examinations = SupervisorGradingPage.this.getExaminations(item.getModel());
final IModel<List<Examination>> examinations = SupervisorGradingPage.this.getExaminations(item.getModel())
.orElseGet(Collections::emptyList);
final IModel<List<Examination>> nonGradedExaminations = getSpecificExaminations(examinations, false);
item.add(new NonGradedPanel(

@ -177,6 +177,10 @@ public class SupervisorGradingReportPage extends AbstractSupervisorProjectDetail
String token = getSession().getMetaData(OAuth.TOKEN);
Project project = projectModel.getObject();
List<Examination> examinations = gradingService.getExaminations(token, project.getIdentifier(), author.getIdentifier());
if (examinations == null) {
// if grading service is down, assume not sent
return false;
}
for (Examination examination : examinations) {
if (examination.hasManyPassingGrades()) {
Either<GetGradeError, Optional<Result>> result = gradingService.getResult(token, project.getIdentifier(), author.getIdentifier(), examination.id());

@ -228,8 +228,8 @@ public class RoughDraftApprovalDecisionPage extends ReviewerPage {
for (User author : authors.getObject()) {
try {
List<Examination> examinations = getPassFailExaminations(author);
if (examinations.isEmpty()) {
// an empty list is returned if there's an error from the grading service
if (examinations == null) {
// null is returned if there's an error from the grading service
return false;
}
} catch (RuntimeException e) {