Skip to content

Commit

Permalink
Add test and tag in log sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitenok committed Dec 17, 2024
1 parent 6f4c48d commit 410db3f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/no/nav/syfo/db/UtsendtVarselDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<PUtsendtVarsel> {
val queryStatement = """SELECT *
FROM UTSENDT_VARSEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

5 changes: 4 additions & 1 deletion src/main/kotlin/no/nav/syfo/service/SenderFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
})

0 comments on commit 410db3f

Please sign in to comment.