diff --git a/core/src/main/java/se/su/dsv/scipro/CoreConfig.java b/core/src/main/java/se/su/dsv/scipro/CoreConfig.java index d94c934073..080ff17d1a 100644 --- a/core/src/main/java/se/su/dsv/scipro/CoreConfig.java +++ b/core/src/main/java/se/su/dsv/scipro/CoreConfig.java @@ -154,6 +154,7 @@ import se.su.dsv.scipro.report.GradingReportServiceImpl; import se.su.dsv.scipro.report.GradingReportTemplateRepo; import se.su.dsv.scipro.report.GradingReportTemplateRepoImpl; import se.su.dsv.scipro.report.OppositionReportRepo; +import se.su.dsv.scipro.report.OppositionReportService; import se.su.dsv.scipro.report.OppositionReportServiceImpl; import se.su.dsv.scipro.report.ReportServiceImpl; import se.su.dsv.scipro.report.SupervisorGradingReportRepository; @@ -438,7 +439,8 @@ public class CoreConfig { FinalSeminarOppositionRepo finalSeminarOppositionRepository, Clock clock, FinalSeminarSettingsService finalSeminarSettingsService, - DaysService daysService + DaysService daysService, + OppositionReportService oppositionReportService ) { return new FinalSeminarOppositionServiceImpl( em, @@ -447,7 +449,8 @@ public class CoreConfig { finalSeminarOppositionRepository, clock, finalSeminarSettingsService, - daysService + daysService, + oppositionReportService ); } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionService.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionService.java index e3b82f0682..e7d7916583 100755 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionService.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionService.java @@ -3,10 +3,7 @@ package se.su.dsv.scipro.finalseminar; import java.time.Instant; import se.su.dsv.scipro.system.GenericService; -public interface FinalSeminarOppositionService extends GenericService<FinalSeminarOpposition, Long> { - @Override - void delete(Long aLong); - +public interface FinalSeminarOppositionService { OppositionCriteria getCriteriaForOpposition(FinalSeminarOpposition opposition); FinalSeminarOpposition gradeOpponent(FinalSeminarOpposition opposition, int points, String feedback) @@ -16,4 +13,6 @@ public interface FinalSeminarOppositionService extends GenericService<FinalSemin * @return the deadline by which the improvements must have been submitted */ Instant requestImprovements(FinalSeminarOpposition opposition, String supervisorComment); + + Opposition getOpposition(long id); } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionServiceImpl.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionServiceImpl.java index f175df78a9..a39d78eeda 100755 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionServiceImpl.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOppositionServiceImpl.java @@ -10,6 +10,7 @@ import java.time.Instant; import java.util.List; import se.su.dsv.scipro.misc.DaysService; import se.su.dsv.scipro.report.OppositionReport; +import se.su.dsv.scipro.report.OppositionReportService; import se.su.dsv.scipro.system.AbstractServiceImpl; public class FinalSeminarOppositionServiceImpl @@ -22,6 +23,7 @@ public class FinalSeminarOppositionServiceImpl private final Clock clock; private final FinalSeminarSettingsService finalSeminarSettingsService; private final DaysService daysService; + private final OppositionReportService oppositionReportService; @Inject public FinalSeminarOppositionServiceImpl( @@ -31,7 +33,8 @@ public class FinalSeminarOppositionServiceImpl FinalSeminarOppositionRepo finalSeminarOppositionRepository, Clock clock, FinalSeminarSettingsService finalSeminarSettingsService, - DaysService daysService + DaysService daysService, + OppositionReportService oppositionReportService ) { super(em, FinalSeminarOpposition.class, QFinalSeminarOpposition.finalSeminarOpposition); this.finalSeminarOppositionGrading = finalSeminarOppositionGrading; @@ -40,6 +43,7 @@ public class FinalSeminarOppositionServiceImpl this.clock = clock; this.finalSeminarSettingsService = finalSeminarSettingsService; this.daysService = daysService; + this.oppositionReportService = oppositionReportService; } @Override @@ -95,4 +99,14 @@ public class FinalSeminarOppositionServiceImpl return deadline; } + + @Override + public Opposition getOpposition(long id) { + FinalSeminarOpposition finalSeminarOpposition = finalSeminarOppositionRepository.findOne(id); + if (finalSeminarOpposition == null) { + return null; + } + OppositionReport report = oppositionReportService.findOrCreateReport(finalSeminarOpposition); + return new Opposition(finalSeminarOpposition.getUser(), report); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/Opposition.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/Opposition.java new file mode 100644 index 0000000000..b661be2a32 --- /dev/null +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/Opposition.java @@ -0,0 +1,6 @@ +package se.su.dsv.scipro.finalseminar; + +import se.su.dsv.scipro.report.OppositionReport; +import se.su.dsv.scipro.system.User; + +public record Opposition(User user, OppositionReport report) {} diff --git a/view/src/main/java/se/su/dsv/scipro/finalseminar/OppositionReportPage.java b/view/src/main/java/se/su/dsv/scipro/finalseminar/OppositionReportPage.java index 743e8aaee5..8c4ffcad8b 100644 --- a/view/src/main/java/se/su/dsv/scipro/finalseminar/OppositionReportPage.java +++ b/view/src/main/java/se/su/dsv/scipro/finalseminar/OppositionReportPage.java @@ -35,13 +35,15 @@ public class OppositionReportPage extends AbstractProjectDetailsPage implements throw new RestartResponseException(ProjectDetailsPage.class, pp); } - final FinalSeminarOpposition opposition = finalSeminarOppositionService.findOne(pp.get("oid").toLong()); + final IModel<Opposition> opposition = LoadableDetachableModel.of(() -> + finalSeminarOppositionService.getOpposition(pp.get("oid").toLong()) + ); - if (opposition == null) { + if (opposition.getObject() == null) { throw new RestartResponseException(ProjectDetailsPage.class, pp); } - final IModel<OppositionReport> report = getOppositionReport(opposition); + final IModel<OppositionReport> report = opposition.map(Opposition::report); add( new ViewAttachmentPanel( @@ -71,18 +73,9 @@ public class OppositionReportPage extends AbstractProjectDetailsPage implements @Override protected void onConfigure() { super.onConfigure(); - setEnabled(opposition.getUser().equals(SciProSession.get().getUser())); + setEnabled(opposition.getObject().user().equals(SciProSession.get().getUser())); } } ); } - - private IModel<OppositionReport> getOppositionReport(final FinalSeminarOpposition opposition) { - return new LoadableDetachableModel<>() { - @Override - protected OppositionReport load() { - return oppositionReportService.findOrCreateReport(opposition); - } - }; - } } diff --git a/view/src/test/java/se/su/dsv/scipro/finalseminar/OppositionReportPageTest.java b/view/src/test/java/se/su/dsv/scipro/finalseminar/OppositionReportPageTest.java index 05b2d9a1f5..f3efe7c6ca 100644 --- a/view/src/test/java/se/su/dsv/scipro/finalseminar/OppositionReportPageTest.java +++ b/view/src/test/java/se/su/dsv/scipro/finalseminar/OppositionReportPageTest.java @@ -76,10 +76,9 @@ public class OppositionReportPageTest extends SciProTest { Mockito.when(finalSeminarService.findByProject(opponentsProject)).thenReturn(finalSeminar); } - private void mockReport(ProjectType bachelor) { + private OppositionReport mockReport(ProjectType bachelor) { GradingReportTemplate reportTemplate = createTemplate(bachelor); - OppositionReport oppositionReport = reportTemplate.createOppositionReport(finalSeminarOpposition); - Mockito.when(oppositionReportService.findOrCreateReport(finalSeminarOpposition)).thenReturn(oppositionReport); + return reportTemplate.createOppositionReport(finalSeminarOpposition); } @Test @@ -104,14 +103,16 @@ public class OppositionReportPageTest extends SciProTest { public void disable_form_if_opposition_does_not_belong_to_logged_in_user() { mockReport(bachelor); long oppositionId = 4L; - Mockito.when(finalSeminarOppositionService.findOne(oppositionId)).thenReturn(finalSeminarOpposition); + Mockito.when(finalSeminarOppositionService.getOpposition(oppositionId)).thenReturn( + new Opposition(user, mockReport(bachelor)) + ); startPage(oppositionId); tester.assertDisabled(FILL_OUT_REPORT); } @Test public void redirect_if_no_opposition_is_found_from_id() { - Mockito.when(finalSeminarOppositionService.findOne(ArgumentMatchers.anyLong())).thenReturn(null); + Mockito.when(finalSeminarOppositionService.getOpposition(ArgumentMatchers.anyLong())).thenReturn(null); startPage(1L); tester.assertRenderedPage(ProjectDetailsPage.class); } @@ -156,7 +157,9 @@ public class OppositionReportPageTest extends SciProTest { private void startOppositionPage() { long oppositionId = 4L; setLoggedInAs(user); - Mockito.when(finalSeminarOppositionService.findOne(oppositionId)).thenReturn(finalSeminarOpposition); + Mockito.when(finalSeminarOppositionService.getOpposition(oppositionId)).thenReturn( + new Opposition(user, mockReport(bachelor)) + ); startPage(oppositionId); }