Skip to content

Commit

Permalink
Replace constructor arg type of api from String to Class
Browse files Browse the repository at this point in the history
  • Loading branch information
ole-ve committed Dec 3, 2024
1 parent 9e0a4d9 commit 047a5e9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void execute() {
List<Course> activeCourses = courseRepository.findAllActiveWithoutTestCourses(ZonedDateTime.now());

log.info("Updating competency progress for {} active courses", activeCourses.size());
var api = competencyProgressApi.orElseThrow(() -> new ApiNotPresentException("competencyProgressApi", PROFILE_ATLAS));
var api = competencyProgressApi.orElseThrow(() -> new ApiNotPresentException(CompetencyProgressApi.class, PROFILE_ATLAS));
api.updateProgressForCoursesAsync(activeCourses);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.cit.aet.artemis.core.exception;

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

/**
* Exception that an optionally autowired API is not present.
* This is caused by Spring profiles not being present.
Expand All @@ -9,10 +11,10 @@ public class ApiNotPresentException extends RuntimeException {
/**
* Constructor.
*
* @param api name of the api class
* @param api the api class that should be present
* @param profile name of the Spring profile that needs to be enabled.
*/
public ApiNotPresentException(String api, String profile) {
super(String.format("Api %s is not enabled, because Spring profile %s is not enabled. Did you enable it?", api, profile));
public ApiNotPresentException(Class<? extends AbstractApi> api, String profile) {
super(String.format("Api %s is not enabled, because Spring profile %s is not enabled. Did you enable it?", api.getName(), profile));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void executeCourseChatPipeline(String variant, IrisCourseChatSession sess
// @formatter:off
var courseId = session.getCourse().getId();
var studentId = session.getUser().getId();
var api = learningMetricsApi.orElseThrow(() -> new ApiNotPresentException("learningMetricsApi", PROFILE_ATLAS));
var api = learningMetricsApi.orElseThrow(() -> new ApiNotPresentException(LearningMetricsApi.class, PROFILE_ATLAS));

executePipeline(
"course-chat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public ResponseEntity<Void> ingestLectures(@PathVariable Long courseId, @Request
public ResponseEntity<Lecture> getLectureWithDetails(@PathVariable Long lectureId) {
log.debug("REST request to get lecture {} with details", lectureId);
Lecture lecture = lectureRepository.findByIdWithAttachmentsAndPostsAndLectureUnitsAndCompetenciesAndCompletionsElseThrow(lectureId);
competencyApi.orElseThrow(() -> new ApiNotPresentException("competencyApi", PROFILE_ATLAS)).addCompetencyLinksToExerciseUnits(lecture);
competencyApi.orElseThrow(() -> new ApiNotPresentException(CompetencyApi.class, PROFILE_ATLAS)).addCompetencyLinksToExerciseUnits(lecture);
Course course = lecture.getCourse();
if (course == null) {
return ResponseEntity.badRequest().build();
Expand Down Expand Up @@ -336,7 +336,7 @@ public ResponseEntity<Lecture> getLectureWithDetailsAndSlides(@PathVariable long
User user = userRepository.getUserWithGroupsAndAuthorities();
authCheckService.checkIsAllowedToSeeLectureElseThrow(lecture, user);

competencyApi.orElseThrow(() -> new ApiNotPresentException("competencyApi", PROFILE_ATLAS)).addCompetencyLinksToExerciseUnits(lecture);
competencyApi.orElseThrow(() -> new ApiNotPresentException(CompetencyApi.class, PROFILE_ATLAS)).addCompetencyLinksToExerciseUnits(lecture);
lectureService.filterActiveAttachmentUnits(lecture);
lectureService.filterActiveAttachments(lecture, user);
return ResponseEntity.ok(lecture);
Expand Down

0 comments on commit 047a5e9

Please sign in to comment.