From 410db3f66d50c5a0ce94ed2cdf6b526db108abf4 Mon Sep 17 00:00:00 2001 From: Tanja Krasnomovets Date: Tue, 17 Dec 2024 08:46:34 +0100 Subject: [PATCH] Add test and tag in log sentence --- .../kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt | 17 +++++++++++++++++ .../job/SendForcedAktivitetspliktLetterJob.kt | 4 ++-- .../syfo/service/FysiskBrevUtsendingService.kt | 2 +- .../kotlin/no/nav/syfo/service/SenderFacade.kt | 5 ++++- .../nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt | 13 +++++++++---- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt b/src/main/kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt index 705432137..ff73d3542 100644 --- a/src/main/kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt +++ b/src/main/kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt @@ -73,6 +73,23 @@ fun DatabaseInterface.fetchAlleUferdigstilteAktivitetspliktVarsler( } } +fun DatabaseInterface.setUferdigstiltUtsendtVarselToForcedLEtter(eksternRef: String): Int { + val updateStatement = """UPDATE UTSENDT_VARSEL + SET is_forced_letter = ? + WHERE EKSTERN_REF = ? + """.trimMargin() + + return connection.use { connection -> + val rowsUpdated = connection.prepareStatement(updateStatement).use { + it.setBoolean(1, true) + it.setString(2, eksternRef) + it.executeUpdate() + } + connection.commit() + rowsUpdated + } +} + fun DatabaseInterface.fetchUtsendtVarselByFnr(fnr: String): List { val queryStatement = """SELECT * FROM UTSENDT_VARSEL diff --git a/src/main/kotlin/no/nav/syfo/job/SendForcedAktivitetspliktLetterJob.kt b/src/main/kotlin/no/nav/syfo/job/SendForcedAktivitetspliktLetterJob.kt index 6a2e08755..9ca436f23 100644 --- a/src/main/kotlin/no/nav/syfo/job/SendForcedAktivitetspliktLetterJob.kt +++ b/src/main/kotlin/no/nav/syfo/job/SendForcedAktivitetspliktLetterJob.kt @@ -22,7 +22,7 @@ class SendForcedAktivitetspliktLetterJob(private val db: DatabaseInterface, priv unreadVarslerOverdude.forEach { pUtsendtVarsel -> if (pUtsendtVarsel.eksternReferanse.isNullOrBlank()) { - log.error("User can not be notified by letter due to missing journalpostId: ${pUtsendtVarsel.eksternReferanse}") + log.error("[FORCED PHYSICAL PRINT]: User can not be notified by letter due to missing journalpostId: ${pUtsendtVarsel.eksternReferanse}") } else { senderFacade.sendForcedBrevTilFysiskPrint( uuid = pUtsendtVarsel.uuid, @@ -39,7 +39,7 @@ class SendForcedAktivitetspliktLetterJob(private val db: DatabaseInterface, priv } sentForcedLettersAmount++ } - log.info("SendForcedAktivitetspliktLetterJob sent ${sentForcedLettersAmount} forced letters") + log.info("[FORCED PHYSICAL PRINT]: SendForcedAktivitetspliktLetterJob sent ${sentForcedLettersAmount} forced letters") return sentForcedLettersAmount } diff --git a/src/main/kotlin/no/nav/syfo/service/FysiskBrevUtsendingService.kt b/src/main/kotlin/no/nav/syfo/service/FysiskBrevUtsendingService.kt index e41283b96..bae17c9fd 100644 --- a/src/main/kotlin/no/nav/syfo/service/FysiskBrevUtsendingService.kt +++ b/src/main/kotlin/no/nav/syfo/service/FysiskBrevUtsendingService.kt @@ -32,7 +32,7 @@ class FysiskBrevUtsendingService( uuid, distribusjonsType ).bestillingsId - log.info("Sendte tvunget brev til print, bestillingsId er $bestillingsId, varsel med UUID: $uuid") + log.info("[FORCED PHYSICAL PRINT]: Sent forced letter to physical print, bestillingsId is $bestillingsId, varsel with UUID: $uuid") } } diff --git a/src/main/kotlin/no/nav/syfo/service/SenderFacade.kt b/src/main/kotlin/no/nav/syfo/service/SenderFacade.kt index 2866257ce..5f406e335 100644 --- a/src/main/kotlin/no/nav/syfo/service/SenderFacade.kt +++ b/src/main/kotlin/no/nav/syfo/service/SenderFacade.kt @@ -14,6 +14,7 @@ import no.nav.syfo.db.domain.Kanal.DITT_SYKEFRAVAER import no.nav.syfo.db.domain.PUtsendtVarsel import no.nav.syfo.db.domain.PUtsendtVarselFeilet import no.nav.syfo.db.fetchUferdigstilteVarsler +import no.nav.syfo.db.setUferdigstiltUtsendtVarselToForcedLEtter import no.nav.syfo.db.setUtsendtVarselToFerdigstilt import no.nav.syfo.db.storeUtsendtVarsel import no.nav.syfo.db.storeUtsendtVarselFeilet @@ -271,7 +272,7 @@ class SenderFacade( fysiskBrevUtsendingService.sendForcedBrev(uuid, journalpostId, distribusjonsType) } catch (e: Exception) { isSendingSucceed = false - log.warn("Error while sending forced brev til forced fysisk print: ${e.message}") + log.warn("[FORCED PHYSICAL PRINT]: Error while sending forced brev til forced fysisk print: ${e.message}") lagreIkkeUtsendtArbeidstakerVarsel( kanal = BREV, varselHendelse = varselHendelse, @@ -283,7 +284,9 @@ class SenderFacade( ) } if (isSendingSucceed) { + log.info("[FORCED PHYSICAL PRINT]: sending forced physical letter with journalpostId ${journalpostId} succeded, storing in database") lagreUtsendtArbeidstakerVarsel(BREV, varselHendelse, uuid, isForcedLetter = true) + database.setUferdigstiltUtsendtVarselToForcedLEtter(eksternRef = uuid) } } diff --git a/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt index 2328fac73..1a9559a81 100644 --- a/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt @@ -17,9 +17,10 @@ class UtsendtVarselFeiletDAOSpek : DescribeSpec({ } it("Returns 3 varsler") { + val uuidToTest = UUID.randomUUID().toString() val utsendtVarsel1 = // skal sendes PUtsendtVarsel( - uuid = UUID.randomUUID().toString(), + uuid = uuidToTest, fnr = no.nav.syfo.planner.arbeidstakerFnr1, aktorId = arbeidstakerAktorId1, narmesteLederFnr = null, @@ -107,10 +108,14 @@ class UtsendtVarselFeiletDAOSpek : DescribeSpec({ embeddedDatabase.storeUtsendtVarsel(utsendtVarsel4) embeddedDatabase.storeUtsendtVarsel(utsendtVarsel5) - val result = embeddedDatabase.fetchAlleUferdigstilteAktivitetspliktVarsler().size - // val result = job.sendForcedLetterFromJob() + val result = embeddedDatabase.fetchAlleUferdigstilteAktivitetspliktVarsler() + result.size shouldBeEqualTo 3 + - result shouldBeEqualTo 3 + // Should not pick original uferdigstilt utsend varsel to notify user by physical letter for the second time + embeddedDatabase.setUferdigstiltUtsendtVarselToForcedLEtter(eksternRef = "123") + val result2 = embeddedDatabase.fetchAlleUferdigstilteAktivitetspliktVarsler() + result2.size shouldBeEqualTo 2 } } })