From e364ba38c118f379c92b0e9e573426d85d09d472 Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Mon, 4 Nov 2024 15:33:12 +0100 Subject: [PATCH] Proxy association endpoint also for GET --- .../java/generiek/api/EnrollmentEndpoint.java | 23 ++++++++++++++----- .../generiek/api/EnrollmentEndpointTest.java | 16 +++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/main/java/generiek/api/EnrollmentEndpoint.java b/src/main/java/generiek/api/EnrollmentEndpoint.java index 4d9cfb0..4fad4fe 100644 --- a/src/main/java/generiek/api/EnrollmentEndpoint.java +++ b/src/main/java/generiek/api/EnrollmentEndpoint.java @@ -44,10 +44,7 @@ import java.net.URI; import java.net.URLEncoder; import java.text.ParseException; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -362,6 +359,19 @@ public ResponseEntity> associate(@PathVariable("personId") S @PatchMapping("/associations/{associationId}") public ResponseEntity> associationUpdate(@PathVariable("associationId") String associationId, @RequestBody Map association) { + return doAssociationUpdate(associationId, Optional.of(association)); + } + + /* + * Called by the SIS of the guest institution to inform the home institution of the status of the (pending) + * enrollment + */ + @GetMapping("/associations/{associationId}") + public ResponseEntity> associationUpdateGet(@PathVariable("associationId") String associationId) { + return doAssociationUpdate(associationId, Optional.empty()); + } + + private ResponseEntity> doAssociationUpdate(String associationId, Optional> association) { EnrollmentRequest enrollmentRequest = associationRepository.findByAssociationId(associationId) .orElseThrow(ExpiredEnrollmentRequestException::new).getEnrollmentRequest(); @@ -375,8 +385,9 @@ public ResponseEntity> associationUpdate(@PathVariable("asso } LOG.debug(String.format("Patching association endpoint for enrolment request %s to %s", enrollmentRequest, associationURI)); - Map body = EnrollmentAssociation.transform(association, enrollmentRequest); - return exchangeToHomeInstitution(enrollmentRequest, body, associationURI, HttpMethod.PATCH, false, true); + Map body = association.map(ass -> EnrollmentAssociation.transform(ass, enrollmentRequest)).orElse(null) ; + HttpMethod httpMethod = association.map(ass -> HttpMethod.PATCH).orElse(HttpMethod.GET) ; + return exchangeToHomeInstitution(enrollmentRequest, body, associationURI, httpMethod, false, true); } /* diff --git a/src/test/java/generiek/api/EnrollmentEndpointTest.java b/src/test/java/generiek/api/EnrollmentEndpointTest.java index f3470bd..ffc2fc0 100644 --- a/src/test/java/generiek/api/EnrollmentEndpointTest.java +++ b/src/test/java/generiek/api/EnrollmentEndpointTest.java @@ -299,8 +299,6 @@ void associationUriInvalid() throws Exception { .patch("/associations/{associationId}") .then() .statusCode(403); - - } @Test @@ -730,6 +728,20 @@ private void doPatchAssociate(String associationId) throws IOException { .patch("/associations/{associationId}") .then() .statusCode(200); + //Alternative GET + stubFor(get(urlPathMatching("/associations/" + associationId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(200))); + + given() + .when() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .auth().basic("sis", "secret") + .pathParam("associationId", associationId) + .get("/associations/{associationId}") + .then() + .statusCode(200); } private void doPlayReportBackResults(String correlationId) throws IOException {