Skip to content

Commit

Permalink
Invalid message if vedlegg over 300 MB
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk committed Oct 24, 2023
1 parent e476591 commit e8aacd4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package no.nav.syfo.application
import java.io.StringReader
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.util.UUID
import java.util.*
import javax.jms.MessageConsumer
import javax.jms.MessageProducer
import javax.jms.TextMessage
Expand Down Expand Up @@ -32,6 +32,7 @@ import no.nav.syfo.handlestatus.handleStatusINVALID
import no.nav.syfo.handlestatus.handleStatusMANUALPROCESSING
import no.nav.syfo.handlestatus.handleStatusOK
import no.nav.syfo.handlestatus.handleVedleggContainsVirus
import no.nav.syfo.handlestatus.handleVedleggOver300MB
import no.nav.syfo.handlestatus.handleVirksomhetssykmeldingOgFnrManglerIHPR
import no.nav.syfo.handlestatus.handleVirksomhetssykmeldingOgHprMangler
import no.nav.syfo.logger
Expand All @@ -50,6 +51,7 @@ import no.nav.syfo.model.toSykmelding
import no.nav.syfo.pdl.service.PdlPersonService
import no.nav.syfo.service.DuplicationService
import no.nav.syfo.service.VirusScanService
import no.nav.syfo.service.fileSizeLagerThan300MegaBytes
import no.nav.syfo.service.sha256hashstring
import no.nav.syfo.util.LoggingMeta
import no.nav.syfo.util.checkSM2013Content
Expand Down Expand Up @@ -419,6 +421,28 @@ class BlockingApplicationRunner(
}

if (vedlegg.isNotEmpty()) {
val vedleggOver300MegaByte =
vedlegg.filter {
fileSizeLagerThan300MegaBytes(
Base64.getMimeDecoder().decode(it.content.content)
)
}

if (vedleggOver300MegaByte.isNotEmpty()) {
handleVedleggOver300MB(
loggingMeta,
fellesformat,
ediLoggId,
msgId,
msgHead,
env,
kafkaproducerApprec,
duplicationService,
duplicateCheck,
)
continue@loop
}

if (virusScanService.vedleggContainsVirus(vedlegg)) {
handleVedleggContainsVirus(
loggingMeta,
Expand Down
34 changes: 34 additions & 0 deletions src/main/kotlin/no/nav/syfo/handlestatus/HandleStatusInvalid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import no.nav.syfo.metrics.INVALID_MESSAGE_NO_NOTICE
import no.nav.syfo.metrics.SYKMELDING_AVVIST_DUPLIKCATE_COUNTER
import no.nav.syfo.metrics.SYKMELDING_AVVIST_VIRUS_VEDLEGG_COUNTER
import no.nav.syfo.metrics.TEST_FNR_IN_PROD
import no.nav.syfo.metrics.VEDLEGG_AVVIST_OVER_300_MEGABYTE_COUNTER
import no.nav.syfo.model.ReceivedSykmelding
import no.nav.syfo.model.ValidationResult
import no.nav.syfo.sendReceipt
Expand Down Expand Up @@ -713,6 +714,39 @@ fun handleBehandletDatoMangler(
)
}

fun handleVedleggOver300MB(
loggingMeta: LoggingMeta,
fellesformat: XMLEIFellesformat,
ediLoggId: String,
msgId: String,
msgHead: XMLMsgHead,
env: EnvironmentVariables,
kafkaproducerApprec: KafkaProducer<String, Apprec>,
duplicationService: DuplicationService,
duplicateCheck: DuplicateCheck,
) {
logger.warn(
"Sykmelding er avvist fordi eit eller flere vedlegg er over 300 MB {} {}",
fields(loggingMeta),
keyValue("avvistAv", env.applicationName),
)

val apprec =
fellesformatToAppprec(
fellesformat,
"Sykmeldingen kan ikke rettes, det må skrives en ny." +
"Pasienten har ikke fått beskjed, men venter på ny sykmelding fra deg. Grunnet følgende:" +
"Eit eller flere vedlegg er over 300 MB",
ediLoggId,
msgId,
msgHead,
)

VEDLEGG_AVVIST_OVER_300_MEGABYTE_COUNTER.inc()

sendApprec(apprec, env, kafkaproducerApprec, loggingMeta, duplicationService, duplicateCheck)
}

fun handleVedleggContainsVirus(
loggingMeta: LoggingMeta,
fellesformat: XMLEIFellesformat,
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/no/nav/syfo/metrics/MetricRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ val VEDLEGG_OVER_300_MEGABYTE_COUNTER: Counter =
.help("Number of vedleggs that is over 300 megabyte")
.register()

val VEDLEGG_AVVIST_OVER_300_MEGABYTE_COUNTER: Counter =
Counter.build()
.namespace(METRICS_NS)
.name("vedlegg_avvist_over_300_megabyte")
.help("Number of avvist due to vedlegg is over 300 megabyte")
.register()

val SYKMELDING_AVVIST_VIRUS_VEDLEGG_COUNTER: Counter =
Counter.build()
.namespace(METRICS_NS)
Expand Down

0 comments on commit e8aacd4

Please sign in to comment.