diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/ConnectorMagdaClient.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/ConnectorMagdaClient.java index 13460c90..fceccccb 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/ConnectorMagdaClient.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/ConnectorMagdaClient.java @@ -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 { diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/LenientConnectorMagdaClient.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/LenientConnectorMagdaClient.java index 8d6ac450..5dfc0db8 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/LenientConnectorMagdaClient.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/LenientConnectorMagdaClient.java @@ -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 { diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/EnrollmentHistory.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/EnrollmentHistory.java index a5a7e8a5..7a7d6793 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/EnrollmentHistory.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/EnrollmentHistory.java @@ -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 ofMagdaDocument(MagdaDocument magdaDocument) throws MagdaClientException { return MagdaResponseEnrollmentHistoryAdapterJaxbImpl.getInstance().adapt(new MagdaResponseWrapper(MagdaResponse.builder() .document(magdaDocument) .build())); diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/GiveEnrollmentHistoryService.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/GiveEnrollmentHistoryService.java index e8c86897..b7074a16 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/GiveEnrollmentHistoryService.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/GiveEnrollmentHistoryService.java @@ -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; /** @@ -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 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 getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException; } diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaClientGiveEnrollmentHistoryService.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaClientGiveEnrollmentHistoryService.java index d7b275c1..ae37d094 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaClientGiveEnrollmentHistoryService.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaClientGiveEnrollmentHistoryService.java @@ -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 { @@ -27,7 +28,7 @@ public MagdaClientGiveEnrollmentHistoryService( } @Override - public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException { + public Optional getEnrollmentHistory(GeefHistoriekInschrijvingRequest request) throws MagdaClientException { var responseWrapper = client.send(request); validateResponse(responseWrapper.getResponse(), request); @@ -36,7 +37,7 @@ public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest r } @Override - public EnrollmentHistory getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException { + public Optional getEnrollmentHistory(GeefHistoriekInschrijvingRequest request, UUID requestId) throws MagdaClientException { var responseWrapper = client.send(request, requestId); validateResponse(responseWrapper.getResponse(), request); diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapter.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapter.java index c1d018bd..ae0a3155 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapter.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapter.java @@ -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 adapt(MagdaResponseWrapper wrapper) throws MagdaClientException; } \ No newline at end of file diff --git a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapterJaxbImpl.java b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapterJaxbImpl.java index c8d5bd7c..5b5706c6 100644 --- a/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapterJaxbImpl.java +++ b/interfaces/src/main/java/be/vlaanderen/vip/magda/client/domain/giveenrollmenthistory/MagdaResponseEnrollmentHistoryAdapterJaxbImpl.java @@ -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 { @@ -29,16 +28,19 @@ private MagdaResponseEnrollmentHistoryAdapterJaxbImpl() { } @Override - public EnrollmentHistory adapt(MagdaResponseWrapper wrapper) throws MagdaClientException { + public Optional 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); } } diff --git a/magdamock/src/test/java/be/vlaanderen/vip/mock/magda/client/domain/giveenrollmenthistory/MagdaResponseGiveEnrollmentHistoryIntegrationTest.java b/magdamock/src/test/java/be/vlaanderen/vip/mock/magda/client/domain/giveenrollmenthistory/MagdaResponseGiveEnrollmentHistoryIntegrationTest.java index b04d936d..b43e8133 100644 --- a/magdamock/src/test/java/be/vlaanderen/vip/mock/magda/client/domain/giveenrollmenthistory/MagdaResponseGiveEnrollmentHistoryIntegrationTest.java +++ b/magdamock/src/test/java/be/vlaanderen/vip/mock/magda/client/domain/giveenrollmenthistory/MagdaResponseGiveEnrollmentHistoryIntegrationTest.java @@ -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(String insz) throws MagdaClientException { var response = MagdaMock.getInstance().send(GeefHistoriekInschrijvingRequest.builder() .insz(insz) .startDate(LocalDate.of(2024, 1, 1))