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 Feb 29, 2024
2 parents 63bac74 + 4db4225 commit aeae5bb
Show file tree
Hide file tree
Showing 63 changed files with 2,563 additions and 77 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.7.0</version>
<version>2.8.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.7.0</version>
<version>2.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,46 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.io.Serializable;
import java.util.regex.Pattern;

/**
* An INSZ number.
*
* @see <a href="https://overheid.vlaanderen.be/personeel/regelgeving/insz-nummer">Information on INSZ numbers</a>
*/
@EqualsAndHashCode
public class INSZ {
public class INSZ implements Serializable {
private static final Pattern INSZ_PATTERN = Pattern.compile("\\d{11}");

@Getter
private final String value;

public INSZ(@NotNull String value) {
public static INSZ of(String value) {
validate(value);

return new INSZ(value);
}

private static void validate(String value) {
if(value == null || !INSZ_PATTERN.matcher(value).matches() || !passesModulo97Check(value)) {
throw new IllegalArgumentException("Invalid RRNR: %s".formatted(value));
}
}

private static boolean passesModulo97Check(String value) {
var base = Long.valueOf(value.substring(0, 9));

// Note: The validation of INSZ Numbers for people born after 2000 differs,
// cfr. https://nl.wikipedia.org/wiki/Rijksregisternummer
var baseAfter2000 = Long.valueOf("2" + value.substring(0, 9));

var check = Long.valueOf(value.substring(9));

return (base + check) % 97 == 0 || (baseAfter2000 + check) % 97 == 0;
}

private INSZ(@NotNull String value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package be.vlaanderen.vip.magda.client.domain.dto;

import java.io.Serializable;

/**
* Marker record for an INSZ number (of some type) that has been registered in the MAGDA Repertorium.
*
* @see INSZ
*/
public record RegisteredINSZ<T extends INSZ>(T insz) {
public record RegisteredINSZ(INSZ insz) implements Serializable {

public String toString() {
return insz.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public MagdaClientRepertoriumRegistrationService(
}

@Override
public <T extends INSZ> RegisteredINSZ<T> register(Function<String, T> inszCtor, RegistreerInschrijvingRequest request) throws MagdaClientException {
public RegisteredINSZ register(RegistreerInschrijvingRequest request) throws MagdaClientException {
correlationHeaderProvider.getXCorrelationId().ifPresent(xCorrelationId -> request.setCorrelationId(UUID.fromString(xCorrelationId)));

var response = service.send(request);
validateResponse(response);

return new RegisteredINSZ<>(inszCtor.apply(request.getInsz().getValue()));
return new RegisteredINSZ(INSZ.of(request.getInsz().getValue()));
}

private void validateResponse(MagdaResponseWrapper response) throws MagdaClientException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* A service for interfacing with MAGDA's "RegistreerInschrijving" services for registering INSZ numbers in the Repertorium.
*/
public interface RepertoriumRegistrationService {

/**
* Registers an INSZ number in the Repertorium from a RegistreerInschrijving request.
*
* @see RegisteredINSZ
* @see RegistreerInschrijvingRequest
*/
<T extends INSZ> RegisteredINSZ<T> register(Function<String, T> inszCtor, RegistreerInschrijvingRequest request) throws MagdaClientException;
RegisteredINSZ register(RegistreerInschrijvingRequest request) throws MagdaClientException;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,67 @@
package be.vlaanderen.vip.magda.client.domain.dto;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

class INSZTest {

/*
For more information on the validation, see:
https://vlaamseoverheid.atlassian.net/wiki/spaces/MG/pages/1127907704/Identificatienummer+Persoon-02.02#Extra-info
*/

@Test
void of_ifValueIsValidRRNRNumber_returnsRRNRWithGivenValue() {
var rrnr = INSZ.of("46061400105");

assertNotNull(rrnr);
assertEquals("46061400105", rrnr.getValue());
}

@ParameterizedTest
@ValueSource(strings = {"00012556777", "03060212051"})
void of_ifValueAfter2000IsValidRRNRNumber_returnsRRNRWithGivenValue(String value) {
var rrnr = INSZ.of(value);

assertNotNull(rrnr);
assertEquals(value, rrnr.getValue());
}

@Test
void of_ifValueIsHighRRNRNumber_returnsRRNRWithGivenValue() {
var rrnr = INSZ.of("99999999964");

assertNotNull(rrnr);
assertEquals("99999999964", rrnr.getValue());
}

@Test
void constructor_neverThrowsExceptions() {
assertDoesNotThrow(() -> new INSZ("46061400105"));
assertDoesNotThrow(() -> new INSZ("460614"));
assertDoesNotThrow(() -> new INSZ("46061400106"));
assertDoesNotThrow(() -> new INSZ("total bogus"));
assertDoesNotThrow(() -> new INSZ(null));
void of_throwsException_ifValueIsNull() {
assertThrows(IllegalArgumentException.class, () -> INSZ.of(null));
}

@Test
void of_throwsException_ifValueIsNotOfCorrectLength() {
assertThrows(IllegalArgumentException.class, () -> INSZ.of("460614"));
}

@ParameterizedTest
@ValueSource(strings = {"460614E0105", "-46061400105", "46061400.105"})
void of_throwsException_ifValueDoesNotConsistOfDigits(String value) {
assertThrows(IllegalArgumentException.class, () -> INSZ.of(value));
}

@ParameterizedTest
@ValueSource(strings = {"46061400106", "12345678901"})
void of_throwsException_ifValueFailsModulo97Check(String value) {
assertThrows(IllegalArgumentException.class, () -> INSZ.of(value));
}
@Test
void toString_returnsValue() {
assertEquals("46061400105", new INSZ("46061400105").toString());
assertEquals("46061400105", INSZ.of("46061400105").toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class RegisteredINSZTest {

@Test
void toString_returnsInszValue() {
assertEquals("46061400105", new RegisteredINSZ<>(new INSZ("46061400105")).toString());
assertEquals("46061400105", new RegisteredINSZ(INSZ.of("46061400105")).toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void setup() {
@Test
void callsMagdaService() throws MagdaClientException {
mockResultResponse("1");
var insz = new INSZ("insz");
var insz = INSZ.of("00000000097");
var start = LocalDate.now();

var registeredInsz = service.register(INSZ::new, RegistreerInschrijvingRequest.builder()
var registeredInsz = service.register(RegistreerInschrijvingRequest.builder()
.insz(insz.getValue())
.startDate(start)
.build());
Expand All @@ -56,7 +56,7 @@ void callsMagdaService() throws MagdaClientException {

verify(magdaClient).send(argThat(r -> {
if(r instanceof RegistreerInschrijvingRequest request) {
return request.getInsz().getValue().equals("insz") &&
return request.getInsz().getValue().equals("00000000097") &&
request.getStartDate().equals(start) &&
request.getCorrelationId().equals(UUID.fromString("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));
}
Expand All @@ -67,11 +67,11 @@ void callsMagdaService() throws MagdaClientException {
@Test
void throwsException_whenResultNot1() {
mockResultResponse("0");
var insz = new INSZ("insz");
var insz = INSZ.of("00000000097");
var start = LocalDate.now();

assertThrows(MagdaClientException.class,
() -> service.register(INSZ::new, RegistreerInschrijvingRequest.builder()
() -> service.register(RegistreerInschrijvingRequest.builder()
.insz(insz.getValue())
.startDate(start)
.build()));
Expand Down
2 changes: 1 addition & 1 deletion magdaconnector/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.7.0</version>
<version>2.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion magdamock-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>magda</artifactId>
<groupId>be.vlaanderen.vip.mock</groupId>
<version>2.7.0</version>
<version>2.8.0</version>
</parent>
<artifactId>magdamock-starter</artifactId>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2004-11-27">
<Straat>
<Naam>Kolvestraat</Naam>
</Straat>
Expand All @@ -126,7 +126,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2004-11-27">
<Straat>
<Naam>Drie Koningen</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2004-11-27">
<Straat>
<Naam>Rijsenbergstraat</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Referte>3147454e-cd8d-456b-a629-95eaf2e6d8d4</Referte>
<Inhoud>
<Onderneming>
<Ondernemingsnummer>0456123791</Ondernemingsnummer>
<Ondernemingsnummer>0464123719</Ondernemingsnummer>
<AuthentiekBron>
<Code>03</Code>
<Omschrijving>KBO</Omschrijving>
Expand Down Expand Up @@ -92,7 +92,7 @@
</Adres>
</Adressen>
<Inschrijving>
<Datum>2023-04-01</Datum>
<Datum>2022-04-01</Datum>
</Inschrijving>
<Rechtsvormen>
<Rechtsvorm>
Expand All @@ -107,7 +107,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2022-04-01">
<Straat>
<Naam>Schrijversstraat</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</Adres>
</Adressen>
<Inschrijving>
<Datum>2023-06-01</Datum>
<Datum>2022-06-01</Datum>
</Inschrijving>
<Rechtsvormen>
<Rechtsvorm>
Expand All @@ -107,7 +107,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2022-06-01">
<Straat>
<Naam>Hoogstraat</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2006-07-27">
<Straat>
<Naam>Tijgerstraat</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</Adres>
</Adressen>
<Inschrijving>
<Datum>2023-08-01</Datum>
<Datum>2022-08-01</Datum>
</Inschrijving>
<Rechtsvormen>
<Rechtsvorm>
Expand All @@ -106,7 +106,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2022-08-01">
<Straat>
<Naam>Zwijnaardsesteenweg</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="1998-07-27">
<Straat>
<Naam>Zandstraat</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</Adres>
</Adressen>
<Inschrijving>
<Datum>2023-06-01</Datum>
<Datum>2022-06-01</Datum>
</Inschrijving>
<Rechtsvormen>
<Rechtsvorm>
Expand All @@ -106,7 +106,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2022-06-01">
<Straat>
<Naam>Eikenlaan</Naam>
</Straat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Code>AC</Code>
</StatusKBO>
<Adressen>
<Adres>
<Adres DatumBegin="2002-07-23">
<Straat>
<Naam>Gistelse Steenweg</Naam>
</Straat>
Expand Down
Loading

0 comments on commit aeae5bb

Please sign in to comment.