Notify the author when reflection improvements are needed

Can not send the notification from the Notifications class since that class is registered in the test-context and for some reason HSQLDB fails with some unknown check constraint violation with absolutely no information about why.

For some reason it is not possible to debug HSQLDB with breakpoints to step through and see exactly why it fails, so registering a new single purpose class in the cross-cutting module (that's not available in test) is used as a work-around.
This commit is contained in:
Andreas Svanberg 2024-09-25 13:57:57 +02:00
parent 32353c0d1f
commit ffb571fd23
7 changed files with 56 additions and 2 deletions

@ -20,7 +20,7 @@ public class ProjectEvent extends NotificationEvent {
ROUGH_DRAFT_APPROVAL_APPROVED, ROUGH_DRAFT_APPROVAL_REJECTED, REVIEWER_GRADING_REPORT_SUBMITTED,
ONE_YEAR_PASSED_FROM_LATEST_ANNUAL_REVIEW, SUPERVISOR_GRADING_INITIAL_ASSESSMENT_DONE,
EXPORTED_SUCCESS, REVIEWER_GRADING_INITIAL_ASSESSMENT_DONE, FIRST_MEETING, OPPOSITION_FAILED, PARTICIPATION_APPROVED, COMPLETED,
PARTICIPATION_FAILED
REFLECTION_IMPROVEMENTS_REQUESTED, PARTICIPATION_FAILED
}
@ManyToOne

@ -85,6 +85,10 @@ PROJECT.PARTICIPATION_APPROVED.body = Your active participation on {0} has been
PROJECT.PARTICIPATION_FAILED.title = Your active participation on {1} did not meet the minimum requirements.
PROJECT.PARTICIPATION_FAILED.body = Your active participation did not meet the minimum requirements set, and you will \
have to be an active participant on a different final seminar to pass this step.
PROJECT.REFLECTION_IMPROVEMENTS_REQUESTED.title = Reflection improvements requested
PROJECT.REFLECTION_IMPROVEMENTS_REQUESTED.body = The supervisor has deemed that the reflection submitted does not meet \
the minimum requirements and has requested improvements. Please log into SciPro and submit a new reflection. \
Their comments can be seen below:\n\n{0}
FORUM.NEW_FORUM_POST.title = Forum post: {2}
FORUM.NEW_FORUM_POST.body = New forum post submitted:<br /><br />{0}

@ -0,0 +1,7 @@
package se.su.dsv.scipro.reflection;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.system.User;
public record ReflectionImprovementsRequestedEvent(Project project, User author, String supervisorComment) {
}

@ -1,5 +1,6 @@
package se.su.dsv.scipro.reflection;
import com.google.common.eventbus.EventBus;
import com.google.inject.persist.Transactional;
import se.su.dsv.scipro.finalseminar.AuthorRepository;
import se.su.dsv.scipro.finalseminar.FinalSeminarService;
@ -15,11 +16,17 @@ import java.util.Optional;
class ReflectionServiceImpl implements ReflectionService {
private final AuthorRepository authorRepository;
private final FinalSeminarService finalSeminarService;
private final EventBus eventBus;
@Inject
ReflectionServiceImpl(AuthorRepository authorRepository, FinalSeminarService finalSeminarService) {
ReflectionServiceImpl(
AuthorRepository authorRepository,
FinalSeminarService finalSeminarService,
EventBus eventBus)
{
this.authorRepository = authorRepository;
this.finalSeminarService = finalSeminarService;
this.eventBus = eventBus;
}
@Override
@ -63,6 +70,7 @@ class ReflectionServiceImpl implements ReflectionService {
author.setReflectionStatus(ReflectionStatus.IMPROVEMENTS_NEEDED);
author.setReflectionSupervisorComment(supervisorComment);
});
eventBus.post(new ReflectionImprovementsRequestedEvent(project, user, supervisorComment));
}
@Override

@ -13,5 +13,6 @@ public class CrosscuttingModule extends AbstractModule {
bind(ReviewerAssignedNotifications.class).asEagerSingleton();
bind(ReviewerAssignedDeadline.class).asEagerSingleton();
bind(ForwardPhase2Feedback.class).asEagerSingleton();
bind(NotifyFailedReflection.class).asEagerSingleton();
}
}

@ -0,0 +1,33 @@
package se.su.dsv.scipro.crosscutting;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import jakarta.inject.Inject;
import se.su.dsv.scipro.data.dataobjects.Member;
import se.su.dsv.scipro.notifications.NotificationController;
import se.su.dsv.scipro.notifications.dataobject.NotificationSource;
import se.su.dsv.scipro.notifications.dataobject.ProjectEvent;
import se.su.dsv.scipro.reflection.ReflectionImprovementsRequestedEvent;
import java.util.Set;
public class NotifyFailedReflection {
private final NotificationController notificationController;
@Inject
public NotifyFailedReflection(NotificationController notificationController, EventBus eventBus) {
this.notificationController = notificationController;
eventBus.register(this);
}
@Subscribe
public void reflectionImprovementsRequested(ReflectionImprovementsRequestedEvent event) {
NotificationSource source = new NotificationSource();
source.setMessage(event.supervisorComment());
notificationController.notifyCustomProject(
event.project(),
ProjectEvent.Event.REFLECTION_IMPROVEMENTS_REQUESTED,
source,
Set.of(new Member(event.author(), Member.Type.AUTHOR)));
}
}

@ -65,6 +65,7 @@ ProjectEvent.FIRST_MEETING = First meeting created. (with date, time, place/room
ProjectEvent.OPPOSITION_FAILED = An author fails their opposition.
ProjectEvent.PARTICIPATION_APPROVED = An author's active participation is approved.
ProjectEvent.PARTICIPATION_FAILED = An author fails their active participation.
ProjectEvent.REFLECTION_IMPROVEMENTS_REQUESTED = Reflection improvements requested.
ProjectForumEvent.NEW_FORUM_POST = Forum thread created.
ProjectForumEvent.NEW_FORUM_POST_COMMENT = Comment posted in forum thread.