diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/CourseServiceClientConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/CourseServiceClientConfiguration.java new file mode 100644 index 0000000..bf00e79 --- /dev/null +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/CourseServiceClientConfiguration.java @@ -0,0 +1,23 @@ +package de.unistuttgart.iste.meitrex.assignment_service.config; + + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.graphql.client.GraphQlClient; +import org.springframework.graphql.client.HttpGraphQlClient; +import org.springframework.web.reactive.function.client.WebClient; + +@Configuration +public class CourseServiceClientConfiguration { + + @Value("${course_service.url}") + private String courseServiceUrl; + + @Bean + public CourseServiceClient courseServiceClient() { + final WebClient webClient = WebClient.builder().baseUrl(courseServiceUrl).build(); + final GraphQlClient graphQlClient = HttpGraphQlClient.builder(webClient).build(); + return new CourseServiceClient(graphQlClient); + } +} diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/UserServiceClientConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/UserServiceClientConfiguration.java index 8a8f632..244f0a8 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/UserServiceClientConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/config/UserServiceClientConfiguration.java @@ -14,8 +14,9 @@ public class UserServiceClientConfiguration { private String userServiceUrl; @Bean - public GraphQlClient userServiceClient() { + public UserServiceClient userServiceClient() { final WebClient webClient = WebClient.builder().baseUrl(userServiceUrl).build(); - return HttpGraphQlClient.builder(webClient).build(); + final GraphQlClient graphQlClient = HttpGraphQlClient.builder(webClient).build(); + return new UserServiceClient(graphQlClient); } } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/service/GradingService.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/service/GradingService.java index 8a4820a..4dd9349 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/service/GradingService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/service/GradingService.java @@ -4,6 +4,7 @@ import de.unistuttgart.iste.meitrex.assignment_service.exception.ExternalPlatformConnectionException; import de.unistuttgart.iste.meitrex.assignment_service.exception.ManualMappingRequiredException; import de.unistuttgart.iste.meitrex.user_service.exception.UserServiceConnectionException; +import de.unistuttgart.iste.meitrex.course_service.exception.CourseServiceConnectionException; import de.unistuttgart.iste.meitrex.assignment_service.persistence.entity.*; import de.unistuttgart.iste.meitrex.assignment_service.persistence.mapper.AssignmentMapper; import de.unistuttgart.iste.meitrex.assignment_service.persistence.repository.GradingRepository; @@ -103,7 +104,7 @@ public void importGradingsForAssignment(final UUID assignmentId, final LoggedInU final List meitrexStudentInfoList; try { meitrexStudentInfoList = getMeitrexStudentInfoList(); - } catch (UserServiceConnectionException e){ + } catch (UserServiceConnectionException | CourseServiceConnectionException e){ throw new RuntimeException(e); // wrapping exception // return; TODO return or throw wrapped exception? } @@ -349,12 +350,10 @@ private JSONObject getExternalStudentInfo(final String externalStudentId) throws return new JSONObject(body); } + private List getMeitrexStudentInfoList() throws UserServiceConnectionException, CourseServiceConnectionException { - // TODO this whole thing should be in userService rather than here - private List getMeitrexStudentInfoList() throws UserServiceConnectionException { - - final List userIds = courseServiceClient.queryUserIds(); // TODO needs to be queried from course service - + final List userMemberships = courseServiceClient.queryMembershipsInCourse(); + List userIds = userMemberships.stream().map(CourseMembership::getUserId).toList(); final List meitrexStudentInfoList = userServiceClient.queryUserInfos(userIds); return meitrexStudentInfoList; @@ -383,7 +382,7 @@ public List saveStudentMappings(final UUID courseId, final List meitrexStudentInfoList; try { meitrexStudentInfoList = getMeitrexStudentInfoList(); - } catch (UserServiceConnectionException e){ + } catch (UserServiceConnectionException | CourseServiceConnectionException e){ throw new RuntimeException(e); // wrapping exception // return null; TODO return null or throw wrapped exception? } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b675667..b408e58 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -15,4 +15,8 @@ server.max-http-request-header-size=64000 # enable probing used by kubernetes management.endpoint.health.probes.enabled=true management.health.livenessstate.enabled=true -management.health.readinessState.enabled=true \ No newline at end of file +management.health.readinessState.enabled=true + +# URLs for course and user service +course_service.url=http://localhost:2001/graphql +user_service.url=http://localhost:5001/graphql \ No newline at end of file