Skip to content

Commit

Permalink
chore: Simplify IrisEventType.java
Browse files Browse the repository at this point in the history
  • Loading branch information
kaancayli committed Nov 30, 2024
1 parent f10ac7a commit e66e0dc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@
*/
public enum IrisEventType {

BUILD_FAILED("build_failed"), PROGRESS_STALLED("progress_stalled"), JOL("jol");

private final String name;

IrisEventType(String name) {
this.name = name;
}

public String getName() {
return name;
}
BUILD_FAILED, PROGRESS_STALLED, JOL
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void onBuildFailure(Result result) {
if (participant instanceof User user) {
var session = getCurrentSessionOrCreateIfNotExistsInternal(exercise, user, false);
log.info("Build failed for user {}", user.getName());
CompletableFuture.runAsync(() -> requestAndHandleResponse(session, Optional.of("build_failed")));
CompletableFuture.runAsync(() -> requestAndHandleResponse(session, Optional.of(IrisEventType.BUILD_FAILED.name().toLowerCase())));
}
else {
throw new PyrisEventProcessingException("Build failure event is not supported for team participations");
Expand Down Expand Up @@ -236,7 +236,7 @@ public void onNewResult(Result result) {
var participant = ((ProgrammingExerciseStudentParticipation) participation).getParticipant();
if (participant instanceof User user) {
var session = getCurrentSessionOrCreateIfNotExistsInternal(exercise, user, false);
CompletableFuture.runAsync(() -> requestAndHandleResponse(session, Optional.of("progress_stalled")));
CompletableFuture.runAsync(() -> requestAndHandleResponse(session, Optional.of(IrisEventType.PROGRESS_STALLED.name().toLowerCase())));
}
else {
throw new PyrisEventProcessingException("Progress stalled event is not supported for team participations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,15 +739,15 @@ private boolean isEventEnabledInSettings(IrisCombinedSettingsDTO settings, IrisE
return switch (type) {
case PROGRESS_STALLED -> {
if (settings.irisChatSettings().disabledProactiveEvents() != null) {
yield !settings.irisChatSettings().disabledProactiveEvents().contains(IrisEventType.PROGRESS_STALLED.getName());
yield !settings.irisChatSettings().disabledProactiveEvents().contains(IrisEventType.PROGRESS_STALLED.name().toLowerCase());
}
else {
yield true;
}
}
case BUILD_FAILED -> {
if (settings.irisChatSettings().disabledProactiveEvents() != null) {
yield !settings.irisChatSettings().disabledProactiveEvents().contains(IrisEventType.BUILD_FAILED.getName());
yield !settings.irisChatSettings().disabledProactiveEvents().contains(IrisEventType.BUILD_FAILED.name().toLowerCase());
}
else {
yield true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private Result createSubmission(ProgrammingExerciseStudentParticipation studentP
submission = submissionRepository.saveAndFlush(submission);

Result result = ParticipationFactory.generateResult(true, score);
result.setParticipation(studentParticipation);
result.setSubmission(submission);
result.completionDate(ZonedDateTime.now());
result.setAssessmentType(AssessmentType.AUTOMATIC);
Expand Down Expand Up @@ -259,7 +258,7 @@ public void handleEvent(IrisExerciseChatSessionService service) {
void testShouldNotFireProgressStalledEventWithEventDisabled() {
// Find settings for the current exercise
var settings = irisSettingsRepository.findExerciseSettings(exercise.getId()).orElseThrow();
settings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.getName())));
settings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.name().toLowerCase())));
irisSettingsRepository.save(settings);

createSubmissionWithScore(studentParticipation, 40);
Expand All @@ -273,7 +272,7 @@ void testShouldNotFireProgressStalledEventWithEventDisabled() {
void testShouldNotFireBuildFailedEventWhenEventSettingDisabled() {
// Find settings for the current exercise
var settings = irisSettingsRepository.findExerciseSettings(exercise.getId()).orElseThrow();
settings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.BUILD_FAILED.getName())));
settings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.BUILD_FAILED.name().toLowerCase())));
irisSettingsRepository.save(settings);

irisExerciseChatSessionService.createChatSessionForProgrammingExercise(exercise, userUtilService.getUserByLogin(TEST_PREFIX + "student1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ void updateProgrammingExerciseSettings4() throws Exception {
courseSettings.setIrisChatSettings(new IrisChatSubSettings());
courseSettings.getIrisChatSettings().setEnabled(true);
courseSettings.getIrisChatSettings().setSelectedVariant(null);
courseSettings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.getName())));
courseSettings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.name().toLowerCase())));

request.putWithResponseBody("/api/courses/" + course.getId() + "/raw-iris-settings", courseSettings, IrisSettings.class, HttpStatus.OK);
var loadedCourseSettings = request.get("/api/courses/" + course.getId() + "/raw-iris-settings", HttpStatus.OK, IrisSettings.class);
request.get("/api/courses/" + course.getId() + "/raw-iris-settings", HttpStatus.OK, IrisSettings.class);

programmingExercise = programmingExerciseRepository.findByIdElseThrow(programmingExercise.getId());

Expand All @@ -433,12 +433,12 @@ void updateProgrammingExerciseSettings4() throws Exception {
exerciseSettings.setIrisChatSettings(new IrisChatSubSettings());
exerciseSettings.getIrisChatSettings().setEnabled(true);
exerciseSettings.getIrisChatSettings().setSelectedVariant(null);
exerciseSettings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.BUILD_FAILED.getName())));
exerciseSettings.getIrisChatSettings().setDisabledProactiveEvents(new TreeSet<>(Set.of(IrisEventType.BUILD_FAILED.name().toLowerCase())));

request.putWithResponseBody("/api/exercises/" + programmingExercise.getId() + "/raw-iris-settings", exerciseSettings, IrisSettings.class, HttpStatus.OK);
var loadedExerciseSettings = request.get("/api/exercises/" + programmingExercise.getId() + "/iris-settings", HttpStatus.OK, IrisCombinedSettingsDTO.class);
// Combined settings should include the union of the disabled course events and disabled exercise events
assertThat(loadedExerciseSettings.irisChatSettings().disabledProactiveEvents()).isNotNull()
.isEqualTo(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.getName(), IrisEventType.BUILD_FAILED.getName())));
.isEqualTo(new TreeSet<>(Set.of(IrisEventType.PROGRESS_STALLED.name().toLowerCase(), IrisEventType.BUILD_FAILED.name().toLowerCase())));
}
}

0 comments on commit e66e0dc

Please sign in to comment.