From 9e26017f9d8ff618907c1221872c99730ff9572a Mon Sep 17 00:00:00 2001 From: "julian.lxs" Date: Thu, 17 Oct 2024 16:06:49 +0200 Subject: [PATCH] add http setup, non-functional --- .../controller/AssignmentController.java | 1 + .../service/GradingService.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/controller/AssignmentController.java b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/controller/AssignmentController.java index 217e63b..0091adf 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/controller/AssignmentController.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/assignment_service/controller/AssignmentController.java @@ -52,6 +52,7 @@ public Grading getGradingForAssignmentForStudent(@Argument final UUID assessment public List getExternalAssignments(@Argument final UUID courseId, @ContextValue final LoggedInUser currentUser) { return gradingService.getExternalAssignments(courseId, currentUser); } + /* Mutation Mappings */ @MutationMapping(name = "_internal_noauth_createAssignment") 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 f570d4d..5abf567 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 @@ -15,8 +15,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.util.List; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse; @@ -49,7 +56,28 @@ public List getExternalAssignments(final UUID courseId, fina } catch (final NoAccessToCourseException ex) { return null; } + // get stuff from TMS here + + CompletableFuture response; + try (HttpClient client = HttpClient.newBuilder().authenticator(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication( + "username", + "password".toCharArray()); + } + }).build()) { + HttpRequest request = HttpRequest.newBuilder().uri(URI.create("")).build(); + response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(HttpResponse::body); + } + String body = response.join(); + List externalAssignments = this.parseStringIntoList(body); + + return externalAssignments; + } + + private List parseStringIntoList(final String string) { return null; }