Fix grade calculator being serialized ()

The new calculator that's based on templates has a reference to the @Entity for the template which should not be serialized.

Fixes 

## How to test/replicate
1. Log in as a supervisor
1. Open a project that's new enough to use a grading report template with grade limits
1. Go to the "Finishing up" tab
1. Go to the sub-tab for an individual author

Reviewed-on: 
Reviewed-by: Nico Athanassiadis <nico@dsv.su.se>
Co-authored-by: Andreas Svanberg <andreass@dsv.su.se>
Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
This commit is contained in:
Andreas Svanberg 2024-12-16 11:24:33 +01:00 committed by Nico Athanassiadis
parent 857f646678
commit c6bd17d9ad
4 changed files with 10 additions and 20 deletions
core/src/main/java/se/su/dsv/scipro/report
view/src
main/java/se/su/dsv/scipro/grading
test/java/se/su/dsv/scipro/grading

@ -1,8 +1,6 @@
package se.su.dsv.scipro.report; package se.su.dsv.scipro.report;
import java.io.Serializable; public interface GradeCalculator {
public interface GradeCalculator extends Serializable {
GradingReport.Grade getGrade(GradingReport gradingReport); GradingReport.Grade getGrade(GradingReport gradingReport);
long getPoints(GradingReport gradingReport); long getPoints(GradingReport gradingReport);

@ -4,7 +4,6 @@ import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel; import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import se.su.dsv.scipro.components.OppositeVisibility; import se.su.dsv.scipro.components.OppositeVisibility;
import se.su.dsv.scipro.report.GradeCalculator; import se.su.dsv.scipro.report.GradeCalculator;
import se.su.dsv.scipro.report.GradingReport; import se.su.dsv.scipro.report.GradingReport;
@ -18,15 +17,13 @@ public class GradingReportPointsPanel extends Panel {
public GradingReportPointsPanel( public GradingReportPointsPanel(
String id, String id,
final IModel<? extends GradingReport> gradingReportIModel, final IModel<? extends GradingReport> gradingReportIModel,
final GradeCalculator gradeCalculator final IModel<GradeCalculator> gradeCalculator
) { ) {
super(id, gradingReportIModel); super(id, gradingReportIModel);
final IModel<GradingReport.Grade> gradeModel = new LoadableDetachableModel<>() { final IModel<GradingReport.Grade> gradeModel = gradingReportIModel.combineWith(
@Override gradeCalculator,
protected GradingReport.Grade load() { GradingReport::getGrade
return gradingReportIModel.getObject().getGrade(gradeCalculator); );
}
};
final Label grade = new Label(GRADE, gradeModel.map(GradingReport.Grade::name)) { final Label grade = new Label(GRADE, gradeModel.map(GradingReport.Grade::name)) {
@Override @Override
protected void onConfigure() { protected void onConfigure() {
@ -36,12 +33,7 @@ public class GradingReportPointsPanel extends Panel {
}; };
add(grade); add(grade);
final IModel<Long> points = new LoadableDetachableModel<>() { final IModel<Long> points = gradingReportIModel.combineWith(gradeCalculator, GradingReport::getPoints);
@Override
protected Long load() {
return gradingReportIModel.getObject().getPoints(gradeCalculator);
}
};
add(new Label(POINTS_LABEL, points)); add(new Label(POINTS_LABEL, points));
add(new WebMarkupContainer(NO_GRADE_EXPLANATION).add(new OppositeVisibility(grade))); add(new WebMarkupContainer(NO_GRADE_EXPLANATION).add(new OppositeVisibility(grade)));

@ -271,8 +271,8 @@ public class IndividualAuthorAssessmentPanel extends GenericPanel<User> {
new TemplatePanel("points_to_grade_conversion", gradingReport.map(SupervisorGradingReport::getProject)) new TemplatePanel("points_to_grade_conversion", gradingReport.map(SupervisorGradingReport::getProject))
); );
GradeCalculator supervisorCalculator = gradeCalculatorService.getSupervisorCalculator( IModel<GradeCalculator> supervisorCalculator = LoadableDetachableModel.of(() ->
gradingReport.getObject().getProject() gradeCalculatorService.getSupervisorCalculator(gradingReport.getObject().getProject())
); );
add(new GradingReportPointsPanel("points", gradingReport, supervisorCalculator)); add(new GradingReportPointsPanel("points", gradingReport, supervisorCalculator));

@ -62,7 +62,7 @@ public class GradingReportPointsPanelTest extends SciProTest {
private void startPanel() { private void startPanel() {
panel = tester.startComponentInPage( panel = tester.startComponentInPage(
new GradingReportPointsPanel("id", Model.of(gradingReport), gradeCalculator) new GradingReportPointsPanel("id", Model.of(gradingReport), () -> gradeCalculator)
); );
} }