-
Notifications
You must be signed in to change notification settings - Fork 350
Programming exercises: Notify active editors when new changes are saved by another user
#11712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elfari1028
wants to merge
14
commits into
develop
Choose a base branch
from
feature/exercise-synchronization/notify-active-editors-when-new-changes-are-saved
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,086
−96
Open
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c754804
Programming exercise: send notification to all active clients when on…
Elfari1028 9f86313
Development: Fix memory leaks and improve cleanup in programming exer…
Elfari1028 de67607
Programming exercise: Refactor synchronization service to move change…
Elfari1028 5599ffe
Merge branch 'develop' into feature/exercise-synchronization/notify-a…
Elfari1028 3a195c3
Programming exercise: Rename synchronization service and related clas…
Elfari1028 71ca8ba
Merge branch 'feature/exercise-synchronization/notify-active-editors-…
Elfari1028 1b2b20b
Programming exercise: Replace 'var' with explicit type declarations i…
Elfari1028 703c5f8
Merge branch 'develop' into feature/exercise-synchronization/notify-a…
Elfari1028 7ad2b7e
Merge branch 'develop' into feature/exercise-synchronization/notify-a…
Elfari1028 52b92f6
Merge branch 'develop' into feature/exercise-synchronization/notify-a…
Elfari1028 20ee3e2
Merge branch 'develop' into feature/exercise-synchronization/notify-a…
Elfari1028 9b329e7
Programming exercise: Fix test repository synchronization broadcast t…
Elfari1028 22a9401
Merge branch 'feature/exercise-synchronization/notify-active-editors-…
Elfari1028 3a8dc0d
Programming exercise: Remove unused method in auxiliary repository in…
Elfari1028 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/de/tum/cit/aet/artemis/programming/domain/SynchronizationTarget.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package de.tum.cit.aet.artemis.programming.domain; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public enum SynchronizationTarget { | ||
| PROBLEM_STATEMENT, TEMPLATE_REPOSITORY, SOLUTION_REPOSITORY, TESTS_REPOSITORY, AUXILIARY_REPOSITORY | ||
| } |
11 changes: 11 additions & 0 deletions
11
...in/java/de/tum/cit/aet/artemis/programming/dto/ProgrammingExerciseSynchronizationDTO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package de.tum.cit.aet.artemis.programming.dto; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
|
||
| import de.tum.cit.aet.artemis.programming.domain.SynchronizationTarget; | ||
|
|
||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public record ProgrammingExerciseSynchronizationDTO(SynchronizationTarget target, @Nullable Long auxiliaryRepositoryId, @Nullable String clientInstanceId) { | ||
| } |
66 changes: 66 additions & 0 deletions
66
...de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseSynchronizationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package de.tum.cit.aet.artemis.programming.service; | ||
|
|
||
| import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.context.annotation.Lazy; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.context.request.RequestAttributes; | ||
| import org.springframework.web.context.request.RequestContextHolder; | ||
| import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
|
||
| import de.tum.cit.aet.artemis.communication.service.WebsocketMessagingService; | ||
| import de.tum.cit.aet.artemis.programming.domain.SynchronizationTarget; | ||
| import de.tum.cit.aet.artemis.programming.dto.ProgrammingExerciseSynchronizationDTO; | ||
|
|
||
| @Profile(PROFILE_CORE) | ||
| @Lazy | ||
| @Service | ||
| public class ProgrammingExerciseSynchronizationService { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(ProgrammingExerciseSynchronizationService.class); | ||
|
|
||
| public static final String CLIENT_INSTANCE_HEADER = "X-Artemis-Client-Instance-ID"; | ||
|
|
||
| private final WebsocketMessagingService websocketMessagingService; | ||
|
|
||
| public ProgrammingExerciseSynchronizationService(WebsocketMessagingService websocketMessagingService) { | ||
| this.websocketMessagingService = websocketMessagingService; | ||
| } | ||
|
|
||
| public static String getSynchronizationTopic(long exerciseId) { | ||
| return "/topic/programming-exercises/" + exerciseId + "/synchronization"; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the client instance id from the current request, if available. | ||
| * | ||
| * @return the client instance id or null if no request context is available | ||
| */ | ||
| public static String getClientInstanceId() { | ||
| RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); | ||
| if (attributes instanceof ServletRequestAttributes servletRequestAttributes) { | ||
| return servletRequestAttributes.getRequest().getHeader(CLIENT_INSTANCE_HEADER); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Broadcast a single change to all active editors. | ||
| * | ||
| * @param exerciseId the exercise id | ||
| * @param target the target data type associated with this change (e.g. template repository, solution repository, auxiliary repository, problem statement) | ||
| * @param auxiliaryRepositoryId (optional) the id of the auxiliary repository associated with this change | ||
| */ | ||
| public void broadcastChange(long exerciseId, SynchronizationTarget target, @Nullable Long auxiliaryRepositoryId) { | ||
| var payload = new ProgrammingExerciseSynchronizationDTO(target, auxiliaryRepositoryId, getClientInstanceId()); | ||
| websocketMessagingService.sendMessage(getSynchronizationTopic(exerciseId), payload).exceptionally(exception -> { | ||
| log.warn("Cannot send synchronization message for exercise {}", exerciseId, exception); | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.