-
Notifications
You must be signed in to change notification settings - Fork 319
Development
: Introduce module-API for Atlas
#9486
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
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d3bb5e5
Add common AbstractApi
ole-ve 152af19
Add PROFILE_ATLAS constant
ole-ve dc1dbab
Move atlas db config to atlas module
ole-ve 76c4b38
Add atlas API classes and use it in every other module
ole-ve 1db7e34
Add exemplary arch tests for api access, inheritance, and annotation
ole-ve ce7853d
Typo
ole-ve 8350776
Thanks to the ArchTests
ole-ve 786324d
Add missing classes
ole-ve 1a10cdc
Revert "Thanks to the ArchTests"
ole-ve 3b93050
checkstyleMain
ole-ve 6de84ef
Annotate module api controllers with Spring profile
ole-ve 7b54e04
Annotate atlas module config with Spring profile
ole-ve ead9d20
Change visibility of AtlasApiArchitectureTest to package-private
ole-ve 7fda208
Change constructor visibility of some atlas apis to public
ole-ve d41f968
Avoid re-assigning variables in lambda expression
ole-ve 8561759
Improve module arch test method names
ole-ve a8f0cc0
Fix logic of determining disabled profiles
ole-ve bf2dd86
Temporarily use PROFILE_CORE to verify getOrThrow
ole-ve 755f3be
Use competencyProgressApi in spy-verification (in non-atlas tests)
ole-ve 23f7a0d
Merge branch 'develop' into chore/atlas-java-api
ole-ve 763afc1
Make updateProgressForCourses ignore module not present
ole-ve 2f3c744
Merge branch 'develop' into chore/atlas-java-api
ole-ve 90711b6
Merge branch 'develop' into chore/atlas-java-api
ole-ve 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
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
14 changes: 14 additions & 0 deletions
14
src/main/java/de/tum/cit/aet/artemis/atlas/api/AbstractAtlasApi.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,14 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_ATLAS; | ||
|
||
import org.springframework.core.env.Environment; | ||
|
||
import de.tum.cit.aet.artemis.core.api.AbstractApi; | ||
|
||
public abstract class AbstractAtlasApi extends AbstractApi { | ||
|
||
protected AbstractAtlasApi(Environment environment) { | ||
super(environment, PROFILE_ATLAS); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/de/tum/cit/aet/artemis/atlas/api/CompetencyProgressApi.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,77 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.LearningObject; | ||
import de.tum.cit.aet.artemis.atlas.domain.competency.Competency; | ||
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency; | ||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; | ||
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyProgressService; | ||
import de.tum.cit.aet.artemis.core.domain.Course; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
import de.tum.cit.aet.artemis.exercise.domain.participation.Participant; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Controller | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public class CompetencyProgressApi extends AbstractAtlasApi { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Optional<CompetencyProgressService> competencyProgressService; | ||
|
||
private final Optional<CompetencyRepository> competencyRepository; | ||
|
||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public CompetencyProgressApi(Environment environment, Optional<CompetencyProgressService> competencyProgressService, Optional<CompetencyRepository> competencyRepository) { | ||
super(environment); | ||
this.competencyProgressService = competencyProgressService; | ||
this.competencyRepository = competencyRepository; | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void updateProgressByLearningObjectForParticipantAsync(LearningObject learningObject, @NotNull Participant participant) { | ||
competencyProgressService.ifPresent(service -> service.updateProgressByLearningObjectForParticipantAsync(learningObject, participant)); | ||
JohannesStoehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public void updateProgressByLearningObjectAsync(LearningObject learningObject) { | ||
competencyProgressService.ifPresent(service -> service.updateProgressByLearningObjectAsync(learningObject)); | ||
} | ||
|
||
public void updateProgressByCompetencyAsync(CourseCompetency competency) { | ||
competencyProgressService.ifPresent(service -> service.updateProgressByCompetencyAsync(competency)); | ||
} | ||
|
||
public void updateProgressForUpdatedLearningObjectAsync(LearningObject originalLearningObject, Optional<LearningObject> updatedLearningObject) { | ||
competencyProgressService.ifPresent(service -> service.updateProgressForUpdatedLearningObjectAsync(originalLearningObject, updatedLearningObject)); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void updateProgressByLearningObjectSync(LearningObject learningObject, Set<User> users) { | ||
competencyProgressService.ifPresent(service -> service.updateProgressByLearningObjectSync(learningObject, users)); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Updates the progress for all competencies of the given courses. | ||
* | ||
* @param activeCourses the active courses | ||
*/ | ||
public void updateProgressForCourses(List<Course> activeCourses) { | ||
if (!isActive()) { | ||
return; | ||
} | ||
|
||
CompetencyProgressService competencyProgressService = getOrThrow(this.competencyProgressService); | ||
CompetencyRepository competencyRepository = getOrThrow(this.competencyRepository); | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
JohannesStoehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
activeCourses.forEach(course -> { | ||
List<Competency> competencies = competencyRepository.findByCourseIdOrderById(course.getId()); | ||
// Asynchronously update the progress for each competency | ||
competencies.forEach(competencyProgressService::updateProgressByCompetencyAsync); | ||
}); | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/de/tum/cit/aet/artemis/atlas/api/CourseCompetencyApi.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,78 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency; | ||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRelationRepository; | ||
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRepository; | ||
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository; | ||
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository; | ||
import de.tum.cit.aet.artemis.core.domain.Course; | ||
import de.tum.cit.aet.artemis.lecture.domain.ExerciseUnit; | ||
import de.tum.cit.aet.artemis.lecture.domain.LectureUnit; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Controller | ||
public class CourseCompetencyApi extends AbstractAtlasApi { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Optional<CourseCompetencyRepository> optionalCourseCompetencyRepository; | ||
|
||
private final Optional<CompetencyRelationRepository> optionalCompetencyRelationRepository; | ||
|
||
private final Optional<PrerequisiteRepository> optionalPrerequisitesRepository; | ||
|
||
private final Optional<CompetencyRepository> optionalCompetencyRepository; | ||
|
||
public CourseCompetencyApi(Environment environment, Optional<CourseCompetencyRepository> optionalCourseCompetencyRepository, | ||
Optional<CompetencyRelationRepository> optionalCompetencyRelationRepository, Optional<PrerequisiteRepository> optionalPrerequisitesRepository, | ||
Optional<CompetencyRepository> optionalCompetencyRepository) { | ||
super(environment); | ||
this.optionalCourseCompetencyRepository = optionalCourseCompetencyRepository; | ||
this.optionalCompetencyRelationRepository = optionalCompetencyRelationRepository; | ||
this.optionalPrerequisitesRepository = optionalPrerequisitesRepository; | ||
this.optionalCompetencyRepository = optionalCompetencyRepository; | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void findAndSetCompetenciesForCourse(Course course) { | ||
optionalCompetencyRepository.ifPresent(service -> course.setNumberOfCompetencies(service.countByCourse(course))); | ||
optionalPrerequisitesRepository.ifPresent(service -> course.setNumberOfPrerequisites(service.countByCourse(course))); | ||
} | ||
|
||
public void deleteCompetenciesOfCourse(Course course) { | ||
optionalCompetencyRelationRepository.ifPresent(service -> service.deleteAllByCourseId(course.getId())); | ||
optionalPrerequisitesRepository.ifPresent(service -> service.deleteAll(course.getPrerequisites())); | ||
optionalCompetencyRepository.ifPresent(service -> service.deleteAll(course.getCompetencies())); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* ToDo: Consider moving to service | ||
* Deletes the competencies associated with the given lecture unit. | ||
* | ||
* @param lectureUnit the lecture unit | ||
*/ | ||
public void deleteCompetencyOfLectureUnit(@NotNull LectureUnit lectureUnit) { | ||
if (optionalCourseCompetencyRepository.isEmpty()) { | ||
return; | ||
} | ||
|
||
CourseCompetencyRepository repository = optionalCourseCompetencyRepository.get(); | ||
if (!(lectureUnit instanceof ExerciseUnit)) { | ||
// update associated competencies | ||
Set<CourseCompetency> competencies = lectureUnit.getCompetencies(); | ||
repository.saveAll(competencies.stream().map(competency -> { | ||
CourseCompetency updatedCompetency = repository.findByIdWithLectureUnitsElseThrow(competency.getId()); | ||
updatedCompetency.getLectureUnits().remove(lectureUnit); | ||
return updatedCompetency; | ||
}).toList()); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/de/tum/cit/aet/artemis/atlas/api/LearningMetricsApi.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,28 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import de.tum.cit.aet.artemis.atlas.dto.metrics.StudentMetricsDTO; | ||
import de.tum.cit.aet.artemis.atlas.service.LearningMetricsService; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Controller | ||
public class LearningMetricsApi extends AbstractAtlasApi { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Optional<LearningMetricsService> learningMetricsService; | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public LearningMetricsApi(Environment environment, Optional<LearningMetricsService> learningMetricsService) { | ||
super(environment); | ||
this.learningMetricsService = learningMetricsService; | ||
} | ||
|
||
public StudentMetricsDTO getStudentCourseMetrics(long userId, long courseId) { | ||
return getOrThrow(learningMetricsService).getStudentCourseMetrics(userId, courseId); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/de/tum/cit/aet/artemis/atlas/api/LearningPathApi.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,35 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import de.tum.cit.aet.artemis.atlas.service.learningpath.LearningPathService; | ||
import de.tum.cit.aet.artemis.core.domain.Course; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Controller | ||
public class LearningPathApi extends AbstractAtlasApi { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Optional<LearningPathService> optionalLearningPathService; | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public LearningPathApi(Environment environment, Optional<LearningPathService> optionalLearningPathService) { | ||
super(environment); | ||
this.optionalLearningPathService = optionalLearningPathService; | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void generateLearningPathForUser(@NotNull Course course, @NotNull User user) { | ||
optionalLearningPathService.ifPresent(service -> service.generateLearningPathForUser(course, user)); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void generateLearningPaths(@NotNull Course course) { | ||
optionalLearningPathService.ifPresent(service -> service.generateLearningPaths(course)); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/de/tum/cit/aet/artemis/atlas/api/ScienceEventApi.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,33 @@ | ||
package de.tum.cit.aet.artemis.atlas.api; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEvent; | ||
import de.tum.cit.aet.artemis.atlas.repository.ScienceEventRepository; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Controller | ||
public class ScienceEventApi extends AbstractAtlasApi { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Optional<ScienceEventRepository> scienceEventRepository; | ||
|
||
public ScienceEventApi(Environment environment, Optional<ScienceEventRepository> scienceEventRepository) { | ||
super(environment); | ||
this.scienceEventRepository = scienceEventRepository; | ||
} | ||
|
||
public Set<ScienceEvent> findAllByIdentity(String login) { | ||
return getOrThrow(scienceEventRepository).findAllByIdentity(login); | ||
} | ||
|
||
public void renameIdentity(String oldIdentity, String newIdentity) { | ||
scienceEventRepository.ifPresent(repository -> repository.renameIdentity(oldIdentity, newIdentity)); | ||
} | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/de/tum/cit/aet/artemis/atlas/config/AtlasConfig.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,35 @@ | ||
package de.tum.cit.aet.artemis.atlas.config; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.env.Profiles; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
import de.tum.cit.aet.artemis.core.config.AbstractModuleConfig; | ||
import de.tum.cit.aet.artemis.core.config.DatabaseConfiguration; | ||
import de.tum.cit.aet.artemis.core.repository.base.RepositoryImpl; | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Profile(PROFILE_CORE) // in the future, we will switch to PROFILE_ATLAS | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Configuration | ||
public class AtlasConfig extends AbstractModuleConfig { | ||
|
||
/** | ||
* Crucially required profiles for which - if not enabled - renders Atlas useless. | ||
*/ | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final Set<Profiles> requiredProfiles = Set.of(Profiles.of(PROFILE_CORE)); | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public AtlasConfig(Environment environment) { | ||
super(environment, requiredProfiles); | ||
} | ||
|
||
@Profile(PROFILE_CORE) | ||
@Configuration | ||
@EnableJpaRepositories(basePackages = { "de.tum.cit.aet.artemis.atlas.repository" }, repositoryBaseClass = RepositoryImpl.class) | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static class AtlasDatabaseConfig extends DatabaseConfiguration { | ||
ole-ve marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...rcise/service/LearningMetricsService.java → ...atlas/service/LearningMetricsService.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
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.