Skip to content

Commit

Permalink
fix: fixed issue with RolMedewerker without a MedewerkerIdentificatie…
Browse files Browse the repository at this point in the history
… by adding an explicit null check
  • Loading branch information
edgarvonk committed Dec 19, 2024
1 parent 4279b56 commit 64aa75c
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 39 deletions.
3 changes: 0 additions & 3 deletions src/main/java/net/atos/client/zgw/zrc/ZrcClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ public void updateRol(final Zaak zaak, final Rol<?> rol, final String toelichtin

public void deleteRol(final Zaak zaak, final BetrokkeneType betrokkeneType, final String toelichting) {
final List<Rol<?>> rollen = listRollen(zaak);

final Optional<Rol<?>> rolMedewerker = rollen.stream().filter(rol -> rol.getBetrokkeneType() == betrokkeneType).findFirst();

rolMedewerker.ifPresent(betrokkene -> rollen.removeIf(rol -> rol.equalBetrokkeneRol(betrokkene)));

updateRollen(zaak, rollen, toelichting);
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/atos/client/zgw/zrc/model/Rol.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Objects;
import java.util.UUID;

import javax.annotation.Nullable;

import jakarta.json.bind.annotation.JsonbDateFormat;
import jakarta.json.bind.annotation.JsonbTypeDeserializer;

Expand Down Expand Up @@ -172,6 +174,12 @@ public void setIndicatieMachtiging(final IndicatieMachtiging indicatieMachtiging
this.indicatieMachtiging = indicatieMachtiging;
}

/**
* Can be null according to the ZGW API and this does occur in practice in certain circumstances.
*
* @return the betrokkene identificatie; or null if there is none
*/
@Nullable
public T getBetrokkeneIdentificatie() {
return betrokkeneIdentificatie;
}
Expand All @@ -185,6 +193,9 @@ public boolean equals(Object o) {
return false;
}
Rol<T> rol = (Rol<T>) o;
if (rol.getBetrokkeneIdentificatie() == null) {
return false;
}
return equalBetrokkeneRol(rol) && equalBetrokkeneIdentificatie(rol.getBetrokkeneIdentificatie());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import java.net.URI;
import java.util.Objects;

import javax.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;

import net.atos.client.zgw.ztc.model.generated.RolType;

import javax.annotation.Nullable;

public class RolMedewerker extends Rol<Medewerker> {

public RolMedewerker() {
Expand All @@ -27,8 +27,7 @@ public RolMedewerker(
final String roltoelichting,
// it is possible in the ZGW API to have a RolMedewerker without a Medewerker
// and this does occur in practice in certain circumstances
@Nullable
final Medewerker betrokkeneIdentificatie
@Nullable final Medewerker betrokkeneIdentificatie
) {
super(zaak, roltype, BetrokkeneType.MEDEWERKER, betrokkeneIdentificatie, roltoelichting);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class ZGWApiService @Inject constructor(
// but in case there are multiple, we take the first one
.firstOrNull()?.let {
zrcClientService.listRollen(RolListParameters(zaak.url, it.url, betrokkeneType))
.getSingleResult().takeIf { it.isPresent }?.get()
.singleResult.takeIf { it.isPresent }?.get()
}

private fun createStatusForZaak(zaakURI: URI, statustypeURI: URI, toelichting: String?): Status {
Expand Down
19 changes: 10 additions & 9 deletions src/main/kotlin/net/atos/zac/app/zaak/ZaakRestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,8 @@ class ZaakRestService @Inject constructor(
val zaak = zrcClientService.readZaak(toekennenGegevens.zaakUUID).also {
assertPolicy(policyService.readZaakRechten(it).toekennen)
}
val behandelaar = zgwApiService.findBehandelaarMedewerkerRoleForZaak(
zaak
)?.betrokkeneIdentificatie?.identificatie
val behandelaar = zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)
?.betrokkeneIdentificatie?.identificatie
val isUpdated = AtomicBoolean(false)
if (behandelaar != toekennenGegevens.assigneeUserName) {
toekennenGegevens.assigneeUserName?.takeIf { it.isNotEmpty() }?.let {
Expand All @@ -532,13 +531,15 @@ class ZaakRestService @Inject constructor(
?: zrcClientService.deleteRol(zaak, BetrokkeneType.MEDEWERKER, toekennenGegevens.reason)
isUpdated.set(true)
}
zgwApiService.findGroepForZaak(zaak)?.let {
zgwApiService.findGroepForZaak(zaak)?.let { rolOrganisatorischeEenheid ->
val groupId = toekennenGegevens.groupId
if (it.betrokkeneIdentificatie.identificatie != groupId) {
val group = identityService.readGroup(groupId)
val role = zaakService.bepaalRolGroep(group, zaak)
zrcClientService.updateRol(zaak, role, toekennenGegevens.reason)
isUpdated.set(true)
rolOrganisatorischeEenheid.betrokkeneIdentificatie?.let {
if (it.identificatie != groupId) {
val group = identityService.readGroup(groupId)
val role = zaakService.bepaalRolGroep(group, zaak)
zrcClientService.updateRol(zaak, role, toekennenGegevens.reason)
isUpdated.set(true)
}
}
}
if (isUpdated.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class RestZaakConverter @Inject constructor(
@Suppress("LongMethod", "CyclomaticComplexMethod")
fun toRestZaak(zaak: Zaak, status: Status?, statustype: StatusType?): RestZaak {
val zaaktype = ztcClientService.readZaaktype(zaak.zaaktype)
val groep = zgwApiService.findGroepForZaak(zaak)?.let {
restGroupConverter.convertGroupId(it.betrokkeneIdentificatie.identificatie)
val groep = zgwApiService.findGroepForZaak(zaak)?.let { rolOrganisatorischeEenheid ->
rolOrganisatorischeEenheid.betrokkeneIdentificatie?.let {
restGroupConverter.convertGroupId(it.identificatie)
}
}
val besluiten = brcClientService.listBesluiten(zaak)
.map { restDecisionConverter.convertToRestDecision(it) }
val behandelaar = zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let {
restUserConverter.convertUserId(it.betrokkeneIdentificatie.identificatie)
val behandelaar = zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let { rolMedewerker ->
rolMedewerker.betrokkeneIdentificatie?.let { restUserConverter.convertUserId(it.identificatie) }
}
val initiator = zgwApiService.findInitiatorRoleForZaak(zaak)
return RestZaak(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ class RestZaakOverzichtConverter @Inject constructor(
}
},
behandelaar = takeIf { zaakrechten.lezen }?.let {
zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let {
userConverter.convertUserId(it.betrokkeneIdentificatie.identificatie)
zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let { rolMedewerker ->
rolMedewerker.betrokkeneIdentificatie?.let {
userConverter.convertUserId(it.identificatie)
}
}
},
groep = takeIf { zaakrechten.lezen }?.let {
zgwApiService.findGroepForZaak(zaak)?.let {
groupConverter.convertGroupId(it.betrokkeneIdentificatie.identificatie)
zgwApiService.findGroepForZaak(zaak)?.let { rolOrganisatorischeEenheid ->
rolOrganisatorischeEenheid.betrokkeneIdentificatie?.let {
groupConverter.convertGroupId(it.identificatie)
}
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class RestZaakBetrokkene(

var type: String,

var identificatie: String
var identificatie: String?
)

@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
Expand All @@ -35,11 +35,11 @@ fun Rol<*>.toRestZaakBetrokkene() = RestZaakBetrokkene(
roltoelichting = this.roltoelichting,
type = this.betrokkeneType.name,
identificatie = when (this.betrokkeneType) {
BetrokkeneType.NATUURLIJK_PERSOON -> (this as RolNatuurlijkPersoon).betrokkeneIdentificatie.inpBsn
BetrokkeneType.NIET_NATUURLIJK_PERSOON -> (this as RolNietNatuurlijkPersoon).betrokkeneIdentificatie.innNnpId
BetrokkeneType.VESTIGING -> (this as RolVestiging).betrokkeneIdentificatie.vestigingsNummer
BetrokkeneType.ORGANISATORISCHE_EENHEID -> (this as RolOrganisatorischeEenheid).betrokkeneIdentificatie.naam
BetrokkeneType.MEDEWERKER -> (this as RolMedewerker).betrokkeneIdentificatie.identificatie
BetrokkeneType.NATUURLIJK_PERSOON -> (this as RolNatuurlijkPersoon).betrokkeneIdentificatie?.inpBsn
BetrokkeneType.NIET_NATUURLIJK_PERSOON -> (this as RolNietNatuurlijkPersoon).betrokkeneIdentificatie?.innNnpId
BetrokkeneType.VESTIGING -> (this as RolVestiging).betrokkeneIdentificatie?.vestigingsNummer
BetrokkeneType.ORGANISATORISCHE_EENHEID -> (this as RolOrganisatorischeEenheid).betrokkeneIdentificatie?.naam
BetrokkeneType.MEDEWERKER -> (this as RolMedewerker).betrokkeneIdentificatie?.identificatie
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ class ZaakZoekObjectConverter @Inject constructor(
}

private fun findBehandelaar(zaak: Zaak): User? =
zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let {
identityService.readUser(it.betrokkeneIdentificatie.identificatie)
zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak)?.let { rolMedewerker ->
rolMedewerker.betrokkeneIdentificatie?.let {
identityService.readUser(it.identificatie)
}
}

private fun findGroup(zaak: Zaak): Group? =
zgwApiService.findGroepForZaak(zaak)?.let {
identityService.readGroup(it.betrokkeneIdentificatie.identificatie)
zgwApiService.findGroepForZaak(zaak)?.let { rolOrganisatorischeEenheid ->
rolOrganisatorischeEenheid.betrokkeneIdentificatie?.let {
identityService.readGroup(it.identificatie)
}
}

private fun getBagObjectIDs(zaak: Zaak): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ZGWApiServiceTest : BehaviorSpec({
}
}
}
Given("A zaak with a behandelaar medewerker role without a betrokkene identificatie") {
Given("A zaak with a behandelaar medewerker role without a betrokkene identificatie") {
val zaak = createZaak()
val rolMedewerker = createRolMedewerker(
zaak = zaak.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class ZaakRestServiceTest : BehaviorSpec({
with(rolSlot.captured) {
betrokkeneType shouldBe BetrokkeneType.MEDEWERKER
with(betrokkeneIdentificatie as Medewerker) {
identificatie shouldBe rolMedewerker.betrokkeneIdentificatie.identificatie
identificatie shouldBe rolMedewerker.betrokkeneIdentificatie!!.identificatie
}
this.zaak shouldBe rolMedewerker.zaak
omschrijving shouldBe rolType.omschrijving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ZaakZoekObjectConverterTest : BehaviorSpec({
every { zgwApiService.findGroepForZaak(zaak) } returns null
every { zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak) } returns rolMedewerkerBehandelaar
every {
identityService.readUser(rolMedewerkerBehandelaar.betrokkeneIdentificatie.identificatie)
identityService.readUser(rolMedewerkerBehandelaar.betrokkeneIdentificatie!!.identificatie)
} returns userBehandelaar
every { ztcClientService.readZaaktype(zaak.zaaktype) } returns zaakType
every { ztcClientService.readResultaattype(resultaat.resultaattype) } returns resultaatType
Expand Down Expand Up @@ -170,7 +170,7 @@ class ZaakZoekObjectConverterTest : BehaviorSpec({
every { zgwApiService.findGroepForZaak(zaak) } returns null
every { zgwApiService.findBehandelaarMedewerkerRoleForZaak(zaak) } returns rolMedewerkerBehandelaar
every {
identityService.readUser(rolMedewerkerBehandelaar.betrokkeneIdentificatie.identificatie)
identityService.readUser(rolMedewerkerBehandelaar.betrokkeneIdentificatie!!.identificatie)
} returns userBehandelaar
every { ztcClientService.readZaaktype(zaak.zaaktype) } returns zaakType
every { zrcClientService.readStatus(zaak.status) } returns zaakStatus
Expand Down

0 comments on commit 64aa75c

Please sign in to comment.