Skip to content

Commit

Permalink
IS-2244: Migrate from using isdialogmotepdfgen to ispdfgen (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
vetlesolgaard authored Apr 4, 2024
1 parent 7509992 commit 5d6712f
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: isdialogmotepdfgen
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
- application: syfobehandlendeenhet
Expand Down
2 changes: 1 addition & 1 deletion .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ spec:
- application: digdir-krr-proxy
namespace: team-rocket
- application: isdialogmote-redis
- application: isdialogmotepdfgen
- application: ispdfgen
- application: isnarmesteleder
- application: isoppfolgingstilfelle
- application: syfobehandlendeenhet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data class Environment(
val eregUrl: String = getEnvVar("EREG_URL"),
val sidecarInitialDelay: Long = getEnvVar("SIDECAR_INITIAL_DELAY", "30000").toLong(),
val dokarkivUrl: String = getEnvVar("DOKARKIV_URL"),
val isdialogmotepdfgenUrl: String = "http://isdialogmotepdfgen",
val ispdfgenUrl: String = "http://ispdfgen",
val krrClientId: String = getEnvVar("KRR_CLIENT_ID"),
val krrUrl: String = getEnvVar("KRR_URL"),
val syfobehandlendeenhetClientId: String = getEnvVar("SYFOBEHANDLENDEENHET_CLIENT_ID"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/syfo/application/api/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fun Application.apiModule(
cache = cache,
)
val pdfGenClient = PdfGenClient(
pdfGenBaseUrl = environment.isdialogmotepdfgenUrl
pdfGenBaseUrl = environment.ispdfgenUrl
)
val veilederTilgangskontrollClient = VeilederTilgangskontrollClient(
azureAdV2Client = azureAdV2Client,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package no.nav.syfo.client.pdfgen

import no.nav.syfo.dialogmote.domain.DocumentComponentDTO

data class DialogmoteHendelsePdfContent(
val documentComponents: List<DocumentComponentDTO>,
)
27 changes: 9 additions & 18 deletions src/main/kotlin/no/nav/syfo/client/pdfgen/PdfGenClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,8 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory

class PdfGenClient(
pdfGenBaseUrl: String
private val pdfGenBaseUrl: String
) {
private val avlysningUrl: String
private val endringTidStedUrl: String
private val innkallingUrl: String
private val referatUrl: String

init {
this.avlysningUrl = "$pdfGenBaseUrl$AVLYSNING_PATH"
this.endringTidStedUrl = "$pdfGenBaseUrl$ENDRING_TIDSTED_PATH"
this.innkallingUrl = "$pdfGenBaseUrl$INNKALLING_PATH"
this.referatUrl = "$pdfGenBaseUrl$REFERAT_PATH"
}

private val httpClient = httpClientDefault()

Expand All @@ -37,7 +26,7 @@ class PdfGenClient(
return getPdf(
callId = callId,
documentComponentDTOList = documentComponentDTOList,
pdfUrl = avlysningUrl,
pdfUrl = "$pdfGenBaseUrl$AVLYSNING_PATH",
)
}

Expand All @@ -48,7 +37,7 @@ class PdfGenClient(
return getPdf(
callId = callId,
documentComponentDTOList = documentComponentDTOList,
pdfUrl = endringTidStedUrl,
pdfUrl = "$pdfGenBaseUrl$ENDRING_TIDSTED_PATH",
)
}

Expand All @@ -59,7 +48,7 @@ class PdfGenClient(
return getPdf(
callId = callId,
documentComponentDTOList = documentComponentDTOList,
pdfUrl = innkallingUrl,
pdfUrl = "$pdfGenBaseUrl$INNKALLING_PATH",
)
}

Expand All @@ -70,7 +59,7 @@ class PdfGenClient(
return getPdf(
callId = callId,
documentComponentDTOList = documentComponentDTOList,
pdfUrl = referatUrl,
pdfUrl = "$pdfGenBaseUrl$REFERAT_PATH",
)
}

Expand All @@ -80,11 +69,13 @@ class PdfGenClient(
pdfUrl: String,
): ByteArray? {
return try {
val requestBody =
DialogmoteHendelsePdfContent(documentComponents = documentComponentDTOList.sanitizeForPdfGen())
val response: HttpResponse = httpClient.post(pdfUrl) {
header(NAV_CALL_ID_HEADER, callId)
accept(ContentType.Application.Json)
contentType(ContentType.Application.Json)
setBody(documentComponentDTOList.sanitizeForPdfGen())
setBody(requestBody)
}
COUNT_CALL_PDFGEN_SUCCESS.increment()
response.body()
Expand All @@ -101,7 +92,7 @@ class PdfGenClient(
callId: String,
): ByteArray? {
log.error(
"Error while requesting PDF from Isdialogmotepdfgen with {}, {}, {}",
"Error while requesting PDF from ispdfgen with {}, {}, {}",
StructuredArguments.keyValue("statusCode", response.status.value.toString()),
StructuredArguments.keyValue("url", url),
callIdArgument(callId)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/syfo/client/pdfgen/PdfgenMetric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import io.micrometer.core.instrument.Counter
import no.nav.syfo.metric.METRICS_NS
import no.nav.syfo.metric.METRICS_REGISTRY

const val CALL_PDFGEN_BASE = "${METRICS_NS}_call_isdialogmotepdfgen"
const val CALL_PDFGEN_BASE = "${METRICS_NS}_call_ispdfgen"

const val CALL_PDFGEN_SUCCESS = "${CALL_PDFGEN_BASE}_success_count"
const val CALL_PDFGEN_FAIL = "${CALL_PDFGEN_BASE}_fail_count"

val COUNT_CALL_PDFGEN_SUCCESS: Counter = Counter
.builder(CALL_PDFGEN_SUCCESS)
.description("Counts the number of successful calls to Isdialogmotepdfgen")
.description("Counts the number of successful calls to ispdfgen")
.register(METRICS_REGISTRY)
val COUNT_CALL_PDFGEN_FAIL: Counter = Counter
.builder(CALL_PDFGEN_FAIL)
.description("Counts the number of failed calls to Isdialogmotepdfgen")
.description("Counts the number of failed calls to ispdfgen")
.register(METRICS_REGISTRY)
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ package no.nav.syfo.brev.arbeidstaker

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.*
import io.ktor.http.HttpHeaders.Authorization
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.setBody
import io.ktor.server.testing.*
import io.mockk.*
import java.time.LocalDateTime
import java.util.*
import kotlinx.coroutines.runBlocking
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
Expand Down Expand Up @@ -56,6 +49,8 @@ import org.spekframework.spek2.style.specification.describe
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import java.time.LocalDateTime
import java.util.*

class ArbeidstakerBrevApiSpek : Spek({
val objectMapper: ObjectMapper = configuredJacksonMapper()
Expand Down Expand Up @@ -696,7 +691,7 @@ class ArbeidstakerBrevApiSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfInnkalling
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfInnkalling
}
val urlPdfForReferatNedlasting =
"$arbeidstakerBrevApiPath/$createdReferatArbeidstakerBrevUUID$arbeidstakerBrevApiPdfPath"
Expand All @@ -707,7 +702,7 @@ class ArbeidstakerBrevApiSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfReferat
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat
}
}
}
Expand Down Expand Up @@ -842,7 +837,7 @@ class ArbeidstakerBrevApiSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfInnkalling
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfInnkalling
}

val urlPdfForReferatNedlasting =
Expand All @@ -861,7 +856,7 @@ class ArbeidstakerBrevApiSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfReferat
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ package no.nav.syfo.brev.narmesteleder

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.setBody
import io.ktor.http.*
import io.ktor.server.testing.*
import io.mockk.*
import java.time.LocalDateTime
import java.util.*
import kotlinx.coroutines.runBlocking
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
Expand Down Expand Up @@ -59,6 +52,8 @@ import org.spekframework.spek2.style.specification.describe
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import java.time.LocalDateTime
import java.util.*

object NarmesteLederBrevSpek : Spek({
val objectMapper: ObjectMapper = configuredJacksonMapper()
Expand Down Expand Up @@ -331,7 +326,7 @@ object NarmesteLederBrevSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfInnkalling
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfInnkalling
}
val urlMoteUUIDReferat =
"$dialogmoteApiV2Basepath/$createdDialogmoteUUID$dialogmoteApiMoteFerdigstillPath"
Expand Down Expand Up @@ -428,7 +423,7 @@ object NarmesteLederBrevSpek : Spek({
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val pdfContent = response.byteContent!!
pdfContent shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfReferat
pdfContent shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat
}
val urlMoteUUIDEndreReferat =
"$dialogmoteApiV2Basepath/$createdDialogmoteUUID$dialogmoteApiMoteEndreFerdigstiltPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ package no.nav.syfo.dialogmote.api.v2

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.*
import io.ktor.http.HttpHeaders.Authorization
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.setBody
import io.ktor.server.testing.*
import io.mockk.*
import java.time.LocalDate
import java.util.*
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
import no.altinn.services.serviceengine.correspondence._2009._10.ICorrespondenceAgencyExternalBasic
Expand All @@ -39,6 +32,8 @@ import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBe
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.time.LocalDate
import java.util.*

class FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({
val objectMapper: ObjectMapper = configuredJacksonMapper()
Expand Down Expand Up @@ -182,7 +177,7 @@ class FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({

val pdf =
pdfService.getPdf(database.getReferat(UUID.fromString(referat.uuid)).first().pdfId!!)
pdf shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfReferat
pdf shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat

val moteStatusEndretList = database.getMoteStatusEndretNotPublished()
moteStatusEndretList.size shouldBeEqualTo 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ package no.nav.syfo.dialogmote.api.v2

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.*
import io.ktor.http.HttpHeaders.Authorization
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.ktor.server.testing.setBody
import io.ktor.server.testing.*
import io.mockk.*
import java.util.*
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptExternal
import no.altinn.schemas.services.intermediary.receipt._2009._10.ReceiptStatusEnum
import no.altinn.services.serviceengine.correspondence._2009._10.ICorrespondenceAgencyExternalBasic
Expand Down Expand Up @@ -42,6 +36,7 @@ import org.amshove.kluent.shouldContain
import org.amshove.kluent.shouldNotBeEqualTo
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.util.*

class FerdigstillDialogmoteApiV2Spek : Spek({

Expand Down Expand Up @@ -163,7 +158,7 @@ class FerdigstillDialogmoteApiV2Spek : Spek({

val pdf =
pdfService.getPdf(database.getReferat(UUID.fromString(referat.uuid)).first().pdfId!!)
pdf shouldBeEqualTo externalMockEnvironment.isdialogmotepdfgenMock.pdfReferat
pdf shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat

val moteStatusEndretList = database.getMoteStatusEndretNotPublished()
moteStatusEndretList.size shouldBeEqualTo 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.ktor.server.netty.*
import no.nav.common.KafkaEnvironment
import no.nav.syfo.application.ApplicationState
import no.nav.syfo.testhelper.mock.*
import java.util.*

class ExternalMockEnvironment private constructor() {
val applicationState: ApplicationState = testAppState()
Expand All @@ -13,7 +14,7 @@ class ExternalMockEnvironment private constructor() {
val tokendingsMock = TokendingsMock()
val dokarkivMock = DokarkivMock()
val pdlMock = PdlMock()
val isdialogmotepdfgenMock = IsdialogmotepdfgenMock()
val ispdfgenMock = ispdfgenMock()
val isoppfolgingstilfelleMock = IsoppfolgingstilfelleMock()
val eregMock = EregMock()
val krrMock = KrrMock()
Expand All @@ -25,7 +26,7 @@ class ExternalMockEnvironment private constructor() {
azureAdV2Mock.name to azureAdV2Mock.server,
tokendingsMock.name to tokendingsMock.server,
dokarkivMock.name to dokarkivMock.server,
isdialogmotepdfgenMock.name to isdialogmotepdfgenMock.server,
ispdfgenMock.name to ispdfgenMock.server,
isoppfolgingstilfelleMock.name to isoppfolgingstilfelleMock.server,
eregMock.name to eregMock.server,
krrMock.name to krrMock.server,
Expand All @@ -40,7 +41,7 @@ class ExternalMockEnvironment private constructor() {
azureTokenEndpoint = azureAdV2Mock.url,
tokenxEndpoint = tokendingsMock.url,
dokarkivUrl = dokarkivMock.url,
isdialogmotepdfgenUrl = isdialogmotepdfgenMock.url,
ispdfgenUrl = ispdfgenMock.url,
isoppfolgingstilfelleUrl = isoppfolgingstilfelleMock.url,
eregUrl = eregMock.url,
krrUrl = krrMock.url,
Expand Down
9 changes: 6 additions & 3 deletions src/test/kotlin/no/nav/syfo/testhelper/TestEnvironment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package no.nav.syfo.testhelper

import no.nav.syfo.application.*
import io.ktor.utils.io.core.*
import no.nav.syfo.application.ApplicationEnvironmentKafka
import no.nav.syfo.application.ApplicationState
import no.nav.syfo.application.Environment
import java.net.ServerSocket
import java.time.LocalDate

Expand All @@ -9,7 +12,7 @@ fun testEnvironment(
dokarkivUrl: String = "http://dokarkiv",
azureTokenEndpoint: String = "azureTokenEndpoint",
tokenxEndpoint: String = "tokenxEndpoint",
isdialogmotepdfgenUrl: String? = null,
ispdfgenUrl: String? = null,
isoppfolgingstilfelleUrl: String = "isoppfolgingstilfelle",
eregUrl: String = "ereg",
krrUrl: String = "krr",
Expand Down Expand Up @@ -51,7 +54,7 @@ fun testEnvironment(
isdialogmoteDbUsername = "username",
isdialogmoteDbPassword = "password",
dokarkivUrl = dokarkivUrl,
isdialogmotepdfgenUrl = isdialogmotepdfgenUrl ?: "http://isdialogmotepdfgen",
ispdfgenUrl = ispdfgenUrl ?: "http://ispdfgen",
krrClientId = "dev-gcp.team-rocket.digdir-krr-proxy",
krrUrl = krrUrl,
syfobehandlendeenhetClientId = "syfobehandlendeenhetClientId",
Expand Down
Loading

0 comments on commit 5d6712f

Please sign in to comment.