Skip to content
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

Development: Introduce module API for Atlas #9752

Merged
merged 15 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import de.tum.cit.aet.artemis.assessment.repository.ResultRepository;
import de.tum.cit.aet.artemis.assessment.repository.StudentScoreRepository;
import de.tum.cit.aet.artemis.assessment.repository.TeamScoreRepository;
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyProgressService;
import de.tum.cit.aet.artemis.atlas.api.CompetencyProgressApi;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.repository.UserRepository;
import de.tum.cit.aet.artemis.core.security.SecurityUtils;
Expand Down Expand Up @@ -74,7 +74,7 @@ public class ParticipantScoreScheduleService {

private Optional<Instant> lastScheduledRun = Optional.empty();

private final CompetencyProgressService competencyProgressService;
private final CompetencyProgressApi competencyProgressApi;

private final ParticipantScoreRepository participantScoreRepository;

Expand All @@ -96,11 +96,11 @@ public class ParticipantScoreScheduleService {
*/
private final AtomicBoolean isRunning = new AtomicBoolean(false);

public ParticipantScoreScheduleService(@Qualifier("taskScheduler") TaskScheduler scheduler, CompetencyProgressService competencyProgressService,
public ParticipantScoreScheduleService(@Qualifier("taskScheduler") TaskScheduler scheduler, CompetencyProgressApi competencyProgressApi,
ParticipantScoreRepository participantScoreRepository, StudentScoreRepository studentScoreRepository, TeamScoreRepository teamScoreRepository,
ExerciseRepository exerciseRepository, ResultRepository resultRepository, UserRepository userRepository, TeamRepository teamRepository) {
this.scheduler = scheduler;
this.competencyProgressService = competencyProgressService;
this.competencyProgressApi = competencyProgressApi;
this.participantScoreRepository = participantScoreRepository;
this.studentScoreRepository = studentScoreRepository;
this.teamScoreRepository = teamScoreRepository;
Expand Down Expand Up @@ -336,7 +336,7 @@ private void executeTask(Long exerciseId, Long participantId, Instant resultLast
if (scoreParticipant instanceof Team team && !Hibernate.isInitialized(team.getStudents())) {
scoreParticipant = teamRepository.findWithStudentsByIdElseThrow(team.getId());
}
competencyProgressService.updateProgressByLearningObjectSync(score.getExercise(), scoreParticipant.getParticipants());
competencyProgressApi.updateProgressByLearningObjectSync(score.getExercise(), scoreParticipant.getParticipants());
}
catch (Exception e) {
log.error("Exception while processing participant score for exercise {} and participant {} for participant scores:", exerciseId, participantId, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.tum.cit.aet.artemis.atlas.api;

import de.tum.cit.aet.artemis.core.api.AbstractApi;

public abstract class AbstractAtlasApi implements AbstractApi {
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyService;
import de.tum.cit.aet.artemis.lecture.domain.Lecture;

@Controller
@Profile(PROFILE_CORE)
public class CompetencyApi extends AbstractAtlasApi {
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

private final CompetencyService competencyService;

public CompetencyApi(CompetencyService competencyService) {
this.competencyService = competencyService;
}

public void addCompetencyLinksToExerciseUnits(Lecture lecture) {
competencyService.addCompetencyLinksToExerciseUnits(lecture);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 org.springframework.context.annotation.Profile;
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;

@Controller
@Profile(PROFILE_CORE)
public class CompetencyProgressApi extends AbstractAtlasApi {
ole-ve marked this conversation as resolved.
Show resolved Hide resolved

private final CompetencyProgressService competencyProgressService;

private final CompetencyRepository competencyRepository;

public CompetencyProgressApi(CompetencyProgressService competencyProgressService, CompetencyRepository competencyRepository) {
this.competencyProgressService = competencyProgressService;
this.competencyRepository = competencyRepository;
}

public void updateProgressByLearningObjectForParticipantAsync(LearningObject learningObject, Participant participant) {
competencyProgressService.updateProgressByLearningObjectForParticipantAsync(learningObject, participant);
}

public void updateProgressByLearningObjectAsync(LearningObject learningObject) {
competencyProgressService.updateProgressByLearningObjectAsync(learningObject);
}

public void updateProgressByCompetencyAsync(CourseCompetency competency) {
competencyProgressService.updateProgressByCompetencyAsync(competency);
}

public void updateProgressForUpdatedLearningObjectAsync(LearningObject originalLearningObject, Optional<LearningObject> updatedLearningObject) {
competencyProgressService.updateProgressForUpdatedLearningObjectAsync(originalLearningObject, updatedLearningObject);
}

public void updateProgressByLearningObjectSync(LearningObject learningObject, Set<User> users) {
competencyProgressService.updateProgressByLearningObjectSync(learningObject, users);
}

public long countByCourse(Course course) {
return competencyRepository.countByCourse(course);
}

public void deleteAll(Set<Competency> competencies) {
competencyRepository.deleteAll(competencies);
}

/**
* Updates the progress for all competencies of the given courses.
*
* @param activeCourses the active courses
*/
public void updateProgressForCoursesAsync(List<Course> activeCourses) {
activeCourses.forEach(course -> {
List<Competency> competencies = competencyRepository.findByCourseIdOrderById(course.getId());
// Asynchronously update the progress for each competency
competencies.forEach(competencyProgressService::updateProgressByCompetencyAsync);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyExerciseLink;
import de.tum.cit.aet.artemis.atlas.domain.competency.CompetencyLectureUnitLink;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyExerciseLinkRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyLectureUnitLinkRepository;
import de.tum.cit.aet.artemis.atlas.repository.CompetencyRelationRepository;

@Controller
@Profile(PROFILE_CORE)
public class CompetencyRelationApi extends AbstractAtlasApi {

private final CompetencyRelationRepository competencyRelationRepository;

private final CompetencyExerciseLinkRepository competencyExerciseLinkRepository;

private final CompetencyLectureUnitLinkRepository lectureUnitLinkRepository;

public CompetencyRelationApi(CompetencyRelationRepository competencyRelationRepository, CompetencyExerciseLinkRepository competencyExerciseLinkRepository,
CompetencyLectureUnitLinkRepository lectureUnitLinkRepository) {
this.competencyRelationRepository = competencyRelationRepository;
this.competencyExerciseLinkRepository = competencyExerciseLinkRepository;
this.lectureUnitLinkRepository = lectureUnitLinkRepository;
}

public void deleteAllByCourseId(Long courseId) {
competencyRelationRepository.deleteAllByCourseId(courseId);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

public void deleteAllExerciseLinks(Iterable<CompetencyExerciseLink> competencyExerciseLinks) {
competencyExerciseLinkRepository.deleteAll(competencyExerciseLinks);
}

public List<CompetencyExerciseLink> saveAllExerciseLinks(Iterable<CompetencyExerciseLink> competencyExerciseLinks) {
return competencyExerciseLinkRepository.saveAll(competencyExerciseLinks);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

public List<CompetencyLectureUnitLink> saveAllLectureUnitLinks(Iterable<CompetencyLectureUnitLink> lectureUnitLinks) {
return lectureUnitLinkRepository.saveAll(lectureUnitLinks);
}

public void deleteAllLectureUnitLinks(Iterable<CompetencyLectureUnitLink> lectureUnitLinks) {
lectureUnitLinkRepository.deleteAll(lectureUnitLinks);
}

public void deleteAllLectureUnitLinksByLectureId(Long lectureId) {
lectureUnitLinkRepository.deleteAllByLectureId(lectureId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.domain.competency.CourseCompetency;
import de.tum.cit.aet.artemis.atlas.repository.CourseCompetencyRepository;

@Controller
@Profile(PROFILE_CORE)
public class CourseCompetencyApi extends AbstractAtlasApi {
ole-ve marked this conversation as resolved.
Show resolved Hide resolved

private final CourseCompetencyRepository courseCompetencyRepository;

public CourseCompetencyApi(CourseCompetencyRepository courseCompetencyRepository) {
this.courseCompetencyRepository = courseCompetencyRepository;
}

public void save(CourseCompetency courseCompetency) {
courseCompetencyRepository.save(courseCompetency);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.dto.metrics.StudentMetricsDTO;
import de.tum.cit.aet.artemis.atlas.service.LearningMetricsService;

@Controller
@Profile(PROFILE_CORE)
public class LearningMetricsApi extends AbstractAtlasApi {

private final LearningMetricsService metricsService;

public LearningMetricsApi(LearningMetricsService metricsService) {
this.metricsService = metricsService;
}

public StudentMetricsDTO getStudentCourseMetrics(long userId, long courseId) {
return metricsService.getStudentCourseMetrics(userId, courseId);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import jakarta.validation.constraints.NotNull;

import org.springframework.context.annotation.Profile;
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;

@Controller
@Profile(PROFILE_CORE)
public class LearningPathApi extends AbstractAtlasApi {

private final LearningPathService learningPathService;

public LearningPathApi(LearningPathService learningPathService) {
this.learningPathService = learningPathService;
}

public void generateLearningPathForUser(@NotNull Course course, @NotNull User user) {
learningPathService.generateLearningPathForUser(course, user);
}

public void generateLearningPaths(@NotNull Course course) {
learningPathService.generateLearningPaths(course);
}
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.domain.competency.Prerequisite;
import de.tum.cit.aet.artemis.atlas.repository.PrerequisiteRepository;
import de.tum.cit.aet.artemis.core.domain.Course;

@Controller
@Profile(PROFILE_CORE)
public class PrerequisitesApi extends AbstractAtlasApi {

private final PrerequisiteRepository prerequisiteRepository;

public PrerequisitesApi(PrerequisiteRepository prerequisiteRepository) {
this.prerequisiteRepository = prerequisiteRepository;
}

public long countByCourse(Course course) {
return prerequisiteRepository.countByCourse(course);
}

public void deleteAll(Iterable<Prerequisite> prerequisites) {
prerequisiteRepository.deleteAll(prerequisites);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.tum.cit.aet.artemis.atlas.api;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.Set;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import de.tum.cit.aet.artemis.atlas.domain.science.ScienceEvent;
import de.tum.cit.aet.artemis.atlas.repository.ScienceEventRepository;

@Controller
@Profile(PROFILE_CORE)
public class ScienceEventApi extends AbstractAtlasApi {
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

private final ScienceEventRepository scienceEventRepository;

public ScienceEventApi(ScienceEventRepository scienceEventRepository) {
this.scienceEventRepository = scienceEventRepository;
}

public Set<ScienceEvent> findAllByIdentity(String login) {
return scienceEventRepository.findAllByIdentity(login);
}
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

public void renameIdentity(String oldIdentity, String newIdentity) {
scienceEventRepository.renameIdentity(oldIdentity, newIdentity);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tum.cit.aet.artemis.exercise.service;
package de.tum.cit.aet.artemis.atlas.service;

import static de.tum.cit.aet.artemis.core.config.Constants.MIN_SCORE_GREEN;
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.springframework.web.bind.annotation.RestController;

import de.tum.cit.aet.artemis.atlas.dto.metrics.StudentMetricsDTO;
import de.tum.cit.aet.artemis.atlas.service.LearningMetricsService;
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved
import de.tum.cit.aet.artemis.core.repository.UserRepository;
import de.tum.cit.aet.artemis.core.security.annotations.enforceRoleInCourse.EnforceAtLeastStudentInCourse;
import de.tum.cit.aet.artemis.exercise.service.LearningMetricsService;

@Profile(PROFILE_CORE)
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.tum.cit.aet.artemis.core.api;

public interface AbstractApi {
ole-ve marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading