Skip to content

Commit

Permalink
add ExternalSystemConfiguration to set basepath in application.proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
julianlxs committed Dec 31, 2024
1 parent e45d62e commit 19b6770
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.unistuttgart.iste.meitrex.assignment_service.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Getter
@Configuration
public class ExternalSystemConfiguration {

@Value("${external_system.authToken}")
private String authToken;

@Value("${external_system.url}")
private String basePath;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.unistuttgart.iste.meitrex.assignment_service.service;


import de.unistuttgart.iste.meitrex.assignment_service.config.ExternalSystemConfiguration;
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;
Expand Down Expand Up @@ -50,9 +51,8 @@ public class GradingService {
private final UserServiceClient userServiceClient;
private final CourseServiceClient courseServiceClient;

// these need to be set!
private static final String authToken = "";
private static final String basePath = "";
private final ExternalSystemConfiguration externalSystemConfiguration;


public Grading getGradingForAssignmentForStudent(final UUID assignmentId, final UUID studentId, final LoggedInUser currentUser) {
final AssignmentEntity assignment = assignmentService.requireAssignmentExists(assignmentId); // throws EntityNotFoundException "Assignment with assessmentId %s not found"
Expand Down Expand Up @@ -86,9 +86,9 @@ public void importGradingsForAssignment(final UUID assignmentId, final LoggedInU
String body;
CompletableFuture<String> response;
try (HttpClient client = HttpClient.newBuilder().build()) {
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(basePath + "api/grading/handIn/" + externalId))
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(externalSystemConfiguration.getBasePath() + "api/grading/handIn/" + externalId))
//.header("Authorization", "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes()))
.header("Cookie", "connect.sid=" + authToken)
.header("Cookie", "connect.sid=" + externalSystemConfiguration.getAuthToken())
.build();
response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(HttpResponse::body);
body = response.join();
Expand Down Expand Up @@ -337,9 +337,9 @@ private JSONObject getExternalStudentInfo(final String externalStudentId) throws
String body;
CompletableFuture<String> response;
try (HttpClient client = HttpClient.newBuilder().build()) {
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(basePath + "api/student/" + externalStudentId))
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(externalSystemConfiguration.getBasePath() + "api/student/" + externalStudentId))
//.header("Authorization", "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes()))
.header("Cookie", "connect.sid=" + authToken)
.header("Cookie", "connect.sid=" + externalSystemConfiguration.getAuthToken())
.build();
response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(HttpResponse::body);
body = response.join();
Expand Down Expand Up @@ -439,9 +439,9 @@ public List<ExternalAssignment> getExternalAssignments(final UUID courseId, fina
String body;
CompletableFuture<String> response;
try (HttpClient client = HttpClient.newBuilder().build()) {
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(basePath + "api/sheet"))
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(externalSystemConfiguration.getBasePath() + "api/sheet"))
//.header("Authorization", "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes()))
.header("Cookie", "connect.sid=" + authToken)
.header("Cookie", "connect.sid=" + externalSystemConfiguration.getAuthToken())
.build();
response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(HttpResponse::body);
body = response.join();
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ 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
user_service.url=http://localhost:5001/graphql

# URL base path for external system like TMS
external_system.url=http://localhost:1234/
external_system.authToken=""

0 comments on commit 19b6770

Please sign in to comment.