Skip to content

Commit 97d5a9c

Browse files
authored
Merge pull request #5881 from espoon-voltti/varda-minimum-valid-fee-end-date
Käsitellään edellisten Varda-lähdejärjestelmien maksutiedot oikein
2 parents eb7d57c + c72fed8 commit 97d5a9c

File tree

2 files changed

+240
-14
lines changed

2 files changed

+240
-14
lines changed

service/src/integrationTest/kotlin/fi/espoo/evaka/varda/new/VardaUpdaterIntegrationTest.kt

+213-2
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ class VardaUpdaterIntegrationTest : PureJdbiTest(resetDbBeforeEach = true) {
22252225
lahdejarjestelma =
22262226
null, // This will be set to new.sourceSystem
22272227
alkamis_pvm = old.beforeEvakaRange.start,
2228-
paattymis_pvm = old.beforeEvakaRange.end,
2228+
paattymis_pvm = null,
22292229
hakemus_pvm = old.applicationDate,
22302230
tuntimaara_viikossa = 35.0,
22312231
kokopaivainen_vaka_kytkin = true,
@@ -2243,7 +2243,7 @@ class VardaUpdaterIntegrationTest : PureJdbiTest(resetDbBeforeEach = true) {
22432243
lahdejarjestelma =
22442244
old.sourceSystem, // This will be kept
22452245
alkamis_pvm = old.beforeEvakaRange.start,
2246-
paattymis_pvm = old.beforeEvakaRange.end,
2246+
paattymis_pvm = null,
22472247
toimipaikka_oid = old.unitOid,
22482248
)
22492249
),
@@ -2394,6 +2394,217 @@ class VardaUpdaterIntegrationTest : PureJdbiTest(resetDbBeforeEach = true) {
23942394
)
23952395
}
23962396

