3064 PO review 7) remove the ability to report graded examinations on the grading page for the supervisor

It is only used in case the reviewer did not report phase 2
This commit is contained in:
Andreas Svanberg 2023-09-27 13:54:35 +02:00
parent 5fb540a2a9
commit 8c1940d6d2
4 changed files with 4 additions and 342 deletions

@ -10,24 +10,8 @@
<h3>Pass/fail examinations</h3>
<wicket:container wicket:id="nonGraded"/>
<h3>Grade suggestion to the examiner</h3>
<wicket:enclosure child="graded">
<p>
Suggested grade from the grading report:
<span wicket:id="gradeSuggestion">C</span>
</p>
<wicket:container wicket:id="graded"/>
</wicket:enclosure>
<div wicket:id="progress"></div>
</div>
</div>
<wicket:fragment wicket:id="progress">
<div wicket:id="finalThesis"></div>
<div wicket:id="textMatching"></div>
<div wicket:id="gradingReport"></div>
<a wicket:id="finish">Click here to finish the remaining tasks</a>
</wicket:fragment>
</wicket:extend>
</body>
</html>

@ -1,106 +1,45 @@
package se.su.dsv.scipro.grading;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LambdaModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.request.flow.RedirectToUrlException;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.lang.Classes;
import se.su.dsv.scipro.components.ListAdapterModel;
import se.su.dsv.scipro.components.OppositeVisibility;
import se.su.dsv.scipro.components.RedGreenLabel;
import se.su.dsv.scipro.daisyExternal.http.DaisyAPI;
import se.su.dsv.scipro.components.menuhighlighting.MenuHighlightSupervisorGradingReport;
import se.su.dsv.scipro.data.FilteredListModel;
import se.su.dsv.scipro.file.FileDescription;
import se.su.dsv.scipro.file.FileReference;
import se.su.dsv.scipro.file.FileService;
import se.su.dsv.scipro.finalthesis.FinalThesis;
import se.su.dsv.scipro.finalthesis.FinalThesisService;
import se.su.dsv.scipro.io.dto.ResearchAreaWithID;
import se.su.dsv.scipro.io.dto.ResearchAreas;
import se.su.dsv.scipro.io.dto.ThesisPublication;
import se.su.dsv.scipro.io.dto.ThesisToBeUpdated;
import se.su.dsv.scipro.io.dto.UnitWithID;
import se.su.dsv.scipro.oauth.OAuth;
import se.su.dsv.scipro.oauth.OAuthService;
import se.su.dsv.scipro.profile.UserLabel;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.reflection.ReflectionService;
import se.su.dsv.scipro.report.GradeCalculator;
import se.su.dsv.scipro.report.GradeCalculatorService;
import se.su.dsv.scipro.report.GradingReport;
import se.su.dsv.scipro.report.GradingReportService;
import se.su.dsv.scipro.report.SupervisorGradingReport;
import se.su.dsv.scipro.reviewing.RoughDraftApproval;
import se.su.dsv.scipro.reviewing.RoughDraftApprovalService;
import se.su.dsv.scipro.supervisor.pages.AbstractSupervisorProjectDetailsPage;
import se.su.dsv.scipro.system.Language;
import se.su.dsv.scipro.system.ResearchArea;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.util.Either;
import javax.inject.Inject;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage {
public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage
implements MenuHighlightSupervisorGradingReport
{
@Inject
private OAuthService oAuthService;
@Inject
private GradingService gradingService;
@Inject
private GradingReportService gradingReportService;
@Inject
private FinalThesisService finalThesisService;
@Inject
private DaisyAPI daisyAPI;
@Inject
private GradeCalculatorService gradeCalculatorService;
@Inject
private FileService fileDescriptionService;
@Inject
private ReflectionService reflectionService;
@Inject
private RoughDraftApprovalService roughDraftApprovalService;
@Inject
private PublicationMetadataService publicationMetadataService;
private final IModel<FinalThesis> finalThesisModel;
private IModel<Boolean> hasFinalThesis;
private IModel<Boolean> hasTextMatchingDocument;
public SupervisorGradingPage(final PageParameters pp) {
super(pp);
add(new FeedbackPanel("feedback"));
finalThesisModel = new LoadableDetachableModel<>() {
@Override
protected FinalThesis load() {
return finalThesisService.findByProject(projectModel.getObject());
}
};
hasFinalThesis = finalThesisModel
.map(FinalThesis::getStatus)
.filter(status -> status == FinalThesis.Status.APPROVED)
.isPresent();
hasTextMatchingDocument = finalThesisModel
.map(FinalThesis::getTextMatchingDocument)
.isPresent();
final IModel<List<User>> authors = new ListAdapterModel<>(LambdaModel.of(projectModel, Project::getProjectParticipants, Project::setProjectParticipants));
add(new ListView<>("authors", authors) {
{
@ -118,46 +57,10 @@ public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage
item.getModel(),
nonGradedExaminations,
Model.of(LocalDate.now())));
final IModel<SupervisorGradingReport> gradingReportModel = new LoadableDetachableModel<>() {
@Override
protected SupervisorGradingReport load() {
return gradingReportService.getSupervisorGradingReport(projectModel.getObject(), item.getModelObject());
}
};
final IModel<Boolean> hasFinishedGradingReport = gradingReportModel
.map(GradingReport::getState)
.filter(state -> state == GradingReport.State.FINALIZED)
.isPresent();
final IModel<List<Examination>> gradedExaminations = getSpecificExaminations(examinations, true);
final ProgressPanel progress = new ProgressPanel("progress", hasFinishedGradingReport);
item.add(progress);
final GradedPanel gradedPanel = new GradedPanel(
"graded",
item.getModel(),
gradedExaminations,
finalThesisModel.map(FinalThesis::getDocument).map(FileReference::getFileDescription).map(FileDescription::getDateCreated).map(SupervisorGradingPage.this::toLocalDate));
gradedPanel.add(new OppositeVisibility(progress));
item.add(gradedPanel);
item.add(new Label("gradeSuggestion", projectModel
.map(SupervisorGradingPage.this::getGradeCalculator)
.combineWith(gradingReportModel, GradeCalculator::getGrade)));
}
});
}
private LocalDate toLocalDate(Date date) {
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
@Override
public void detachModels() {
super.detachModels();
finalThesisModel.detach();
hasFinalThesis.detach();
hasTextMatchingDocument.detach();
}
private IModel<List<Examination>> getSpecificExaminations(final IModel<List<Examination>> examinations, final boolean graded) {
return new FilteredListModel<>(examinations) {
@Override
@ -226,209 +129,6 @@ public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage
}
}
private class GradedPanel extends NonGradedPanel {
public GradedPanel(
final String id,
final IModel<User> userModel,
final IModel<List<Examination>> gradedExaminations,
final IModel<LocalDate> suggestedReportDate) {
super(id, userModel, gradedExaminations, suggestedReportDate);
}
@Override
protected void reportGrade(final Project project, final User user, final Examination examination, final String letter, final LocalDate reported) {
final String token = getSession().getMetaData(OAuth.TOKEN);
sendTitlesToDaisy(project, finalThesisModel.getObject());
if (!sendPublicationToDaisy(project)) {
error(getString("publication.could.not.be.sent.to.daisy"));
return;
}
else {
success(getString("publication.sent.to.daisy"));
}
if (!sendTextMatchingDocument(project, token)) {
error(getString("text.matching.could.not.be.sent.to.daisy"));
return;
}
else {
success(getString("text.matching.sent.to.daisy"));
}
super.reportGrade(project, user, examination, letter, reported);
if (hasErrorMessage()) {
return;
}
if (!sendProtocol(project, user, examination, token)) {
error(getString("protocol.could.not.be.sent.to.daisy"));
}
else {
success(getString("protocol.sent.to.daisy"));
}
}
private void sendTitlesToDaisy(final Project project, final FinalThesis finalThesis) {
daisyAPI.getThesis(project.getIdentifier()).ifPresent(thesis -> {
final ThesisToBeUpdated thesisToBeUpdated = new ThesisToBeUpdated();
thesisToBeUpdated.setStartDate(thesis.getStartDate());
thesisToBeUpdated.setAborted(thesis.isAborted());
thesisToBeUpdated.setEndDate(thesis.getEndDate());
final UnitWithID unitWithID = new UnitWithID();
unitWithID.setId(thesis.getUnit().getId());
thesisToBeUpdated.setUnit(unitWithID);
final ResearchAreas researchAreas = new ResearchAreas();
thesis.getResearchAreas().getResearchAreas().forEach(researchArea -> {
final ResearchAreaWithID researchArea2 = new ResearchAreaWithID();
researchArea2.setId(researchArea.getId());
researchAreas.getResearchAreas().add(researchArea2);
});
thesisToBeUpdated.setResearchAreas(researchAreas);
if (finalThesis.getSwedishTitle() != null) {
thesisToBeUpdated.setTitle(finalThesis.getSwedishTitle());
}
else {
thesisToBeUpdated.setTitle(finalThesis.getEnglishTitle());
}
thesisToBeUpdated.setTitleEn(finalThesis.getEnglishTitle());
daisyAPI.updateThesis(project.getIdentifier(), thesisToBeUpdated);
});
}
private boolean sendPublicationToDaisy(final Project project) {
final ThesisPublication old = daisyAPI
.getPublication(project.getIdentifier())
.orElse(null);
if (old == null || old.getFile() == null) {
final ThesisPublication thesisPublication = createThesisPublication();
final boolean sentPublication = daisyAPI.sendPublication(project.getIdentifier(), thesisPublication);
if (sentPublication) {
final FinalThesis finalThesis = finalThesisModel.getObject();
final FileDescription finalThesisDocument = finalThesis.getDocument().getFileDescription();
boolean sentPublicationFile;
try {
sentPublicationFile = daisyAPI.sendPublicationFile(
project.getIdentifier(),
finalThesisDocument.getName(),
fileDescriptionService.getData(finalThesisDocument));
} catch (RuntimeException e) {
sentPublicationFile = false;
}
return sentPublicationFile;
}
else {
return false;
}
}
return true;
}
private ThesisPublication createThesisPublication() {
final FinalThesis finalThesis = finalThesisModel.getObject();
final ThesisPublication thesisPublication = new ThesisPublication();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(finalThesis.getDocument().getFileDescription().getDateCreated());
thesisPublication.setDate(calendar);
thesisPublication.setLanguage(projectModel.getObject().getLanguage() == Language.SWEDISH ? "sv" : "en");
ResearchArea researchArea = finalThesis.getProject().getResearchArea();
if (researchArea != null) {
ResearchAreaWithID researchArea2 = new ResearchAreaWithID();
researchArea2.setId(researchArea.getIdentifier());
thesisPublication.getResearchAreas().add(researchArea2);
}
PublicationMetadata publicationMetadata = publicationMetadataService.getByProject(projectModel.getObject());
thesisPublication.setEnglishKeywords(publicationMetadata.getKeywordsEnglish());
thesisPublication.setSwedishKeywords(publicationMetadata.getKeywordsSwedish());
thesisPublication.setEnglishAbstract(publicationMetadata.getAbstractEnglish());
thesisPublication.setSwedishAbstract(publicationMetadata.getAbstractSwedish());
return thesisPublication;
}
private boolean sendTextMatchingDocument(final Project project, final String token) {
final boolean hasTextMatchingDocument =
gradingService.hasTextMatchingDocument(
getSession().getMetaData(OAuth.TOKEN),
projectModel.getObject().getIdentifier());
if (!hasTextMatchingDocument) {
try {
final FinalThesis finalThesis = finalThesisModel.getObject();
final Either<UploadTextMatchingError, Void> sendTextMatchingDocument
= gradingService.sendTextMatchingDocument(
token,
project.getIdentifier(),
fileDescriptionService.getData(finalThesis.getTextMatchingDocument().getFileDescription()),
finalThesis.getTextMatchingDocument().getFileDescription().getMimeType());
SupervisorGradingPage.this.hasTextMatchingDocument.detach();
return sendTextMatchingDocument.isRight();
} catch (RuntimeException e) {
return false;
}
}
return true;
}
private boolean sendProtocol(final Project project, final User user, final Examination examination, final String token) {
final SupervisorGradingReport supervisorGradingReport =
gradingReportService.getSupervisorGradingReport(project, user);
IModel<String> reflection = LoadableDetachableModel.of(() ->
reflectionService.getSubmittedReflection(project, user));
IModel<RoughDraftApproval> roughDraftApproval = LoadableDetachableModel.of(() -> roughDraftApprovalService.findBy(project))
.map(o -> o.orElse(null));
IModel<FinalThesis> finalThesis = LoadableDetachableModel.of(() -> finalThesisService.findByProject(project));
final DataExposedGradingReportPdf pdf =
new DataExposedGradingReportPdf(
Model.of(supervisorGradingReport), reflection,
roughDraftApproval,
finalThesis);
final Either<UploadProtocolError, Void> sendProtocol = gradingService.sendProtocol(
token,
project.getIdentifier(),
getModelObject().getIdentifier(),
examination.id(),
pdf.getData(),
pdf.getContentType());
return sendProtocol.isRight();
}
}
private class ProgressPanel extends Fragment {
private final IModel<Boolean> hasFinishedGradingReport;
public ProgressPanel(final String id, final IModel<Boolean> hasFinishedGradingReport) {
super(id, "progress", SupervisorGradingPage.this, hasFinishedGradingReport);
this.hasFinishedGradingReport = hasFinishedGradingReport;
add(new RedGreenLabel(
"gradingReport",
hasFinishedGradingReport,
new ResourceModel("grading.report.not.done"), new ResourceModel("grading.report.finished")));
add(new RedGreenLabel(
"finalThesis",
hasFinalThesis,
new ResourceModel("approve.final.thesis"), new ResourceModel("final.thesis.approved")));
add(new RedGreenLabel(
"textMatching",
hasTextMatchingDocument,
new ResourceModel("upload.text.matching.document"), new ResourceModel("text.matching.document.uploaded")));
add(new BookmarkablePageLink<Void>(
"finish",
SupervisorGradingReportPage.class,
SupervisorGradingReportPage.getPageParameters(projectModel.getObject())));
}
@Override
protected void onConfigure() {
super.onConfigure();
setVisibilityAllowed(!(hasFinishedGradingReport.getObject() && hasFinalThesis.getObject() && hasTextMatchingDocument.getObject()));
}
}
private boolean isGraded(final Examination examination) {
final long passingGrades = examination.grades()
.stream()
@ -437,8 +137,4 @@ public class SupervisorGradingPage extends AbstractSupervisorProjectDetailsPage
.count();
return passingGrades > 1;
}
private GradeCalculator getGradeCalculator(final Project project) {
return gradeCalculatorService.getSupervisorCalculator(project);
}
}

