Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbucket-pipelines committed Jul 19, 2024
2 parents ecaea1d + f3ee49e commit 523c8ed
Show file tree
Hide file tree
Showing 31 changed files with 1,715 additions and 36 deletions.
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>magda</artifactId>
<groupId>be.vlaanderen.vip.mock</groupId>
<version>2.35.0</version>
<version>2.36.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion interfaces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>magda</artifactId>
<groupId>be.vlaanderen.vip.mock</groupId>
<version>2.35.0</version>
<version>2.36.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package be.vlaanderen.vip.magda.client;

import be.vlaanderen.vip.magda.exception.ServerException;

import java.util.UUID;

public abstract class AbstractConnectorMagdaClient implements MagdaClient {

private final MagdaConnector connector;

protected AbstractConnectorMagdaClient(
MagdaConnector connector) {
this.connector = connector;
}

@Override
public MagdaResponseWrapper send(MagdaRequest request) throws MagdaClientException {
return send(request, UUID.randomUUID());
}

@Override
public MagdaResponseWrapper send(MagdaRequest request, UUID requestId) throws MagdaClientException {
try {
var response = connector.send(request, requestId);

validateMagdaResponse(response, request);

return new MagdaResponseWrapper(response);
}
catch (ServerException e) {
throw new MagdaClientException("Error occurred while sending magda request", e);
}
}

protected abstract void validateMagdaResponse(MagdaResponse response, MagdaRequest request) throws MagdaClientException;
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
package be.vlaanderen.vip.magda.client;

import be.vlaanderen.vip.magda.exception.ServerException;
import be.vlaanderen.vip.magda.exception.UitzonderingenSectionInResponseException;
import be.vlaanderen.vip.magda.legallogging.model.UitzonderingEntry;
import be.vlaanderen.vip.magda.legallogging.model.UitzonderingType;

import java.util.List;
import java.util.UUID;

public class ConnectorMagdaClient implements MagdaClient {
private MagdaConnector connector;

public ConnectorMagdaClient(
MagdaConnector connector) {
this.connector = connector;
}
/**
* 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".
*/
public class ConnectorMagdaClient extends AbstractConnectorMagdaClient {

@Override
public MagdaResponseWrapper send(MagdaRequest request) throws MagdaClientException {
return send(request, UUID.randomUUID());
public ConnectorMagdaClient(MagdaConnector connector) {
super(connector);
}

@Override
public MagdaResponseWrapper send(MagdaRequest request, UUID requestId) throws MagdaClientException {
try {
var response = connector.send(request, requestId);

validateMagdaResponse(response, request);

return new MagdaResponseWrapper(response);
}
catch (ServerException e) {
throw new MagdaClientException("Error occurred while sending magda request", e);
}
}

private void validateMagdaResponse(MagdaResponse response, MagdaRequest request) throws MagdaClientException {
protected void validateMagdaResponse(MagdaResponse response, MagdaRequest request) throws MagdaClientException {
if(!response.getUitzonderingEntries().isEmpty()) {
throw new MagdaClientException("Level 2 exception occurred while calling magda service", new UitzonderingenSectionInResponseException(request.getSubject(), response.getUitzonderingEntries(), request.getCorrelationId(), response.getRequestId()));
}
Expand All @@ -47,5 +29,4 @@ private void validateMagdaResponse(MagdaResponse response, MagdaRequest request)
private boolean haveAtLeastOneFout(List<UitzonderingEntry> entries) {
return entries.stream().anyMatch(uitzonderingEntry -> uitzonderingEntry.getUitzonderingType().equals(UitzonderingType.FOUT));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package be.vlaanderen.vip.magda.client;

import be.vlaanderen.vip.magda.exception.UitzonderingenSectionInResponseException;

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

public LenientConnectorMagdaClient(MagdaConnector connector) {
super(connector);
}

@Override
protected void validateMagdaResponse(MagdaResponse response, MagdaRequest request) throws MagdaClientException {
if(!response.getUitzonderingEntries().isEmpty()) {
throw new MagdaClientException("Level 2 exception occurred while calling magda service", new UitzonderingenSectionInResponseException(request.getSubject(), response.getUitzonderingEntries(), request.getCorrelationId(), response.getRequestId()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package be.vlaanderen.vip.magda.client.diensten;

import lombok.Getter;

@Getter
public enum EducationEnrollmentSource {
HO("HO"),
INT("INT"),
LP("LP"),
VWO("VWO");

private final String value;

EducationEnrollmentSource(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package be.vlaanderen.vip.magda.client.diensten;

import be.vlaanderen.vip.magda.client.MagdaDocument;
import be.vlaanderen.vip.magda.client.MagdaServiceIdentification;
import be.vlaanderen.vip.magda.client.diensten.subject.INSZNumber;
import be.vlaanderen.vip.magda.client.domeinservice.MagdaRegistrationInfo;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.time.LocalDate;
import java.util.Set;
import java.util.UUID;

import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;

/**
* A request to the "Onderwijs.GeefHistoriekInschrijving" MAGDA service, which provides education enrollment histories for a person.
* Adds the following fields to the {@link PersonMagdaRequest}:
* <ul>
* <li>startDate: the start date of the period</li>
* <li>endDate: the end date of the period</li>
* <li>sources: the sources to be consulted (optional)</li>
* </ul>
*
* @see <a href="file:resources/templates/Onderwijs.GeefHistoriekInschrijvingDienst/02.01.0000/template.xml">XML template for this request type</a>
*/
@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
public class GeefHistoriekInschrijvingRequest extends PersonMagdaRequest {

public static class Builder extends PersonMagdaRequest.Builder<Builder> {

@Getter(AccessLevel.PROTECTED)
private LocalDate startDate;
@Getter(AccessLevel.PROTECTED)
private LocalDate endDate;
@Getter(AccessLevel.PROTECTED)
private Set<EducationEnrollmentSource> sources;

public Builder startDate(LocalDate startDate) {
this.startDate = startDate;
return this;
}

public Builder endDate(LocalDate endDate) {
this.endDate = endDate;
return this;
}

public Builder sources(Set<EducationEnrollmentSource> sources) {
this.sources = sources;
return this;
}

public GeefHistoriekInschrijvingRequest build() {
if(getInsz() == null) { throw new IllegalStateException("INSZ number must be given"); }
if(getStartDate() == null) { throw new IllegalStateException("Start date must be given"); }
if(getEndDate() == null) { throw new IllegalStateException("End date must be given"); }

return new GeefHistoriekInschrijvingRequest(
getInsz(),
getRegistration(),
getStartDate(),
getEndDate(),
getSources()
);
}
}

public static Builder builder() {
return new Builder();
}

@NotNull
private final LocalDate startDate;
@NotNull
private final LocalDate endDate;
@Nullable
private final Set<EducationEnrollmentSource> sources;

private GeefHistoriekInschrijvingRequest(
@NotNull INSZNumber insz,
@NotNull String registratie,
@NotNull LocalDate startDate,
@NotNull LocalDate endDate,
@Nullable Set<EducationEnrollmentSource> sources) {
super(insz, registratie);
this.startDate = startDate;
this.endDate = endDate;
this.sources = sources;
}

@Override
public MagdaServiceIdentification magdaServiceIdentification() {
return new MagdaServiceIdentification("Onderwijs.GeefHistoriekInschrijving", "02.01.0000");
}

@Override
protected void fillIn(MagdaDocument request, UUID requestId, MagdaRegistrationInfo magdaRegistrationInfo) {
fillInCommonFields(request, requestId, magdaRegistrationInfo);

request.setValue("//Criteria/Periode/Begin", startDate.format(ISO_LOCAL_DATE));
request.setValue("//Criteria/Periode/Einde", endDate.format(ISO_LOCAL_DATE));
if(sources != null) {
sources.forEach(source -> request.createTextNode("//Criteria/Bronnen", "Bron", source.getValue()));
} else {
request.removeNode("//Criteria/Bronnen");
}
}
}
Loading

0 comments on commit 523c8ed

Please sign in to comment.