2397+
@Test
2398+
fun `write to varda - maksutieto from other source system is deleted if it would end before 2019-09-01`() {
2399+
val henkiloUrl = URI.create("henkilo")
2400+
val lapsiUrl = URI.create("lapsi")
2401+
2402+
val old =
2403+
object {
2404+
val sourceSystem = "oldSourceSystem"
2405+
val organizerOid = "oldOrganizerOid"
2406+
val unitOid = "oldUnitOid"
2407+
2408+
val start = LocalDate.of(2018, 1, 1)
2409+
val applicationDate = start.minusMonths(4)
2410+
2411+
val varhaiskasvatusPaatosToEndUrl = URI.create("varhaiskasvatuspaatos_to_end")
2412+
val varhaiskasvatusSuhdeToEndUrl = URI.create("varhaiskasvatussuhde_to_end")
2413+
val maksutietoToDeleteUrl = URI.create("maksutieto_to_end")
2414+
}
2415+
val new =
2416+
object {
2417+
val sourceSystem = "sourceSystem"
2418+
val organizerOid = "organizerOid"
2419+
val unitOid = "unitOid"
2420+
2421+
// This is after 2019-01-01 but before 2019-09-01
2422+
// => other data is set to end, maksutieto is deleted
2423+
val range = FiniteDateRange(LocalDate.of(2019, 6, 1), LocalDate.of(2019, 12, 31))
2424+
2425+
val applicationDate = range.start.minusDays(22)
2426+
}
2427+
2428+
val vardaHenkilo =
2429+
VardaUpdater.VardaHenkiloNode(
2430+
henkilo =
2431+
VardaReadClient.HenkiloResponse(
2432+
url = henkiloUrl,
2433+
henkilo_oid = "henkilo_oid_1",
2434+
lapsi = listOf(lapsiUrl),
2435+
),
2436+
lapset =
2437+
listOf(
2438+
VardaUpdater.VardaLapsiNode(
2439+
lapsi =
2440+
VardaReadClient.LapsiResponse(
2441+
url = lapsiUrl,
2442+
lahdejarjestelma = old.sourceSystem,
2443+
vakatoimija_oid = old.organizerOid,
2444+
oma_organisaatio_oid = null,
2445+
paos_organisaatio_oid = null,
2446+
paos_kytkin = false,
2447+
),
2448+
varhaiskasvatuspaatokset =
2449+
listOf(
2450+
VardaUpdater.VardaVarhaiskasvatuspaatosNode(
2451+
varhaiskasvatuspaatos =
2452+
VardaReadClient.VarhaiskasvatuspaatosResponse(
2453+
url = old.varhaiskasvatusPaatosToEndUrl,
2454+
lahdejarjestelma = old.sourceSystem,
2455+
alkamis_pvm = old.start,
2456+
paattymis_pvm = null,
2457+
hakemus_pvm = old.applicationDate,
2458+
tuntimaara_viikossa = 35.0,
2459+
kokopaivainen_vaka_kytkin = true,
2460+
tilapainen_vaka_kytkin = false,
2461+
paivittainen_vaka_kytkin = true,
2462+
vuorohoito_kytkin = false,
2463+
jarjestamismuoto_koodi = "jm01",
2464+
),
2465+
varhaiskasvatussuhteet =
2466+
listOf(
2467+
VardaReadClient.VarhaiskasvatussuhdeResponse(
2468+
url = old.varhaiskasvatusSuhdeToEndUrl,
2469+
varhaiskasvatuspaatos =
2470+
old.varhaiskasvatusPaatosToEndUrl,
2471+
lahdejarjestelma = old.sourceSystem,
2472+
alkamis_pvm = old.start,
2473+
paattymis_pvm = null,
2474+
toimipaikka_oid = old.unitOid,
2475+
)
2476+
),
2477+
)
2478+
),
2479+
maksutiedot =
2480+
listOf(
2481+
VardaReadClient.MaksutietoResponse(
2482+
url = old.maksutietoToDeleteUrl,
2483+
lapsi = lapsiUrl,
2484+
lahdejarjestelma = old.sourceSystem,
2485+
alkamis_pvm = old.start,
2486+
paattymis_pvm = null,
2487+
perheen_koko = 2,
2488+
maksun_peruste_koodi = "MP03",
2489+
asiakasmaksu = 10.0,
2490+
palveluseteli_arvo = 0.0,
2491+
huoltajat =
2492+
listOf(
2493+
Huoltaja(
2494+
henkilotunnus = null,
2495+
henkilo_oid = "huoltaja_oid_1",
2496+
etunimet = "Test",
2497+
sukunimi = "Person",
2498+
)
2499+
),
2500+
)
2501+
),
2502+
)
2503+
),
2504+
)
2505+
2506+
val evakaHenkilo =
2507+
VardaUpdater.EvakaHenkiloNode(
2508+
henkilo =
2509+
Henkilo(
2510+
etunimet = "Test",
2511+
sukunimi = "Person",
2512+
henkilo_oid = null,
2513+
henkilotunnus = "030320A904N",
2514+
),
2515+
lapset =
2516+
listOf(
2517+
VardaUpdater.EvakaLapsiNode(
2518+
lapsi =
2519+
Lapsi(
2520+
vakatoimija_oid = new.organizerOid,
2521+
oma_organisaatio_oid = null,
2522+
paos_organisaatio_oid = null,
2523+
),
2524+
varhaiskasvatuspaatokset =
2525+
listOf(
2526+
varhaiskasvatuspaatos(
2527+
new.unitOid,
2528+
new.range,
2529+
hakemus_pvm = new.applicationDate,
2530+
)
2531+
),
2532+
maksutiedot = listOf(maksutieto(new.range)),
2533+
)
2534+
),
2535+
)
2536+
2537+
val client = DryRunClient()
2538+
val updater =
2539+
VardaUpdater(DateRange(new.range.start, null), new.organizerOid, new.sourceSystem)
2540+
2541+
updater.diffAndUpdate(client, vardaHenkilo, evakaHenkilo)
2542+
2543+
val dayBeforeEvaka = new.range.start.minusDays(1)
2544+
assertEquals(
2545+
listOf(
2546+
"Delete" to old.maksutietoToDeleteUrl,
2547+
"SetPaattymisPvm" to
2548+
(old.varhaiskasvatusSuhdeToEndUrl to
2549+
VardaWriteClient.SetPaattymisPvmRequest(old.sourceSystem, dayBeforeEvaka)),
2550+
"SetPaattymisPvm" to
2551+
(old.varhaiskasvatusPaatosToEndUrl to
2552+
VardaWriteClient.SetPaattymisPvmRequest(old.sourceSystem, dayBeforeEvaka)),
2553+
"Create" to
2554+
VardaWriteClient.CreateLapsiRequest(
2555+
lahdejarjestelma = new.sourceSystem,
2556+
henkilo = URI.create("henkilo"),
2557+
vakatoimija_oid = new.organizerOid,
2558+
oma_organisaatio_oid = null,
2559+
paos_organisaatio_oid = null,
2560+
),
2561+
"Create" to
2562+
VardaWriteClient.CreateVarhaiskasvatuspaatosRequest(
2563+
lapsi = URI.create("lapsi_0"),
2564+
hakemus_pvm = new.applicationDate,
2565+
alkamis_pvm = new.range.start,
2566+
paattymis_pvm = new.range.end,
2567+
tuntimaara_viikossa = 35.0,
2568+
kokopaivainen_vaka_kytkin = true,
2569+
tilapainen_vaka_kytkin = false,
2570+
paivittainen_vaka_kytkin = true,
2571+
vuorohoito_kytkin = false,
2572+
jarjestamismuoto_koodi = "jm01",
2573+
lahdejarjestelma = new.sourceSystem,
2574+
),
2575+
"Create" to
2576+
VardaWriteClient.CreateVarhaiskasvatussuhdeRequest(
2577+
lahdejarjestelma = new.sourceSystem,
2578+
varhaiskasvatuspaatos = URI.create("varhaiskasvatuspaatos_0"),
2579+
toimipaikka_oid = new.unitOid,
2580+
alkamis_pvm = new.range.start,
2581+
paattymis_pvm = new.range.end,
2582+
),
2583+
"Create" to
2584+
VardaWriteClient.CreateMaksutietoRequest(
2585+
lahdejarjestelma = new.sourceSystem,
2586+
huoltajat =
2587+
listOf(
2588+
Huoltaja(
2589+
henkilotunnus = "070644-937X",
2590+
henkilo_oid = null,
2591+
etunimet = "Test",
2592+
sukunimi = "Person",
2593+
)
2594+
),
2595+
lapsi = URI.create("lapsi_0"),
2596+
alkamis_pvm = new.range.start,
2597+
paattymis_pvm = new.range.end,
2598+
maksun_peruste_koodi = "MP03",
2599+
palveluseteli_arvo = 0.0,
2600+
asiakasmaksu = 0.0,
2601+
perheen_koko = 2,
2602+
),
2603+
),
2604+
client.operations,
2605+
)
2606+
}
2607+
23972608
@Test
23982609
fun `write to varda - data created with different source system is not deleted`() {
23992610
val otherSourceSystem = "otherSourceSystem"

service/src/main/kotlin/fi/espoo/evaka/varda/new/VardaUpdateServiceNew.kt

+27-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ import org.springframework.stereotype.Service
2727

2828
private val logger = KotlinLogging.logger {}
2929

30+
// TODO: testit tarvitaan
31+
32+
/**
33+
* Data before this date is not sent to Varda. This is Varda's internal validation rule that must be
34+
* followed.
35+
*/
36+
val VARDA_START_DATE: LocalDate = LocalDate.of(2019, 1, 1)
37+
38+
/**
39+
* Fee data before this date is not sent to Varda. This is Varda's internal validation rule that
40+
* must be followed.
41+
*/
42+
val VARDA_FEE_START_DATE: LocalDate = LocalDate.of(2019, 9, 1)
43+
3044
@Service
3145
class VardaUpdateServiceNew(
3246
private val asyncJobRunner: AsyncJobRunner<AsyncJob>,
@@ -88,15 +102,11 @@ class VardaUpdateServiceNew(
88102
VardaClient(httpClient, jsonMapper, vardaEnv.url, vardaEnv.basicAuth.value)
89103

90104
private val vardaEnabledRange =
91-
DateRange(
92-
// 2019-01-01 was the hard-coded cutoff date of the old Varda integration
93-
vardaEnv.startDate ?: LocalDate.of(2019, 1, 1),
94-
vardaEnv.endDate,
95-
)
105+
DateRange(vardaEnv.startDate ?: VARDA_START_DATE, vardaEnv.endDate)
96106

97107
init {
98-
check(vardaEnabledRange.start >= LocalDate.of(2019, 1, 1)) {
99-
"Varda enabled range must start after 2019-01-01"
108+
check(vardaEnabledRange.start >= VARDA_START_DATE) {
109+
"Varda enabled range must start after $VARDA_START_DATE"
100110
}
101111
asyncJobRunner.registerHandler(::updateChildJob)
102112
}
@@ -279,9 +289,9 @@ class VardaUpdater(
279289
return null
280290
}
281291

282-
// Only fee data after 2019-09-01 can be sent to Varda (error code MA019)
292+
// Only fee data after VARDA_FEE_START_DATE can be sent to Varda (error code MA019)
283293
val vardaFeeDataRange =
284-
vardaEnabledRange.intersection(DateRange(LocalDate.of(2019, 9, 1), null))
294+
vardaEnabledRange.intersection(DateRange(VARDA_FEE_START_DATE, null))
285295

286296
val evakaLapsiServiceNeeds =
287297
serviceNeeds
@@ -593,9 +603,14 @@ class VardaUpdater(
593603
entity: VardaEntityWithValidity,
594604
endDate: LocalDate,
595605
) {
596-
if (endDate < LocalDate.of(2019, 1, 1)) {
597-
// Delete old entries that would be set to end before 2019-01-01, because sending data
598-
// before 2019-01-01 is not supported by Varda (error MI021)
606+
val earliestValidEndDate =
607+
when (entity) {
608+
is VardaReadClient.MaksutietoResponse -> VARDA_FEE_START_DATE
609+
else -> VARDA_START_DATE
610+
}
611+
if (endDate < earliestValidEndDate) {
612+
// Delete old entries that would be set to end before the data type's earliest valid end
613+
// date. Sending too old data is prohibited by Varda (e.g. errors MA019, MI021).
599614
this.delete(entity)
600615
} else if (entity.alkamis_pvm > endDate) {
601616
this.delete(entity)

0 commit comments

Comments
 (0)