Skip to content

Commit

Permalink
Merged in feature/MAGDASOLID-1814-enrollmenthistory-empty-if-no-conte…
Browse files Browse the repository at this point in the history
…nt (pull request #258)

fix!: return an empty optional in the high-level API layer for enrollment histories if the document has no content

Approved-by: Laurens Debackere
  • Loading branch information
NielskoDesmetski committed Aug 8, 2024
2 parents 83554bb + 338a88d commit 71a3276
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.util.List;

/**
* A MagdaConnector-based client which handles both level 2 and level 3 uitzondingen in the response.
* Level 3 uitzondingen are handled in an opinionated manner whereby an exception is thrown if at least one of them is of type "FOUT".
* A MagdaConnector-based client which handles both level 2 and level 3 uitzonderingen in the response.
* Level 3 uitzonderingen are handled in an opinionated manner whereby an exception is thrown if at least one of them is of type "FOUT".
*/
public class ConnectorMagdaClient extends AbstractConnectorMagdaClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import be.vlaanderen.vip.magda.exception.UitzonderingenSectionInResponseException;

/**
* A MagdaConnector-based client which handles level 2 uitzondingen in the response.
* A MagdaConnector-based client which handles level 2 uitzonderingen in the response.
*/
public class LenientConnectorMagdaClient extends AbstractConnectorMagdaClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import java.time.LocalDate;
import java.time.Year;
import java.util.List;
import java.util.Optional;

/**
* Information on a citizen's history of enrollment in education.
*/
public interface EnrollmentHistory {

static EnrollmentHistory ofMagdaDocument(MagdaDocument magdaDocument) throws MagdaClientException {
static Optional<EnrollmentHistory> ofMagdaDocument(MagdaDocument magdaDocument) throws MagdaClientException {
return MagdaResponseEnrollmentHistoryAdapterJaxbImpl.getInstance().adapt(new MagdaResponseWrapper(MagdaResponse.builder()
.document(magdaDocument)
.build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.diensten.GeefHistoriekInschrijvingRequest;

import java.util.Optional;
import java.util.UUID;

/**
Expand All @@ -11,18 +12,18 @@
public interface GiveEnrollmentHistoryService {

/**
* Retrieves education enrollment history information from a GeefHistoriekInschrijvingRequest request.
* Retrieves education enrollment history information, if any, from a GeefHistoriekInschrijvingRequest request.
*
* @see EnrollmentHistory
* @see GeefHistoriekInschrijvingRequest
*/
EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException;
Optional<EnrollmentHistory> getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException;

/**
* Retrieves education enrollment history information from a GeefHistoriekInschrijvingRequest request, with a provided request ID.
* Retrieves education enrollment history information, if any, from a GeefHistoriekInschrijvingRequest request, with a provided request ID.
*
* @see EnrollmentHistory
* @see GeefHistoriekInschrijvingRequest
*/
EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException;
Optional<EnrollmentHistory> getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import be.vlaanderen.vip.magda.exception.UitzonderingenSectionInResponseException;
import be.vlaanderen.vip.magda.legallogging.model.UitzonderingType;

import java.util.Optional;
import java.util.UUID;

public class MagdaClientGiveEnrollmentHistoryService implements GiveEnrollmentHistoryService {
Expand All @@ -27,7 +28,7 @@ public MagdaClientGiveEnrollmentHistoryService(
}

@Override
public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException {
public Optional<EnrollmentHistory> getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException {
var responseWrapper = client.send(request);

validateResponse(responseWrapper.getResponse(), request);
Expand All @@ -36,7 +37,7 @@ public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest r
}

@Override
public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException {
public Optional<EnrollmentHistory> getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException {
var responseWrapper = client.send(request, requestId);

validateResponse(responseWrapper.getResponse(), request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.MagdaResponseWrapper;

import java.util.Optional;

public interface MagdaResponseEnrollmentHistoryAdapter {

EnrollmentHistory adapt(MagdaResponseWrapper wrapper) throws MagdaClientException;
Optional<EnrollmentHistory> adapt(MagdaResponseWrapper wrapper) throws MagdaClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.xml.bind.JAXBException;
import lombok.SneakyThrows;

import java.util.NoSuchElementException;
import java.util.Optional;

public class MagdaResponseEnrollmentHistoryAdapterJaxbImpl implements MagdaResponseEnrollmentHistoryAdapter {
Expand All @@ -29,16 +28,19 @@ private MagdaResponseEnrollmentHistoryAdapterJaxbImpl() {
}

@Override
public EnrollmentHistory adapt(MagdaResponseWrapper wrapper) throws MagdaClientException {
public Optional<EnrollmentHistory> adapt(MagdaResponseWrapper wrapper) throws MagdaClientException {
try {
var node = Optional.ofNullable(wrapper
.getResponse()
.getDocument()
.xpath("//Inhoud")
.item(0));
return (EnrollmentHistory) context.createUnmarshaller()
.unmarshal(node.orElseThrow());
} catch (NoSuchElementException | JAXBException e) {
if(node.isPresent()) {
return Optional.of((EnrollmentHistory) context.createUnmarshaller().unmarshal(node.get()));
} else {
return Optional.empty();
}
} catch (JAXBException e) {
throw new MagdaClientException("Could not parse magda response", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@
import be.vlaanderen.vip.magda.client.diensten.GeefHistoriekInschrijvingRequest;
import be.vlaanderen.vip.magda.client.domain.giveenrollmenthistory.EnrollmentHistory;
import be.vlaanderen.vip.mock.magda.client.domain.MagdaMock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

class MagdaResponseGiveEnrollmentHistoryIntegrationTest {

private EnrollmentHistory enrollmentHistory;
@Test
void dataIsBoundToResponseDocument() throws MagdaClientException {
var enrollmentHistory = enrollmentHistory("88611099807");

@BeforeEach
void setup() throws MagdaClientException {
enrollmentHistory = enrollmentHistory("88611099807");
assertTrue(enrollmentHistory.isPresent());
var enrollments = enrollmentHistory.get().enrollments();
assertNotNull(enrollments);
assertEquals(6, enrollments.size());
}

@Test
void dataIsBoundToResponseDocument() {
var enrollments = enrollmentHistory.enrollments();
assertNotNull(enrollments);
assertEquals(6, enrollments.size());
void empty_ifResponseDocumentHasNoContent() throws MagdaClientException {
var enrollmentHistory = enrollmentHistory("00000000097");

assertTrue(enrollmentHistory.isEmpty());
}

private EnrollmentHistory enrollmentHistory(String insz) throws MagdaClientException {
private Optional<EnrollmentHistory> enrollmentHistory(String insz) throws MagdaClientException {
var response = MagdaMock.getInstance().send(GeefHistoriekInschrijvingRequest.builder()
.insz(insz)
.startDate(LocalDate.of(2024, 1, 1))
Expand Down

0 comments on commit 71a3276

Please sign in to comment.