Skip to content

Commit

Permalink
Proxy association endpoint also for GET
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Nov 4, 2024
1 parent 8897f6f commit e364ba3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/main/java/generiek/api/EnrollmentEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -362,6 +359,19 @@ public ResponseEntity<Map<String, Object>> associate(@PathVariable("personId") S
@PatchMapping("/associations/{associationId}")
public ResponseEntity<Map<String, Object>> associationUpdate(@PathVariable("associationId") String associationId,
@RequestBody Map<String, Object> 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<Map<String, Object>> associationUpdateGet(@PathVariable("associationId") String associationId) {
return doAssociationUpdate(associationId, Optional.empty());
}

private ResponseEntity<Map<String, Object>> doAssociationUpdate(String associationId, Optional<Map<String, Object>> association) {
EnrollmentRequest enrollmentRequest = associationRepository.findByAssociationId(associationId)
.orElseThrow(ExpiredEnrollmentRequestException::new).getEnrollmentRequest();

Expand All @@ -375,8 +385,9 @@ public ResponseEntity<Map<String, Object>> associationUpdate(@PathVariable("asso
}
LOG.debug(String.format("Patching association endpoint for enrolment request %s to %s", enrollmentRequest, associationURI));

Map<String, Object> body = EnrollmentAssociation.transform(association, enrollmentRequest);
return exchangeToHomeInstitution(enrollmentRequest, body, associationURI, HttpMethod.PATCH, false, true);
Map<String, Object> 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);
}

/*
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/generiek/api/EnrollmentEndpointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ void associationUriInvalid() throws Exception {
.patch("/associations/{associationId}")
.then()
.statusCode(403);


}

@Test
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e364ba3

Please sign in to comment.