From 047a5e9aef630076490ee9e4342bb43f26bc6f67 Mon Sep 17 00:00:00 2001 From: Ole Vester Date: Tue, 3 Dec 2024 12:33:12 +0100 Subject: [PATCH] Replace constructor arg type of api from String to Class --- .../migration/entries/MigrationEntry20240614_140000.java | 2 +- .../artemis/core/exception/ApiNotPresentException.java | 8 +++++--- .../artemis/iris/service/pyris/PyrisPipelineService.java | 2 +- .../tum/cit/aet/artemis/lecture/web/LectureResource.java | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/core/config/migration/entries/MigrationEntry20240614_140000.java b/src/main/java/de/tum/cit/aet/artemis/core/config/migration/entries/MigrationEntry20240614_140000.java index 9fe5db77603f..cf592937daa4 100644 --- a/src/main/java/de/tum/cit/aet/artemis/core/config/migration/entries/MigrationEntry20240614_140000.java +++ b/src/main/java/de/tum/cit/aet/artemis/core/config/migration/entries/MigrationEntry20240614_140000.java @@ -33,7 +33,7 @@ public void execute() { List 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); } diff --git a/src/main/java/de/tum/cit/aet/artemis/core/exception/ApiNotPresentException.java b/src/main/java/de/tum/cit/aet/artemis/core/exception/ApiNotPresentException.java index 80425a5f535c..97be39e564f4 100644 --- a/src/main/java/de/tum/cit/aet/artemis/core/exception/ApiNotPresentException.java +++ b/src/main/java/de/tum/cit/aet/artemis/core/exception/ApiNotPresentException.java @@ -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. @@ -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 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)); } } diff --git a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisPipelineService.java b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisPipelineService.java index 970714194d63..ec5115789c74 100644 --- a/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisPipelineService.java +++ b/src/main/java/de/tum/cit/aet/artemis/iris/service/pyris/PyrisPipelineService.java @@ -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", diff --git a/src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java b/src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java index 05e67061cf74..9b2301e41109 100644 --- a/src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java +++ b/src/main/java/de/tum/cit/aet/artemis/lecture/web/LectureResource.java @@ -306,7 +306,7 @@ public ResponseEntity ingestLectures(@PathVariable Long courseId, @Request public ResponseEntity 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(); @@ -336,7 +336,7 @@ public ResponseEntity 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);