From 939b67a45004df17c8b685b3234da5753e6f0fd3 Mon Sep 17 00:00:00 2001 From: Hristo Iliev Date: Mon, 28 Oct 2024 12:35:37 +0200 Subject: [PATCH] feature: shift zaak fatal date with additional info task (#1944) Shift due and fatal dates in accordance with additional info task fatal date Solves: PZ-3986 --------- Co-authored-by: Hristo Iliev --- .../app/planitems/PlanItemsRESTService.java | 48 ++++++---- .../formulieren/FormulierRuntimeService.java | 8 +- ...kHelper.java => SuspensionZaakHelper.java} | 91 +++++++++++-------- .../net/atos/zac/app/task/TaskRestService.kt | 6 +- .../net/atos/zac/app/zaak/ZaakRestService.kt | 8 +- .../app/planitems/PlanItemsRESTServiceTest.kt | 80 +++++++++++++++- .../atos/zac/app/task/TaskRestServiceTest.kt | 4 +- .../atos/zac/app/zaak/ZaakRestServiceTest.kt | 4 +- ...perTest.kt => SuspensionZaakHelperTest.kt} | 55 +++++++++-- 9 files changed, 223 insertions(+), 81 deletions(-) rename src/main/java/net/atos/zac/shared/helper/{OpschortenZaakHelper.java => SuspensionZaakHelper.java} (55%) rename src/test/kotlin/net/atos/zac/shared/helper/{OpschortenZaakHelperTest.kt => SuspensionZaakHelperTest.kt} (75%) diff --git a/src/main/java/net/atos/zac/app/planitems/PlanItemsRESTService.java b/src/main/java/net/atos/zac/app/planitems/PlanItemsRESTService.java index c396f3600e..71016b1c9e 100644 --- a/src/main/java/net/atos/zac/app/planitems/PlanItemsRESTService.java +++ b/src/main/java/net/atos/zac/app/planitems/PlanItemsRESTService.java @@ -40,6 +40,7 @@ import net.atos.client.zgw.zrc.model.Zaak; import net.atos.client.zgw.zrc.model.generated.Resultaat; import net.atos.zac.admin.ZaakafhandelParameterService; +import net.atos.zac.admin.model.FormulierDefinitie; import net.atos.zac.admin.model.HumanTaskParameters; import net.atos.zac.admin.model.MailtemplateKoppeling; import net.atos.zac.admin.model.ZaakafhandelParameters; @@ -61,7 +62,7 @@ import net.atos.zac.mailtemplates.model.MailGegevens; import net.atos.zac.mailtemplates.model.MailTemplate; import net.atos.zac.policy.PolicyService; -import net.atos.zac.shared.helper.OpschortenZaakHelper; +import net.atos.zac.shared.helper.SuspensionZaakHelper; import net.atos.zac.util.UriUtil; import net.atos.zac.util.time.DateTimeConverterUtil; import net.atos.zac.zoeken.IndexingService; @@ -75,6 +76,7 @@ @Produces(MediaType.APPLICATION_JSON) public class PlanItemsRESTService { private static final String REDEN_OPSCHORTING = "Aanvullende informatie opgevraagd"; + private static final String REDEN_PAST_FATALE_DATUM = "Aanvullende informatie opgevraagd"; private ZaakVariabelenService zaakVariabelenService; private CMMNService cmmnService; @@ -88,7 +90,7 @@ public class PlanItemsRESTService { private ConfiguratieService configuratieService; private MailTemplateService mailTemplateService; private PolicyService policyService; - private OpschortenZaakHelper opschortenZaakHelper; + private SuspensionZaakHelper suspensionZaakHelper; private RESTMailGegevensConverter restMailGegevensConverter; /** @@ -111,7 +113,7 @@ public PlanItemsRESTService( ConfiguratieService configuratieService, MailTemplateService mailTemplateService, PolicyService policyService, - OpschortenZaakHelper opschortenZaakHelper, + SuspensionZaakHelper suspensionZaakHelper, RESTMailGegevensConverter restMailGegevensConverter ) { this.zaakVariabelenService = zaakVariabelenService; @@ -126,7 +128,7 @@ public PlanItemsRESTService( this.configuratieService = configuratieService; this.mailTemplateService = mailTemplateService; this.policyService = policyService; - this.opschortenZaakHelper = opschortenZaakHelper; + this.suspensionZaakHelper = suspensionZaakHelper; this.restMailGegevensConverter = restMailGegevensConverter; } @@ -159,23 +161,22 @@ public List listUserEventListenerPlanItems(@PathParam("uuid") fina @GET @Path("humanTaskPlanItem/{id}") public RESTPlanItem readHumanTaskPlanItem(@PathParam("id") final String planItemId) { - final PlanItemInstance humanTaskPlanItem = cmmnService.readOpenPlanItem(planItemId); - final UUID zaakUUID = zaakVariabelenService.readZaakUUID(humanTaskPlanItem); - final UUID zaaktypeUUID = zaakVariabelenService.readZaaktypeUUID(humanTaskPlanItem); - final ZaakafhandelParameters zaakafhandelParameters = zaakafhandelParameterService.readZaakafhandelParameters( - zaaktypeUUID); - return planItemConverter.convertPlanItem(humanTaskPlanItem, zaakUUID, zaakafhandelParameters); + return convertPlanItem(planItemId); } @GET @Path("processTaskPlanItem/{id}") public RESTPlanItem readProcessTaskPlanItem(@PathParam("id") final String planItemId) { - final PlanItemInstance processTaskPlanItem = cmmnService.readOpenPlanItem(planItemId); - final UUID zaakUUID = zaakVariabelenService.readZaakUUID(processTaskPlanItem); - final UUID zaaktypeUUID = zaakVariabelenService.readZaaktypeUUID(processTaskPlanItem); + return convertPlanItem(planItemId); + } + + private RESTPlanItem convertPlanItem(String planItemId) { + final PlanItemInstance planItemInstance = cmmnService.readOpenPlanItem(planItemId); + final UUID zaakUUID = zaakVariabelenService.readZaakUUID(planItemInstance); + final UUID zaaktypeUUID = zaakVariabelenService.readZaaktypeUUID(planItemInstance); final ZaakafhandelParameters zaakafhandelParameters = zaakafhandelParameterService.readZaakafhandelParameters( zaaktypeUUID); - return planItemConverter.convertPlanItem(processTaskPlanItem, zaakUUID, zaakafhandelParameters); + return planItemConverter.convertPlanItem(planItemInstance, zaakUUID, zaakafhandelParameters); } @POST @@ -191,9 +192,14 @@ public void doHumanTaskplanItem(@Valid final RESTHumanTaskData humanTaskData) { ); final LocalDate fatalDate = calculateFatalDate(humanTaskData, zaakafhandelParameters, planItem, zaak); - if (fatalDate != null && isZaakOpschorten(taakdata)) { - final long numberOfDays = ChronoUnit.DAYS.between(LocalDate.now(), fatalDate); - opschortenZaakHelper.opschortenZaak(zaak, numberOfDays, REDEN_OPSCHORTING); + if (fatalDate != null) { + if (isZaakOpschorten(taakdata)) { + final long numberOfDays = ChronoUnit.DAYS.between(LocalDate.now(), fatalDate); + suspensionZaakHelper.suspendZaak(zaak, numberOfDays, REDEN_OPSCHORTING); + } else if (fatalDate.isAfter(zaak.getUiterlijkeEinddatumAfdoening())) { + final long numberOfDays = ChronoUnit.DAYS.between(zaak.getUiterlijkeEinddatumAfdoening(), fatalDate); + suspensionZaakHelper.extendZaakFatalDate(zaak, numberOfDays, REDEN_PAST_FATALE_DATUM); + } } if (humanTaskData.taakStuurGegevens.sendMail) { @@ -305,7 +311,9 @@ private LocalDate calculateFatalDate( final LocalDate zaakFatalDate = zaak.getUiterlijkeEinddatumAfdoening(); if (humanTaskData.fataledatum != null) { - validateFatalDate(humanTaskData.fataledatum, zaakFatalDate); + if (!isAanvullendeInformatieTask(planItem)) { + validateFatalDate(humanTaskData.fataledatum, zaakFatalDate); + } return humanTaskData.fataledatum; } else { if (humanTaskParameters.isPresent() && humanTaskParameters.get().getDoorlooptijd() != null) { @@ -320,6 +328,10 @@ private LocalDate calculateFatalDate( return null; } + private static boolean isAanvullendeInformatieTask(PlanItemInstance planItem) { + return FormulierDefinitie.AANVULLENDE_INFORMATIE.toString().equals(planItem.getPlanItemDefinitionId()); + } + private static void validateFatalDate(LocalDate taskFatalDate, LocalDate zaakFatalDate) { if (taskFatalDate.isAfter(zaakFatalDate)) { throw new InputValidationFailedException( diff --git a/src/main/java/net/atos/zac/formulieren/FormulierRuntimeService.java b/src/main/java/net/atos/zac/formulieren/FormulierRuntimeService.java index 3da4ff37ed..8cf4ab4067 100644 --- a/src/main/java/net/atos/zac/formulieren/FormulierRuntimeService.java +++ b/src/main/java/net/atos/zac/formulieren/FormulierRuntimeService.java @@ -36,7 +36,7 @@ import net.atos.zac.flowable.task.TaakVariabelenService; import net.atos.zac.formulieren.model.FormulierVeldtype; import net.atos.zac.identity.IdentityService; -import net.atos.zac.shared.helper.OpschortenZaakHelper; +import net.atos.zac.shared.helper.SuspensionZaakHelper; import net.atos.zac.util.time.DateTimeConverterUtil; public class FormulierRuntimeService { @@ -71,7 +71,7 @@ public class FormulierRuntimeService { private ReferenceTableService referenceTableService; @Inject - private OpschortenZaakHelper opschortenZaakHelper; + private SuspensionZaakHelper suspensionZaakHelper; @Inject private DrcClientService drcClientService; @@ -118,7 +118,7 @@ public Task submit(final RestTask restTask, Task task, final Zaak zaak) { task = flowableTaskService.updateTask(task); } if (formulierData.zaakOpschorten && !zaak.isOpgeschort()) { - opschortenZaakHelper.opschortenZaak( + suspensionZaakHelper.suspendZaak( zaak, DAYS.between(LocalDate.now(), convertToLocalDate(task.getDueDate())), restTask.getFormulierDefinitie() != null ? @@ -126,7 +126,7 @@ public Task submit(final RestTask restTask, Task task, final Zaak zaak) { restTask.getFormioFormulier().getString(FORMIO_TITLE)); } if (formulierData.zaakHervatten && zaak.isOpgeschort()) { - opschortenZaakHelper.hervattenZaak(zaak, REDEN_ZAAK_HERVATTEN); + suspensionZaakHelper.resumeZaak(zaak, REDEN_ZAAK_HERVATTEN); } markDocumentAsSent(formulierData); markDocumentAsSigned(formulierData); diff --git a/src/main/java/net/atos/zac/shared/helper/OpschortenZaakHelper.java b/src/main/java/net/atos/zac/shared/helper/SuspensionZaakHelper.java similarity index 55% rename from src/main/java/net/atos/zac/shared/helper/OpschortenZaakHelper.java rename to src/main/java/net/atos/zac/shared/helper/SuspensionZaakHelper.java index c86f90948b..7206a93bd5 100644 --- a/src/main/java/net/atos/zac/shared/helper/OpschortenZaakHelper.java +++ b/src/main/java/net/atos/zac/shared/helper/SuspensionZaakHelper.java @@ -17,9 +17,9 @@ import net.atos.zac.flowable.ZaakVariabelenService; import net.atos.zac.policy.PolicyService; -public class OpschortenZaakHelper { - private static final String OPSCHORTING = "Opschorting"; - private static final String HERVATTING = "Hervatting"; +public class SuspensionZaakHelper { + private static final String SUSPENSION = "Opschorting"; + private static final String RESUMING = "Hervatting"; private PolicyService policyService; private ZrcClientService zrcClientService; @@ -28,11 +28,11 @@ public class OpschortenZaakHelper { /** * Default no-arg constructor, required by Weld. */ - public OpschortenZaakHelper() { + public SuspensionZaakHelper() { } @Inject - OpschortenZaakHelper( + SuspensionZaakHelper( final PolicyService policyService, final ZrcClientService zrcClientService, final ZaakVariabelenService zaakVariabelenService @@ -42,27 +42,29 @@ public OpschortenZaakHelper() { this.zaakVariabelenService = zaakVariabelenService; } - public Zaak opschortenZaak(Zaak zaak, final long aantalDagen, final String redenOpschorting) { + public Zaak suspendZaak(Zaak zaak, final long numberOfDays, final String suspensionReason) { assertPolicy(policyService.readZaakRechten(zaak).opschorten()); assertPolicy(StringUtils.isEmpty(zaak.getOpschorting().getReden())); final UUID zaakUUID = zaak.getUuid(); - final String toelichting = String.format("%s: %s", OPSCHORTING, redenOpschorting); + final String toelichting = String.format("%s: %s", SUSPENSION, suspensionReason); LocalDate einddatumGepland = null; if (zaak.getEinddatumGepland() != null) { - einddatumGepland = zaak.getEinddatumGepland().plusDays(aantalDagen); + einddatumGepland = zaak.getEinddatumGepland().plusDays(numberOfDays); } - final LocalDate uiterlijkeEinddatumAfdoening = zaak.getUiterlijkeEinddatumAfdoening().plusDays(aantalDagen); - final Zaak updatedZaak = zrcClientService.patchZaak( - zaakUUID, - toPatch(einddatumGepland, uiterlijkeEinddatumAfdoening, redenOpschorting, true), - toelichting + final LocalDate uiterlijkeEinddatumAfdoening = zaak.getUiterlijkeEinddatumAfdoening().plusDays(numberOfDays); + final var patchZaak = addSuspensionToZaakPatch( + createZaakPatch(einddatumGepland, uiterlijkeEinddatumAfdoening), + suspensionReason, + true ); + + final Zaak updatedZaak = zrcClientService.patchZaak(zaakUUID, patchZaak, toelichting); zaakVariabelenService.setDatumtijdOpgeschort(zaakUUID, ZonedDateTime.now()); - zaakVariabelenService.setVerwachteDagenOpgeschort(zaakUUID, Math.toIntExact(aantalDagen)); + zaakVariabelenService.setVerwachteDagenOpgeschort(zaakUUID, Math.toIntExact(numberOfDays)); return updatedZaak; } - public Zaak hervattenZaak(final Zaak zaak, final String redenHervatting) { + public Zaak resumeZaak(final Zaak zaak, final String resumeReason) { assertPolicy(policyService.readZaakRechten(zaak).hervatten()); assertPolicy(zaak.isOpgeschort()); final UUID zaakUUID = zaak.getUuid(); @@ -76,40 +78,55 @@ public Zaak hervattenZaak(final Zaak zaak, final String redenHervatting) { } final LocalDate uiterlijkeEinddatumAfdoening = zaak.getUiterlijkeEinddatumAfdoening().plusDays(offset); - final String toelichting = String.format("%s: %s", HERVATTING, redenHervatting); - final Zaak updatedZaak = zrcClientService.patchZaak( - zaakUUID, - toPatch(einddatumGepland, uiterlijkeEinddatumAfdoening, redenHervatting, false), - toelichting + final String toelichting = String.format("%s: %s", RESUMING, resumeReason); + final var patchZaak = addSuspensionToZaakPatch( + createZaakPatch(einddatumGepland, uiterlijkeEinddatumAfdoening), + resumeReason, + false ); + + final Zaak updatedZaak = zrcClientService.patchZaak(zaakUUID, patchZaak, toelichting); zaakVariabelenService.removeDatumtijdOpgeschort(zaakUUID); zaakVariabelenService.removeVerwachteDagenOpgeschort(zaakUUID); return updatedZaak; } - /** - * @param einddatumGepland streefdatum van de zaak; may be null in which case the - * streefdatum is not patched - * @param uiterlijkeEinddatumAfdoening fataledatum van de zaak - * @param reden reden voor de opschorting - * @param isOpschorting true indien opschorten, false indien hervatten - * @return zaak voor patch - */ - private Zaak toPatch( - final LocalDate einddatumGepland, - final LocalDate uiterlijkeEinddatumAfdoening, - final String reden, - final boolean isOpschorting + public Zaak extendZaakFatalDate(final Zaak zaak, final long numberOfDays, final String description) { + var zaakRechten = policyService.readZaakRechten(zaak); + assertPolicy(zaakRechten.wijzigen() && zaakRechten.verlengenDoorlooptijd()); + + final UUID zaakUUID = zaak.getUuid(); + LocalDate endDatePlanned = null; + if (zaak.getEinddatumGepland() != null) { + endDatePlanned = zaak.getEinddatumGepland().plusDays(numberOfDays); + } + final LocalDate finalCompletionDate = zaak.getUiterlijkeEinddatumAfdoening().plusDays(numberOfDays); + + return zrcClientService.patchZaak(zaakUUID, createZaakPatch(endDatePlanned, finalCompletionDate), description); + } + + private Zaak createZaakPatch( + final LocalDate endDatePlanned, + final LocalDate finalCompletionDate ) { final Zaak zaak = new Zaak(); - if (einddatumGepland != null) { - zaak.setEinddatumGepland(einddatumGepland); + if (endDatePlanned != null) { + zaak.setEinddatumGepland(endDatePlanned); } - zaak.setUiterlijkeEinddatumAfdoening(uiterlijkeEinddatumAfdoening); + zaak.setUiterlijkeEinddatumAfdoening(finalCompletionDate); + return zaak; + } + + private Zaak addSuspensionToZaakPatch( + final Zaak zaak, + final String reason, + final boolean isOpschorting + ) { final Opschorting opschorting = new Opschorting(); - opschorting.setReden(reden); + opschorting.setReden(reason); opschorting.setIndicatie(isOpschorting); zaak.setOpschorting(opschorting); return zaak; } + } diff --git a/src/main/kotlin/net/atos/zac/app/task/TaskRestService.kt b/src/main/kotlin/net/atos/zac/app/task/TaskRestService.kt index e04fcd6e9b..a15e59eb4b 100644 --- a/src/main/kotlin/net/atos/zac/app/task/TaskRestService.kt +++ b/src/main/kotlin/net/atos/zac/app/task/TaskRestService.kt @@ -58,7 +58,7 @@ import net.atos.zac.flowable.util.TaskUtil import net.atos.zac.formulieren.FormulierRuntimeService import net.atos.zac.policy.PolicyService import net.atos.zac.policy.PolicyService.assertPolicy -import net.atos.zac.shared.helper.OpschortenZaakHelper +import net.atos.zac.shared.helper.SuspensionZaakHelper import net.atos.zac.signalering.SignaleringService import net.atos.zac.signalering.model.SignaleringType import net.atos.zac.signalering.model.SignaleringZoekParameters @@ -105,7 +105,7 @@ class TaskRestService @Inject constructor( private val taakHistorieConverter: RestTaskHistoryConverter, private val policyService: PolicyService, private val enkelvoudigInformatieObjectUpdateService: EnkelvoudigInformatieObjectUpdateService, - private val opschortenZaakHelper: OpschortenZaakHelper, + private val opschortenZaakHelper: SuspensionZaakHelper, private val formulierRuntimeService: FormulierRuntimeService, private val zaakVariabelenService: ZaakVariabelenService ) { @@ -260,7 +260,7 @@ class TaskRestService @Inject constructor( val updatedTask = updateDescriptionAndDueDate(restTask) createDocuments(restTask, zaak) if (isZaakHervatten(restTask.taakdata)) { - opschortenZaakHelper.hervattenZaak(zaak, REDEN_ZAAK_HERVATTEN) + opschortenZaakHelper.resumeZaak(zaak, REDEN_ZAAK_HERVATTEN) } restTask.taakdata?.let { taakdata -> taakdata[TAAK_DATA_DOCUMENTEN_VERZENDEN_POST]?.let { diff --git a/src/main/kotlin/net/atos/zac/app/zaak/ZaakRestService.kt b/src/main/kotlin/net/atos/zac/app/zaak/ZaakRestService.kt index 3cf07f9662..0ac5e0bac5 100644 --- a/src/main/kotlin/net/atos/zac/app/zaak/ZaakRestService.kt +++ b/src/main/kotlin/net/atos/zac/app/zaak/ZaakRestService.kt @@ -114,7 +114,7 @@ import net.atos.zac.policy.PolicyService import net.atos.zac.policy.PolicyService.assertPolicy import net.atos.zac.productaanvraag.InboxProductaanvraagService import net.atos.zac.productaanvraag.ProductaanvraagService -import net.atos.zac.shared.helper.OpschortenZaakHelper +import net.atos.zac.shared.helper.SuspensionZaakHelper import net.atos.zac.signalering.SignaleringService import net.atos.zac.signalering.model.SignaleringType import net.atos.zac.signalering.model.SignaleringZoekParameters @@ -175,7 +175,7 @@ class ZaakRestService @Inject constructor( private val zaakafhandelParameterService: ZaakafhandelParameterService, private val restGeometryConverter: RestGeometryConverter, private val healthCheckService: HealthCheckService, - private val opschortenZaakHelper: OpschortenZaakHelper, + private val opschortenZaakHelper: SuspensionZaakHelper, private val zaakService: ZaakService, private val restZaakHistorieRegelConverter: RESTZaakHistorieRegelConverter ) { @@ -365,7 +365,7 @@ class ZaakRestService @Inject constructor( val zaak = zrcClientService.readZaak(zaakUUID) return if (opschortGegevens.indicatieOpschorting) { restZaakConverter.toRestZaak( - opschortenZaakHelper.opschortenZaak( + opschortenZaakHelper.suspendZaak( zaak, opschortGegevens.duurDagen, opschortGegevens.redenOpschorting @@ -373,7 +373,7 @@ class ZaakRestService @Inject constructor( ) } else { restZaakConverter.toRestZaak( - opschortenZaakHelper.hervattenZaak(zaak, opschortGegevens.redenOpschorting) + opschortenZaakHelper.resumeZaak(zaak, opschortGegevens.redenOpschorting) ) } } diff --git a/src/test/kotlin/net/atos/zac/app/planitems/PlanItemsRESTServiceTest.kt b/src/test/kotlin/net/atos/zac/app/planitems/PlanItemsRESTServiceTest.kt index a833f76d27..5a6b65895f 100644 --- a/src/test/kotlin/net/atos/zac/app/planitems/PlanItemsRESTServiceTest.kt +++ b/src/test/kotlin/net/atos/zac/app/planitems/PlanItemsRESTServiceTest.kt @@ -17,6 +17,7 @@ import net.atos.client.zgw.zrc.ZrcClientService import net.atos.client.zgw.zrc.model.createZaak import net.atos.client.zgw.zrc.model.generated.Resultaat import net.atos.zac.admin.ZaakafhandelParameterService +import net.atos.zac.admin.model.FormulierDefinitie import net.atos.zac.admin.model.ZaakafhandelParameters import net.atos.zac.admin.model.createHumanTaskParameters import net.atos.zac.admin.model.createZaakafhandelParameters @@ -37,7 +38,7 @@ import net.atos.zac.mailtemplates.model.createMailGegevens import net.atos.zac.policy.PolicyService import net.atos.zac.policy.exception.PolicyException import net.atos.zac.policy.output.createZaakRechtenAllDeny -import net.atos.zac.shared.helper.OpschortenZaakHelper +import net.atos.zac.shared.helper.SuspensionZaakHelper import net.atos.zac.util.time.DateTimeConverterUtil import net.atos.zac.zoeken.IndexingService import org.flowable.cmmn.api.runtime.PlanItemInstance @@ -59,7 +60,7 @@ class PlanItemsRESTServiceTest : BehaviorSpec({ val configuratieService = mockk() val mailTemplateService = mockk() val policyService = mockk() - val opschortenZaakHelper = mockk() + val suspensionZaakHelper = mockk() val restMailGegevensConverter = mockk() val planItemsRESTService = PlanItemsRESTService( @@ -75,7 +76,7 @@ class PlanItemsRESTServiceTest : BehaviorSpec({ configuratieService, mailTemplateService, policyService, - opschortenZaakHelper, + suspensionZaakHelper, restMailGegevensConverter ) @@ -177,7 +178,7 @@ class PlanItemsRESTServiceTest : BehaviorSpec({ ) } just runs every { - opschortenZaakHelper.opschortenZaak(zaak, 1, "Aanvullende informatie opgevraagd") + suspensionZaakHelper.suspendZaak(zaak, 1, "Aanvullende informatie opgevraagd") } returns opgeschorteZaak When("A human task plan item is started from user with access") { @@ -187,7 +188,7 @@ class PlanItemsRESTServiceTest : BehaviorSpec({ verify(exactly = 1) { cmmnService.startHumanTaskPlanItem(any(), any(), any(), any(), any(), any(), any()) indexingService.addOrUpdateZaak(any(), any()) - opschortenZaakHelper.opschortenZaak(any(), any(), any()) + suspensionZaakHelper.suspendZaak(any(), any(), any()) } } } @@ -275,6 +276,75 @@ class PlanItemsRESTServiceTest : BehaviorSpec({ } } + Given("Additional info human task with a fatal date after the fatal date of the related zaak") { + val numberOfDays = 3L + val additionalInfoPlanItemInstanceId = FormulierDefinitie.AANVULLENDE_INFORMATIE.toString() + val restHumanTaskData = createRESTHumanTaskData( + planItemInstanceId = additionalInfoPlanItemInstanceId, + taakdata = mapOf( + "dummyKey" to "dummyValue" + ), + fataledatum = LocalDate.now().plusDays(numberOfDays) + ) + val zaak = createZaak( + zaakTypeURI = URI("http://example.com/$zaakTypeUUID"), + uiterlijkeEinddatumAfdoening = LocalDate.now() + ) + val extendedZaak = createZaak( + zaakTypeURI = URI("http://example.com/$zaakTypeUUID"), + uiterlijkeEinddatumAfdoening = LocalDate.now().plusDays(numberOfDays) + ) + val zaakafhandelParametersMock = mockk() + + every { cmmnService.readOpenPlanItem(additionalInfoPlanItemInstanceId) } returns planItemInstance + every { zaakVariabelenService.readZaakUUID(planItemInstance) } returns zaak.uuid + every { zrcClientService.readZaak(zaak.uuid) } returns zaak + every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny(startenTaak = true) + every { + zaakafhandelParameterService.readZaakafhandelParameters(zaakTypeUUID) + } returns zaakafhandelParametersMock + every { planItemInstance.planItemDefinitionId } returns additionalInfoPlanItemInstanceId + every { + zaakafhandelParametersMock.findHumanTaskParameter(additionalInfoPlanItemInstanceId) + } returns Optional.of( + createHumanTaskParameters().apply { + doorlooptijd = 10 + } + ) + every { + suspensionZaakHelper.extendZaakFatalDate(zaak, numberOfDays, "Aanvullende informatie opgevraagd") + } returns extendedZaak + every { + cmmnService.startHumanTaskPlanItem( + additionalInfoPlanItemInstanceId, + restHumanTaskData.groep.id, + null, + DateTimeConverterUtil.convertToDate(restHumanTaskData.fataledatum), + restHumanTaskData.toelichting, + any(), + zaak.uuid + ) + } just runs + every { indexingService.addOrUpdateZaak(zaak.uuid, false) } just runs + + When("A human task plan item is started") { + planItemsRESTService.doHumanTaskplanItem(restHumanTaskData) + + Then("The task is created with its own fatal date") { + verify(exactly = 1) { + cmmnService.startHumanTaskPlanItem(any(), any(), any(), any(), any(), any(), any()) + indexingService.addOrUpdateZaak(any(), any()) + } + } + + And("zaak extend fatal date was performed") { + verify(exactly = 1) { + suspensionZaakHelper.extendZaakFatalDate(any(), any(), any()) + } + } + } + } + Given("Zaak exists") { val zaak = createZaak() diff --git a/src/test/kotlin/net/atos/zac/app/task/TaskRestServiceTest.kt b/src/test/kotlin/net/atos/zac/app/task/TaskRestServiceTest.kt index 51a6dcfc43..90d7ffa380 100644 --- a/src/test/kotlin/net/atos/zac/app/task/TaskRestServiceTest.kt +++ b/src/test/kotlin/net/atos/zac/app/task/TaskRestServiceTest.kt @@ -53,7 +53,7 @@ import net.atos.zac.policy.output.createDocumentRechtenAllDeny import net.atos.zac.policy.output.createTaakRechtenAllDeny import net.atos.zac.policy.output.createWerklijstRechten import net.atos.zac.policy.output.createWerklijstRechtenAllDeny -import net.atos.zac.shared.helper.OpschortenZaakHelper +import net.atos.zac.shared.helper.SuspensionZaakHelper import net.atos.zac.signalering.SignaleringService import net.atos.zac.task.TaskService import net.atos.zac.util.time.DateTimeConverterUtil @@ -79,7 +79,7 @@ class TaskRestServiceTest : BehaviorSpec({ val restTaskConverter = mockk() val flowableTaskService = mockk() val zrcClientService = mockk() - val opschortenZaakHelper = mockk() + val opschortenZaakHelper = mockk() val restInformatieobjectConverter = mockk() val signaleringService = mockk() val taakHistorieConverter = mockk() diff --git a/src/test/kotlin/net/atos/zac/app/zaak/ZaakRestServiceTest.kt b/src/test/kotlin/net/atos/zac/app/zaak/ZaakRestServiceTest.kt index 4f4ddf9b9c..f5352db34b 100644 --- a/src/test/kotlin/net/atos/zac/app/zaak/ZaakRestServiceTest.kt +++ b/src/test/kotlin/net/atos/zac/app/zaak/ZaakRestServiceTest.kt @@ -83,7 +83,7 @@ import net.atos.zac.policy.output.createZaakRechtenAllDeny import net.atos.zac.productaanvraag.InboxProductaanvraagService import net.atos.zac.productaanvraag.ProductaanvraagService import net.atos.zac.productaanvraag.createProductaanvraagDimpact -import net.atos.zac.shared.helper.OpschortenZaakHelper +import net.atos.zac.shared.helper.SuspensionZaakHelper import net.atos.zac.signalering.SignaleringService import net.atos.zac.websocket.event.ScreenEvent import net.atos.zac.zaak.ZaakService @@ -112,7 +112,7 @@ class ZaakRestServiceTest : BehaviorSpec({ val loggedInUserInstance = mockk>() val objectsClientService = mockk() val ontkoppeldeDocumentenService = mockk() - val opschortenZaakHelper = mockk() + val opschortenZaakHelper = mockk() val policyService = mockk() val productaanvraagService = mockk() val restBAGConverter = mockk() diff --git a/src/test/kotlin/net/atos/zac/shared/helper/OpschortenZaakHelperTest.kt b/src/test/kotlin/net/atos/zac/shared/helper/SuspensionZaakHelperTest.kt similarity index 75% rename from src/test/kotlin/net/atos/zac/shared/helper/OpschortenZaakHelperTest.kt rename to src/test/kotlin/net/atos/zac/shared/helper/SuspensionZaakHelperTest.kt index b64084e9e1..9e630ae630 100644 --- a/src/test/kotlin/net/atos/zac/shared/helper/OpschortenZaakHelperTest.kt +++ b/src/test/kotlin/net/atos/zac/shared/helper/SuspensionZaakHelperTest.kt @@ -21,12 +21,12 @@ import net.atos.zac.policy.output.createZaakRechtenAllDeny import java.time.LocalDate import java.util.Optional -class OpschortenZaakHelperTest : BehaviorSpec({ +class SuspensionZaakHelperTest : BehaviorSpec({ val policyService = mockk() val zrcClientService = mockk() val zaakVariabelenService = mockk() - val opschortenZaakHelper = OpschortenZaakHelper( + val suspensionZaakHelper = SuspensionZaakHelper( policyService, zrcClientService, zaakVariabelenService @@ -75,7 +75,7 @@ class OpschortenZaakHelperTest : BehaviorSpec({ When("the zaak is postponed for x days from user with access") { every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny(opschorten = true) - val returnedZaak = opschortenZaakHelper.opschortenZaak( + val returnedZaak = suspensionZaakHelper.suspendZaak( zaak, numberOfDaysPostponed, postPonementReason @@ -107,7 +107,7 @@ class OpschortenZaakHelperTest : BehaviorSpec({ every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny() val exception = shouldThrow { - opschortenZaakHelper.opschortenZaak( + suspensionZaakHelper.suspendZaak( zaak, numberOfDaysPostponed, postPonementReason @@ -117,6 +117,7 @@ class OpschortenZaakHelperTest : BehaviorSpec({ Then("it throws exception with no message") { exception.message shouldBe null } } } + Given("a zaak that is postponed and does not have an planned end date") { val reasonResumed = "dummyResumeReason" val zaak = createZaak( @@ -149,7 +150,7 @@ class OpschortenZaakHelperTest : BehaviorSpec({ When("the zaak is resumed from user with access") { every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny(hervatten = true) - opschortenZaakHelper.hervattenZaak(zaak, reasonResumed) + suspensionZaakHelper.resumeZaak(zaak, reasonResumed) Then("the zaak should be resumed") { verify(exactly = 1) { @@ -172,7 +173,49 @@ class OpschortenZaakHelperTest : BehaviorSpec({ When("the zaak is resumed from user with no access") { every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny() - val exception = shouldThrow { opschortenZaakHelper.hervattenZaak(zaak, reasonResumed) } + val exception = shouldThrow { suspensionZaakHelper.resumeZaak(zaak, reasonResumed) } + + Then("it throws exception with no message") { exception.message shouldBe null } + } + } + + Given("a zaak with a final date") { + val extensionDescription = "extension description" + val zaak = createZaak( + einddatumGepland = LocalDate.now().plusDays(1), + uiterlijkeEinddatumAfdoening = LocalDate.now().plusDays(2) + ) + val extendedZaak = createZaak( + opschorting = createOpschorting(reden = null), + einddatumGepland = LocalDate.now().plusDays(3), + uiterlijkeEinddatumAfdoening = LocalDate.now().plusDays(4) + ) + val patchedZaak = slot() + + every { + zrcClientService.patchZaak(zaak.uuid, capture(patchedZaak), extensionDescription) + } returns extendedZaak + + When("extension of the final date is requested from user with access") { + every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny( + wijzigen = true, + verlengenDoorlooptijd = true + ) + + val result = suspensionZaakHelper.extendZaakFatalDate(zaak, 2, extensionDescription) + + Then("the correct dates are set") { + result.uiterlijkeEinddatumAfdoening shouldBe extendedZaak.uiterlijkeEinddatumAfdoening + result.einddatumGepland shouldBe extendedZaak.einddatumGepland + } + } + + When("extension of the final date is requested from user with no access") { + every { policyService.readZaakRechten(zaak) } returns createZaakRechtenAllDeny() + + val exception = shouldThrow { + suspensionZaakHelper.extendZaakFatalDate(zaak, 1, extensionDescription) + } Then("it throws exception with no message") { exception.message shouldBe null } }