@@ -5,7 +5,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper
5
5
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
6
6
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7
7
import com.fasterxml.jackson.module.kotlin.readValue
8
- import io.ktor.client.request.request
9
8
import io.ktor.http.HttpStatusCode
10
9
import io.ktor.server.application.ApplicationCall
11
10
import io.ktor.server.application.call
@@ -41,9 +40,21 @@ internal fun Route.ordrelinjeAPI(context: Context) {
41
40
post(" /push" ) {
42
41
logg.info(" incoming push" )
43
42
try {
44
- val ordrelinje = parseOrdrelinje(context, call) ? : return @post
43
+ // Parse innkommende json/xml
44
+ val ordrelinje = parseOrdrelinje(context, call) ? :
45
+ return @post call.respond(HttpStatusCode .BadRequest , " request body was not in a valid format" )
46
+
47
+ // Vi deler alle typer ordrelinjer med kommune-apiet
45
48
sendUvalidertOrdrelinjeTilRapid(context, ordrelinje.toRåOrdrelinje ())
46
- validerOrdrelinje(context, ordrelinje)
49
+
50
+ // Avslutt tidlig hvis ordrelinjen ikke er relevant for oss
51
+ if (! erOrdrelinjeRelevantForOss(context, ordrelinje)) {
52
+ logg.info(" Urelevant ordrelinje mottatt og ignorert" )
53
+ call.respond(HttpStatusCode .OK )
54
+ return @post
55
+ }
56
+
57
+ // Anti-corruption lag
47
58
val melding = if (ordrelinje.erOpprettetFraHOTSAK()) {
48
59
parseHotsakOrdrelinje(context, ordrelinje)
49
60
context.metrics.hotsakSF()
@@ -54,15 +65,13 @@ internal fun Route.ordrelinjeAPI(context: Context) {
54
65
opprettInfotrygdOrdrelinje(ordrelinje)
55
66
}
56
67
68
+ // Publiser resultat
57
69
publiserMelding(context, ordrelinje, melding)
58
70
call.respond(HttpStatusCode .OK )
59
- } catch (e: RapidsAndRiverException ) {
60
- logg.error(e) { " Feil under prosessering" }
61
- call.respond(HttpStatusCode .InternalServerError , " Feil under prosessering" )
62
- return @post
63
- } catch (e: RuntimeException ) {
64
- logg.error(e) { " Feil under prosessering" }
65
- call.respond(HttpStatusCode .OK )
71
+
72
+ } catch (e: Exception ) {
73
+ logg.error(e) { " Uventet feil under prosessering" }
74
+ call.respond(HttpStatusCode .InternalServerError )
66
75
return @post
67
76
}
68
77
}
@@ -77,7 +86,13 @@ private suspend fun parseOrdrelinje(context: Context, call: ApplicationCall): Or
77
86
val requestBody: String = call.receiveText()
78
87
context.metrics.meldingFraOebs()
79
88
if (Configuration .profile != Configuration .Profile .PROD ) {
80
- sikkerlogg.info(" Received $incomingFormatType push request from OEBS: $requestBody " )
89
+ withLoggingContext(
90
+ mapOf (
91
+ " requestBody" to requestBody,
92
+ )
93
+ ) {
94
+ sikkerlogg.info(" Received $incomingFormatType push request from OEBS" )
95
+ }
81
96
}
82
97
83
98
// Check for valid json request
@@ -90,32 +105,26 @@ private suspend fun parseOrdrelinje(context: Context, call: ApplicationCall): Or
90
105
}.fiksTommeSerienumre()
91
106
92
107
if (Configuration .profile != Configuration .Profile .PROD ) {
93
- sikkerlogg.info (
94
- " Parsing incoming $incomingFormatType request successful: ${
95
- mapperJson.writeValueAsString(
96
- ordrelinje
97
- )
98
- } "
99
- )
108
+ withLoggingContext (
109
+ mapOf (
110
+ " ordrelinje " to mapperJson.writeValueAsString(ordrelinje),
111
+ )
112
+ ) {
113
+ sikkerlogg.info( " Parsing incoming $incomingFormatType request successful " )
114
+ }
100
115
}
101
116
context.metrics.oebsParsingOk()
102
117
return ordrelinje
103
118
} catch (e: Exception ) {
104
119
// Deal with invalid json/xml in request
105
120
withLoggingContext(
106
121
mapOf (
107
- " rawRequestBody " to requestBody,
122
+ " requestBody " to requestBody,
108
123
)
109
124
) {
110
- sikkerlogg.info(" Parsing incoming $incomingFormatType request failed with exception (responding 4xx): $e " )
111
- if (Configuration .profile != Configuration .Profile .PROD ) {
112
- sikkerlogg.info(
113
- " $incomingFormatType in failed parsing: ${mapperJson.writeValueAsString(requestBody)} "
114
- )
115
- }
125
+ sikkerlogg.error(e) { " Parsing incoming $incomingFormatType request failed with exception (responding 4xx)" }
116
126
}
117
127
context.metrics.oebsParsingFeilet()
118
- call.respond(HttpStatusCode .BadRequest , " bad request: $incomingFormatType not valid" )
119
128
return null
120
129
}
121
130
}
@@ -136,12 +145,12 @@ private fun sendUvalidertOrdrelinjeTilRapid(context: Context, ordrelinje: RåOrd
136
145
context.metrics.meldingTilRapidSuksess()
137
146
} catch (e: Exception ) {
138
147
context.metrics.meldingTilRapidFeilet()
139
- sikkerlogg.error(" Sending av uvalidert ordrelinje til rapid feilet, exception: $e \n\n ${e.printStackTrace()} " )
148
+ sikkerlogg.error(e) { " Sending av uvalidert ordrelinje til rapid feilet" }
140
149
throw RapidsAndRiverException (" Noe gikk feil ved publisering av melding" )
141
150
}
142
151
}
143
152
144
- private fun validerOrdrelinje (context : Context , ordrelinje : OrdrelinjeOebs ) {
153
+ private fun erOrdrelinjeRelevantForOss (context : Context , ordrelinje : OrdrelinjeOebs ): Boolean {
145
154
if (ordrelinje.serviceforespørseltype != " Vedtak Infotrygd" ) {
146
155
if (ordrelinje.serviceforespørseltype == " " ) {
147
156
logg.info(
@@ -155,7 +164,7 @@ private fun validerOrdrelinje(context: Context, ordrelinje: OrdrelinjeOebs) {
155
164
)
156
165
context.metrics.sfTypeUlikVedtakInfotrygd()
157
166
}
158
- throw RuntimeException ( " Ugyldig ordrelinje " )
167
+ return false
159
168
} else {
160
169
context.metrics.sfTypeVedtakInfotrygd()
161
170
}
@@ -166,10 +175,12 @@ private fun validerOrdrelinje(context: Context, ordrelinje: OrdrelinjeOebs) {
166
175
) {
167
176
logg.info(" Mottok melding fra oebs med irrelevant hjelpemiddeltype ${ordrelinje.hjelpemiddeltype} . Avbryter prosessering" )
168
177
context.metrics.irrelevantHjelpemiddeltype()
169
- throw RuntimeException ( " Ugyldig ordrelinje " )
178
+ return false
170
179
} else {
171
180
context.metrics.rettHjelpemiddeltype()
172
181
}
182
+
183
+ return true
173
184
}
174
185
175
186
private fun publiserMelding (
@@ -182,22 +193,21 @@ private fun publiserMelding(
182
193
context.publish(ordrelinje.fnrBruker, mapperJson.writeValueAsString(melding))
183
194
context.metrics.meldingTilRapidSuksess()
184
195
185
- // TODO: Remove logging when interface stabilizes
186
196
ordrelinje.fnrBruker = " MASKERT"
187
197
if (ordrelinje.sendtTilAdresse.take(4 ).toIntOrNull() == null ) {
188
198
// If address is not municipality-intake we mask it in logging.
189
199
ordrelinje.sendtTilAdresse = " MASKERT"
190
200
}
191
- sikkerlogg.info (
192
- " Ordrelinje med OebsId ${ordrelinje.oebsId} mottatt og sendt til rapid: ${
193
- mapperJson.writeValueAsString(
194
- ordrelinje
195
- )
196
- } "
197
- )
201
+ withLoggingContext (
202
+ mapOf (
203
+ " ordrelinje " to mapperJson.writeValueAsString(ordrelinje),
204
+ )
205
+ ) {
206
+ sikkerlogg.info( " Ordrelinje med OebsId ${ordrelinje.oebsId} mottatt og sendt til rapid " )
207
+ }
198
208
} catch (e: Exception ) {
199
209
context.metrics.meldingTilRapidFeilet()
200
- sikkerlogg.error(" Sending til rapid feilet" , e)
210
+ sikkerlogg.error(e) { " Sending til rapid feilet" }
201
211
throw RapidsAndRiverException (" Noe gikk feil ved publisering av melding" )
202
212
}
203
213
}
0 commit comments