@ -13,18 +13,3 @@ ReportGradeError.PUBLICATION_MISSING= You have to approve the final thesis as \
ReportGradeError.REPORTED_IN_THE_FUTURE= You can not report grades in the future.
ReportGradeError.REPORTED_BEFORE_PROJECT_START= You can not report grades before the project started.
ReportGradeError.TITLE_MISSING=You must have set an english title to report the grade.
grading.report.not.done= You need to finish the grading report first
grading.report.finished= Grading report finished
approve.final.thesis= You need to approve the final thesis first
final.thesis.approved= Final thesis approved
upload.text.matching.document= You need to upload the text matching document first
text.matching.document.uploaded= Text matching document uploaded
publication.could.not.be.sent.to.daisy= Could not send the publication to Daisy
text.matching.could.not.be.sent.to.daisy= Could not send the text matching \
document to Daisy
protocol.could.not.be.sent.to.daisy= Could not send the grading report to Daisy
publication.sent.to.daisy= The final thesis has been sent as the publication \
to Daisy
text.matching.sent.to.daisy= The text matching document has been sent to Daisy
protocol.sent.to.daisy= The grading report has been sent as the protocol to \
Daisy

@ -65,9 +65,6 @@ public class SupervisorSubTabMenuPanel extends AbstractMenuPanel {
items.add(new MenuItem(FINAL_SEMINAR, SupervisorFinalSeminarPage.class, MenuHighlightFinalSeminar.class, projectParams));
if (gradingReportTemplateIsAvailable()) {
items.add(new MenuItem(SEND_TO_EXAMINER, SupervisorGradingReportPage.class, MenuHighlightSupervisorGradingReport.class, projectParams));
if (projectModel.getObject().getIdentifier() != null) {
items.add(new MenuItem("Grading", SupervisorGradingPage.class, projectParams));
}
}
return items;
}