diff --git a/src/main/java/de/tum/cit/aet/artemis/atlas/service/competency/CompetencyJolService.java b/src/main/java/de/tum/cit/aet/artemis/atlas/service/competency/CompetencyJolService.java index 7fa11b6f69b9..3885f233b224 100644 --- a/src/main/java/de/tum/cit/aet/artemis/atlas/service/competency/CompetencyJolService.java +++ b/src/main/java/de/tum/cit/aet/artemis/atlas/service/competency/CompetencyJolService.java @@ -23,7 +23,7 @@ import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; import de.tum.cit.aet.artemis.core.exception.BadRequestAlertException; import de.tum.cit.aet.artemis.core.repository.UserRepository; -import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventService; +import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventPublisher; import de.tum.cit.aet.artemis.iris.service.pyris.event.CompetencyJolSetEvent; /** @@ -45,15 +45,15 @@ public class CompetencyJolService { private final UserRepository userRepository; - private final Optional pyrisEventService; + private final Optional pyrisEventPublisher; public CompetencyJolService(CompetencyJolRepository competencyJolRepository, CompetencyRepository competencyRepository, - CompetencyProgressRepository competencyProgressRepository, UserRepository userRepository, Optional pyrisEventService) { + CompetencyProgressRepository competencyProgressRepository, UserRepository userRepository, Optional pyrisEventPublisher) { this.competencyJolRepository = competencyJolRepository; this.competencyRepository = competencyRepository; this.competencyProgressRepository = competencyProgressRepository; this.userRepository = userRepository; - this.pyrisEventService = pyrisEventService; + this.pyrisEventPublisher = pyrisEventPublisher; } /** @@ -84,10 +84,10 @@ public void setJudgementOfLearning(long competencyId, long userId, short jolValu final var jol = createCompetencyJol(competencyId, userId, jolValue, ZonedDateTime.now(), competencyProgress); competencyJolRepository.save(jol); - pyrisEventService.ifPresent(service -> { - // Inform Iris so it can send a message to the user + // Inform Iris so it can send a message to the user + pyrisEventPublisher.ifPresent(service -> { try { - service.trigger(new CompetencyJolSetEvent(jol)); + service.publishEvent(new CompetencyJolSetEvent(this, jol)); } catch (Exception e) { log.warn("Something went wrong while sending the judgement of learning to Iris", e); diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventPublisher.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventPublisher.java new file mode 100644 index 000000000000..ff0695af0698 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventPublisher.java @@ -0,0 +1,106 @@ +package de.tum.cit.aet.artemis.iris.service.pyris; + +import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_IRIS; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +import de.tum.cit.aet.artemis.iris.domain.settings.event.IrisEventType; +import de.tum.cit.aet.artemis.iris.service.pyris.event.CompetencyJolSetEvent; +import de.tum.cit.aet.artemis.iris.service.pyris.event.NewResultEvent; +import de.tum.cit.aet.artemis.iris.service.pyris.event.PyrisEvent; +import de.tum.cit.aet.artemis.iris.service.settings.IrisSettingsService; +import de.tum.cit.aet.artemis.programming.domain.ProgrammingSubmission; + +/** + * Service for publishing Pyris events. + */ +@Service +@Profile(PROFILE_IRIS) +public class PyrisEventPublisher { + + private static final Logger log = LoggerFactory.getLogger(PyrisEventPublisher.class); + + private final ApplicationEventPublisher eventPublisher; + + private final IrisSettingsService irisSettingsService; + + public PyrisEventPublisher(ApplicationEventPublisher eventPublisher, IrisSettingsService irisSettingsService) { + this.eventPublisher = eventPublisher; + this.irisSettingsService = irisSettingsService; + } + + /** + * Publishes the given event. + * + * @param event the event to publish + */ + public void publishEvent(PyrisEvent event) { + isEventSupportedElseThrow(event); + if (!isEventEnabled(event)) { + log.debug("Skipping event publication as conditions are not met: {}", event.getClass().getSimpleName()); + return; + } + try { + eventPublisher.publishEvent(event); + } + catch (Exception e) { + log.error("Failed to publish event: {}", event, e); + throw e; + } + } + + /** + * Checks if the given event is supported and throws an exception if it is not. + * + * @param event - the event to check + */ + private void isEventSupportedElseThrow(ApplicationEvent event) { + if (!isEventSupported(event)) { + throw new UnsupportedPyrisEventException("Event not supported: " + event); + } + } + + /** + * Checks if the given event is supported. + * + * @param event the event to publish + */ + private boolean isEventSupported(ApplicationEvent event) { + return event instanceof PyrisEvent; + } + + private boolean isEventEnabled(PyrisEvent event) { + return switch (event) { + case NewResultEvent newResultEvent -> { + var result = newResultEvent.getResult(); + var submission = result.getSubmission(); + if (submission instanceof ProgrammingSubmission programmingSubmission) { + var programmingExercise = programmingSubmission.getParticipation().getExercise(); + if (programmingSubmission.isBuildFailed()) { + yield irisSettingsService.isActivatedFor(IrisEventType.BUILD_FAILED, programmingExercise); + } + else { + yield irisSettingsService.isActivatedFor(IrisEventType.PROGRESS_STALLED, programmingExercise); + } + } + else { + yield false; + } + } + case CompetencyJolSetEvent competencyJolSetEvent -> { + var competencyJol = competencyJolSetEvent.getCompetencyJol(); + var course = competencyJol.getCompetency().getCourse(); + yield irisSettingsService.isActivatedFor(IrisEventType.JOL, course); + } + default -> { + log.warn("Unknown event type: {}", event.getClass().getSimpleName()); + yield false; + } + }; + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventService.java index 58f0b8a069b8..4cf7865d5d8d 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisEventService.java @@ -5,18 +5,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; -import de.tum.cit.aet.artemis.iris.domain.session.IrisChatSession; import de.tum.cit.aet.artemis.iris.service.pyris.event.CompetencyJolSetEvent; import de.tum.cit.aet.artemis.iris.service.pyris.event.NewResultEvent; -import de.tum.cit.aet.artemis.iris.service.pyris.event.PyrisEvent; -import de.tum.cit.aet.artemis.iris.service.session.AbstractIrisChatSessionService; import de.tum.cit.aet.artemis.iris.service.session.IrisCourseChatSessionService; import de.tum.cit.aet.artemis.iris.service.session.IrisExerciseChatSessionService; +import de.tum.cit.aet.artemis.programming.domain.ProgrammingSubmission; /** - * Service to handle Pyris events. + * Service for handling Pyris events. */ @Service @Profile(PROFILE_IRIS) @@ -33,33 +32,38 @@ public PyrisEventService(IrisCourseChatSessionService irisCourseChatSessionServi this.irisExerciseChatSessionService = irisExerciseChatSessionService; } - /** - * Triggers a Pyris pipeline based on the received {@link PyrisEvent}. - * - * @param event The event object received to trigger the matching pipeline - * @throws UnsupportedPyrisEventException if the event is not supported - * - * @see PyrisEvent - */ - public void trigger(PyrisEvent, ?> event) { - log.debug("Starting to process event of type: {}", event.getClass().getSimpleName()); + @EventListener + public void handleCompetencyJolSetEvent(CompetencyJolSetEvent event) { + log.debug("Processing CompetencyJolSetEvent"); try { - switch (event) { - case CompetencyJolSetEvent competencyJolSetEvent -> { - log.info("Processing CompetencyJolSetEvent: {}", competencyJolSetEvent); - competencyJolSetEvent.handleEvent(irisCourseChatSessionService); - log.debug("Successfully processed CompetencyJolSetEvent"); + irisCourseChatSessionService.onJudgementOfLearningSet(event.getCompetencyJol()); + log.debug("Successfully processed CompetencyJolSetEvent"); + } + catch (Exception e) { + log.error("Failed to process CompetencyJolSetEvent: {}", event, e); + throw e; + } + } + + @EventListener + public void handleNewResultEvent(NewResultEvent event) { + log.debug("Processing NewResultEvent"); + try { + var result = event.getResult(); + var submission = result.getSubmission(); + + if (submission instanceof ProgrammingSubmission programmingSubmission) { + if (programmingSubmission.isBuildFailed()) { + irisExerciseChatSessionService.onBuildFailure(result); } - case NewResultEvent newResultEvent -> { - log.info("Processing NewResultEvent: {}", newResultEvent); - newResultEvent.handleEvent(irisExerciseChatSessionService); - log.debug("Successfully processed NewResultEvent"); + else { + irisExerciseChatSessionService.onNewResult(result); } - default -> throw new UnsupportedPyrisEventException("Unsupported event type: " + event.getClass().getSimpleName()); } + log.debug("Successfully processed NewResultEvent"); } catch (Exception e) { - log.error("Failed to process event: {}", event, e); + log.error("Failed to process NewResultEvent: {}", event, e); throw e; } } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/CompetencyJolSetEvent.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/CompetencyJolSetEvent.java index 9ee7448811b4..8ad3710df44b 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/CompetencyJolSetEvent.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/CompetencyJolSetEvent.java @@ -1,21 +1,28 @@ package de.tum.cit.aet.artemis.iris.service.pyris.event; +import java.util.Optional; + import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyJol; -import de.tum.cit.aet.artemis.iris.service.session.IrisCourseChatSessionService; +import de.tum.cit.aet.artemis.core.domain.User; -public class CompetencyJolSetEvent extends PyrisEvent { +public class CompetencyJolSetEvent extends PyrisEvent { - private final CompetencyJol eventObject; + private final CompetencyJol competencyJol; - public CompetencyJolSetEvent(CompetencyJol eventObject) { - if (eventObject == null) { - throw new IllegalArgumentException("Event object cannot be null"); + public CompetencyJolSetEvent(Object source, CompetencyJol competencyJol) { + super(source); + if (competencyJol == null) { + throw new IllegalArgumentException("CompetencyJol cannot be null"); } - this.eventObject = eventObject; + this.competencyJol = competencyJol; + } + + public CompetencyJol getCompetencyJol() { + return competencyJol; } @Override - public void handleEvent(IrisCourseChatSessionService service) { - service.onJudgementOfLearningSet(eventObject); + public Optional getUser() { + return Optional.ofNullable(competencyJol.getUser()); } } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/NewResultEvent.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/NewResultEvent.java index 27516dff283a..1917f755a2f3 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/NewResultEvent.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/NewResultEvent.java @@ -1,34 +1,32 @@ package de.tum.cit.aet.artemis.iris.service.pyris.event; +import java.util.Optional; + import de.tum.cit.aet.artemis.assessment.domain.Result; -import de.tum.cit.aet.artemis.iris.service.session.IrisExerciseChatSessionService; -import de.tum.cit.aet.artemis.programming.domain.ProgrammingSubmission; +import de.tum.cit.aet.artemis.core.domain.User; +import de.tum.cit.aet.artemis.programming.domain.ProgrammingExerciseStudentParticipation; -public class NewResultEvent extends PyrisEvent { +public class NewResultEvent extends PyrisEvent { - private final Result eventObject; + private final Result result; - public NewResultEvent(Result eventObject) { - if (eventObject == null) { - throw new IllegalArgumentException("Event object cannot be null"); + public NewResultEvent(Object source, Result result) { + super(source); + if (result == null) { + throw new IllegalArgumentException("Result cannot be null"); } - this.eventObject = eventObject; + this.result = result; + } + + public Result getResult() { + return result; } @Override - public void handleEvent(IrisExerciseChatSessionService service) { - if (service == null) { - throw new IllegalArgumentException("Service cannot be null"); - } - var submission = eventObject.getSubmission(); - // We only care about programming submissions - if (submission instanceof ProgrammingSubmission programmingSubmission) { - if (programmingSubmission.isBuildFailed()) { - service.onBuildFailure(eventObject); - } - else { - service.onNewResult(eventObject); - } + public Optional getUser() { + if (result.getSubmission().getParticipation() instanceof ProgrammingExerciseStudentParticipation studentParticipation) { + return studentParticipation.getStudent(); } + return Optional.empty(); } } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/PyrisEvent.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/PyrisEvent.java index 0f4a723653d6..ba6d4d5b94e0 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/PyrisEvent.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/event/PyrisEvent.java @@ -1,14 +1,24 @@ package de.tum.cit.aet.artemis.iris.service.pyris.event; -import de.tum.cit.aet.artemis.iris.domain.session.IrisChatSession; -import de.tum.cit.aet.artemis.iris.service.session.AbstractIrisChatSessionService; +import java.util.Optional; -public abstract class PyrisEvent, T> { +import org.springframework.context.ApplicationEvent; + +import de.tum.cit.aet.artemis.core.domain.User; + +/** + * Base class for Pyris events. + */ +public abstract class PyrisEvent extends ApplicationEvent { + + public PyrisEvent(Object source) { + super(source); + } /** - * Handles the event using the given service. + * Returns the user associated with this event. * - * @param service The service to handle the event for + * @return the user */ - public abstract void handleEvent(S service); + public abstract Optional getUser(); } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisCourseChatSessionService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisCourseChatSessionService.java index f6a97190142c..00b5379f1496 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisCourseChatSessionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisCourseChatSessionService.java @@ -133,9 +133,6 @@ protected void setLLMTokenUsageParameters(LLMTokenUsageService.LLMTokenUsageBuil */ public void onJudgementOfLearningSet(CompetencyJol competencyJol) { var course = competencyJol.getCompetency().getCourse(); - if (!irisSettingsService.isEnabledFor(IrisSubSettingsType.COURSE_CHAT, course)) { - return; - } var user = competencyJol.getUser(); user.hasAcceptedIrisElseThrow(); var session = getCurrentSessionOrCreateIfNotExistsInternal(course, user, false); diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisExerciseChatSessionService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisExerciseChatSessionService.java index 60c72e952b10..91b7c643258f 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisExerciseChatSessionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/session/IrisExerciseChatSessionService.java @@ -188,11 +188,6 @@ public void onBuildFailure(Result result) { } var exercise = validateExercise(participation.getExercise()); - if (!irisSettingsService.isActivatedFor(IrisEventType.BUILD_FAILED, exercise)) { - log.info("Build failure event is not activated for exercise {}", exercise.getId()); - return; - } - var participant = studentParticipation.getParticipant(); if (participant instanceof User user) { var session = getCurrentSessionOrCreateIfNotExistsInternal(exercise, user, false); @@ -218,11 +213,6 @@ public void onNewResult(Result result) { var exercise = validateExercise(participation.getExercise()); - if (!irisSettingsService.isActivatedFor(IrisEventType.PROGRESS_STALLED, exercise)) { - log.info("Progress stalled event is not activated for exercise {}", exercise.getId()); - return; - } - var recentSubmissions = submissionRepository.findAllWithResultsByParticipationIdOrderBySubmissionDateAsc(studentParticipation.getId()); double successThreshold = 100.0; // TODO: Retrieve configuration from Iris settings diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java index 591e78caee3c..ff5891a219c6 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/settings/IrisSettingsService.java @@ -758,7 +758,16 @@ private boolean isEventEnabledInSettings(IrisCombinedSettingsDTO settings, IrisE yield true; } } - default -> throw new IllegalStateException("Unexpected value: " + type); // TODO: Add JOL event, once Course Chat Settings are implemented + case JOL -> { + if (settings.irisChatSettings().disabledProactiveEvents() != null) { + var isEventEnabled = !settings.irisChatSettings().disabledProactiveEvents().contains(IrisEventType.JOL.name().toLowerCase()); + log.debug("Event JOL enabled: {}", isEventEnabled); + yield isEventEnabled; + } + else { + yield true; + } + } }; } } diff --git a/src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingMessagingService.java b/src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingMessagingService.java index 8c73f1b25850..e25ebc1930f9 100644 --- a/src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingMessagingService.java +++ b/src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingMessagingService.java @@ -25,7 +25,7 @@ import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation; import de.tum.cit.aet.artemis.exercise.dto.SubmissionDTO; import de.tum.cit.aet.artemis.exercise.repository.TeamRepository; -import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventService; +import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventPublisher; import de.tum.cit.aet.artemis.iris.service.pyris.event.NewResultEvent; import de.tum.cit.aet.artemis.lti.service.LtiNewResultService; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; @@ -51,17 +51,17 @@ public class ProgrammingMessagingService { private final TeamRepository teamRepository; - private final Optional pyrisEventService; + private final Optional pyrisEventPublisher; public ProgrammingMessagingService(GroupNotificationService groupNotificationService, WebsocketMessagingService websocketMessagingService, ResultWebsocketService resultWebsocketService, Optional ltiNewResultService, TeamRepository teamRepository, - Optional pyrisEventService) { + Optional pyrisEventPublisher) { this.groupNotificationService = groupNotificationService; this.websocketMessagingService = websocketMessagingService; this.resultWebsocketService = resultWebsocketService; this.ltiNewResultService = ltiNewResultService; this.teamRepository = teamRepository; - this.pyrisEventService = pyrisEventService; + this.pyrisEventPublisher = pyrisEventPublisher; } private static String getExerciseTopicForTAAndAbove(long exerciseId) { @@ -170,7 +170,8 @@ public void notifyInstructorGroupAboutIllegalSubmissionsForExercise(ProgrammingE * @param participation the participation for which the result was created. */ public void notifyUserAboutNewResult(Result result, ProgrammingExerciseParticipation participation) { - log.debug("Send result to client over websocket. Result: {}, Submission: {}, Participation: {}", result, result.getSubmission(), result.getParticipation()); + var submission = result.getSubmission(); + log.debug("Send result to client over websocket. Result: {}, Submission: {}, Participation: {}", result, submission, submission.getParticipation()); // notify user via websocket resultWebsocketService.broadcastNewResult((Participation) participation, result); @@ -193,13 +194,12 @@ public void notifyUserAboutNewResult(Result result, ProgrammingExerciseParticipa */ private void notifyIrisAboutSubmissionStatus(Result result, ProgrammingExerciseStudentParticipation studentParticipation) { if (studentParticipation.getParticipant() instanceof User) { - pyrisEventService.ifPresent(eventService -> { - // Inform event service about the new result + pyrisEventPublisher.ifPresent(service -> { try { - eventService.trigger(new NewResultEvent(result)); + service.publishEvent(new NewResultEvent(this, result)); } catch (Exception e) { - log.error("Could not trigger service for result {}", result.getId(), e); + log.error("Could not publish event for result {}", result.getId(), e); } }); } diff --git a/src/test/java/de/tum/cit/aet/artemis/iris/PyrisEventSystemIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/iris/PyrisEventSystemIntegrationTest.java index dccb9eff49e9..760fa1409415 100644 --- a/src/test/java/de/tum/cit/aet/artemis/iris/PyrisEventSystemIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/iris/PyrisEventSystemIntegrationTest.java @@ -39,13 +39,11 @@ import de.tum.cit.aet.artemis.iris.domain.settings.event.IrisEventType; import de.tum.cit.aet.artemis.iris.repository.IrisSettingsRepository; import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventProcessingException; +import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventPublisher; import de.tum.cit.aet.artemis.iris.service.pyris.PyrisEventService; import de.tum.cit.aet.artemis.iris.service.pyris.PyrisJobService; import de.tum.cit.aet.artemis.iris.service.pyris.PyrisStatusUpdateService; -import de.tum.cit.aet.artemis.iris.service.pyris.UnsupportedPyrisEventException; import de.tum.cit.aet.artemis.iris.service.pyris.event.NewResultEvent; -import de.tum.cit.aet.artemis.iris.service.pyris.event.PyrisEvent; -import de.tum.cit.aet.artemis.iris.service.session.IrisExerciseChatSessionService; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise; import de.tum.cit.aet.artemis.programming.domain.ProgrammingExerciseStudentParticipation; import de.tum.cit.aet.artemis.programming.domain.ProgrammingSubmission; @@ -64,6 +62,9 @@ class PyrisEventSystemIntegrationTest extends AbstractIrisIntegrationTest { @Autowired protected PyrisJobService pyrisJobService; + @Autowired + private PyrisEventService pyrisEventService; + @Autowired protected IrisSettingsRepository irisSettingsRepository; @@ -74,7 +75,7 @@ class PyrisEventSystemIntegrationTest extends AbstractIrisIntegrationTest { private SubmissionTestRepository submissionRepository; @Autowired - private PyrisEventService pyrisEventService; + private PyrisEventPublisher pyrisEventPublisher; @Autowired private ParticipationUtilService participationUtilService; @@ -192,7 +193,7 @@ void testShouldFireProgressStalledEvent() { pipelineDone.set(true); }); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); verify(irisExerciseChatSessionService, times(1)).onNewResult(eq(result)); await().atMost(2, TimeUnit.SECONDS).until(() -> pipelineDone.get()); @@ -212,7 +213,7 @@ void testShouldFireBuildFailedEvent() { pipelineDone.set(true); }); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); verify(irisExerciseChatSessionService, times(1)).onBuildFailure(eq(result)); await().atMost(2, TimeUnit.SECONDS).until(() -> pipelineDone.get()); @@ -239,19 +240,6 @@ void testShouldFireJolEvent() { } - @Test - @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") - void testShouldThrowUnsupportedEventException() { - assertThatExceptionOfType(UnsupportedPyrisEventException.class).isThrownBy(() -> pyrisEventService.trigger(new PyrisEvent() { - - @Override - public void handleEvent(IrisExerciseChatSessionService service) { - // Do nothing - } - })).withMessageStartingWith("Unsupported event"); - - } - @Test() @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") void testShouldNotFireProgressStalledEventWithEventDisabled() { @@ -263,9 +251,9 @@ void testShouldNotFireProgressStalledEventWithEventDisabled() { createSubmissionWithScore(studentParticipation, 40); createSubmissionWithScore(studentParticipation, 40); var result = createSubmissionWithScore(studentParticipation, 40); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); - verify(irisExerciseChatSessionService, times(1)).onNewResult(any(Result.class)); + verify(irisExerciseChatSessionService, times(0)).onNewResult(any(Result.class)); verify(pyrisPipelineService, times(0)).executeExerciseChatPipeline(any(), any(), any(), any(), any()); } @@ -280,9 +268,9 @@ void testShouldNotFireBuildFailedEventWhenEventSettingDisabled() { irisExerciseChatSessionService.createChatSessionForProgrammingExercise(exercise, userUtilService.getUserByLogin(TEST_PREFIX + "student1")); // Create a failing submission for the student. var result = createFailingSubmission(studentParticipation); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); - verify(irisExerciseChatSessionService, times(1)).onBuildFailure(any(Result.class)); + verify(irisExerciseChatSessionService, times(0)).onBuildFailure(any(Result.class)); verify(pyrisPipelineService, times(0)).executeExerciseChatPipeline(any(), any(), any(), any(), any()); } @@ -297,13 +285,13 @@ void testShouldShouldNotFireProgressStalledEventWithExistingSuccessfulSubmission createSubmissionWithScore(studentParticipation, 100); var result = createSubmissionWithScore(studentParticipation, 50); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); await().atMost(2, TimeUnit.SECONDS); result = createSubmissionWithScore(studentParticipation, 50); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); await().atMost(2, TimeUnit.SECONDS); verify(irisExerciseChatSessionService, times(2)).onNewResult(any(Result.class)); @@ -318,7 +306,7 @@ void testShouldNotFireProgressStalledEventWithLessThanThreeSubmissions() { createSubmissionWithScore(studentParticipation, 20); var result = createSubmissionWithScore(studentParticipation, 20); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); verify(irisExerciseChatSessionService, times(1)).onNewResult(any(Result.class)); verify(pyrisPipelineService, times(0)).executeExerciseChatPipeline(any(), any(), any(), any(), any()); @@ -333,7 +321,7 @@ void testShouldNotFireProgressStalledEventWithIncreasingScores() { createSubmissionWithScore(studentParticipation, 30); var result = createSubmissionWithScore(studentParticipation, 40); - pyrisEventService.trigger(new NewResultEvent(result)); + pyrisEventPublisher.publishEvent(new NewResultEvent(this, result)); verify(irisExerciseChatSessionService, times(1)).onNewResult(any(Result.class)); verify(pyrisPipelineService, times(0)).executeExerciseChatPipeline(any(), any(), any(), any(), any());