Fix grade calculator being serialized #59

Merged
niat8586 merged 1 commits from grade-calculator-serialization into develop 2024-12-16 11:24:34 +01:00
4 changed files with 10 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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