Skip to content

Commit 97af86e

Browse files
authored
Return JSON Problem when vardef id not found (#484)
* correct variable name so the method intention is clear * Refactor tests * add json problem response * ktlint * update examples and open api spec * remove commented out annotation
1 parent 704014a commit 97af86e

File tree

9 files changed

+362
-244
lines changed

9 files changed

+362
-244
lines changed

openapi/variable-definitions-internal.yml

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ paths:
102102
value: |-
103103
[
104104
{
105-
"vardok_id": "25",
106-
"vardef_id": "A1699WWE"
105+
"vardok_id": 1607,
106+
"vardef_id": wypvb3wd
107107
}
108108
]
109109
security:
@@ -127,7 +127,24 @@ paths:
127127
examples:
128128
Vardok id:
129129
value: "1607"
130+
Vardef id:
131+
value: wypvb3wd
132+
Not found:
133+
value: Xy9_7-Az
130134
responses:
135+
"404":
136+
description: Not found
137+
content:
138+
application/problem+json:
139+
schema:
140+
$ref: https://opensource.zalando.com/restful-api-guidelines/models/problem-1.0.1.yaml#/Problem
141+
examples:
142+
Not found:
143+
value:
144+
type: about:blank
145+
status: 404
146+
detail: Not found
147+
parameters: {}
131148
"200":
132149
description: OK response
133150
content:
@@ -178,6 +195,7 @@ paths:
178195
- he04
179196
contains_special_categories_of_personal_data: true
180197
variable_status: DRAFT
198+
measurement_type: "01"
181199
valid_from: 2003-01-01
182200
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
183201
comment:
@@ -204,8 +222,7 @@ paths:
204222
last_updated_at: 2024-06-11T08:15:19.038Z
205223
last_updated_by: ano@ssb.no
206224
Vardef id:
207-
value:
208-
vardok_id: "25"
225+
value: "1607"
209226
security:
210227
- labid_token: []
211228
/vardok-migration/{vardok-id}:
@@ -274,6 +291,7 @@ paths:
274291
- he04
275292
contains_special_categories_of_personal_data: true
276293
variable_status: DRAFT
294+
measurement_type: "01"
277295
valid_from: 2003-01-01
278296
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
279297
comment:
@@ -414,7 +432,7 @@ paths:
414432
"subject_fields": ["he04"],
415433
"contains_special_categories_of_personal_data": true,
416434
"variable_status": "DRAFT",
417-
"measurement_type": null,
435+
"measurement_type": "01",
418436
"valid_from": "2003-01-01",
419437
"valid_until": null,
420438
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -467,7 +485,7 @@ paths:
467485
"subject_fields": ["he04"],
468486
"contains_special_categories_of_personal_data": true,
469487
"variable_status": "DRAFT",
470-
"measurement_type": null,
488+
"measurement_type": "01",
471489
"valid_from": "2003-01-01",
472490
"valid_until": null,
473491
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -524,7 +542,11 @@ paths:
524542
],
525543
"contains_special_categories_of_personal_data": true,
526544
"variable_status": "PUBLISHED_INTERNAL",
527-
"measurement_type": null,
545+
"measurement_type": {
546+
"reference_uri": "https://www.ssb.no/klass/klassifikasjoner/303",
547+
"code": "01",
548+
"title": "Andel"
549+
},
528550
"valid_from": "2003-01-01",
529551
"valid_until": null,
530552
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -599,6 +621,7 @@ paths:
599621
subject_fields:
600622
- he04
601623
contains_special_categories_of_personal_data: true
624+
measurement_type: "01"
602625
valid_from: 2003-01-01
603626
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
604627
comment:
@@ -665,6 +688,7 @@ paths:
665688
- he04
666689
contains_special_categories_of_personal_data: true
667690
variable_status: DRAFT
691+
measurement_type: "01"
668692
valid_from: 2003-01-01
669693
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
670694
comment:
@@ -839,6 +863,7 @@ paths:
839863
- he04
840864
contains_special_categories_of_personal_data: true
841865
variable_status: DRAFT
866+
measurement_type: "01"
842867
valid_from: 2003-01-01
843868
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
844869
comment:
@@ -905,6 +930,7 @@ paths:
905930
- he04
906931
contains_special_categories_of_personal_data: true
907932
variable_status: DRAFT
933+
measurement_type: "01"
908934
valid_from: 2003-01-01
909935
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
910936
comment:
@@ -953,6 +979,10 @@ paths:
953979
title: Innvandrere
954980
contains_special_categories_of_personal_data: true
955981
variable_status: PUBLISHED_INTERNAL
982+
measurement_type:
983+
reference_uri: https://www.ssb.no/klass/klassifikasjoner/303
984+
code: "01"
985+
title: Andel
956986
valid_from: 2003-01-01
957987
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
958988
comment: Fra og med 1.1.2003 ble definisjon endret til også å
@@ -1118,6 +1148,7 @@ paths:
11181148
- he04
11191149
contains_special_categories_of_personal_data: true
11201150
variable_status: DRAFT
1151+
measurement_type: "01"
11211152
valid_from: 2003-01-01
11221153
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
11231154
comment:
@@ -1257,7 +1288,7 @@ paths:
12571288
"subject_fields": ["he04"],
12581289
"contains_special_categories_of_personal_data": true,
12591290
"variable_status": "DRAFT",
1260-
"measurement_type": null,
1291+
"measurement_type": "01",
12611292
"valid_from": "2003-01-01",
12621293
"valid_until": null,
12631294
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -1373,6 +1404,7 @@ paths:
13731404
subject_fields:
13741405
- he04
13751406
contains_special_categories_of_personal_data: false
1407+
measurement_type: "01"
13761408
valid_until: 2026-01-01
13771409
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
13781410
comment:
@@ -1436,6 +1468,7 @@ paths:
14361468
- he04
14371469
contains_special_categories_of_personal_data: true
14381470
variable_status: PUBLISHED_INTERNAL
1471+
measurement_type: "01"
14391472
valid_from: 2003-01-01
14401473
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
14411474
comment:
@@ -1592,6 +1625,7 @@ paths:
15921625
- he04
15931626
contains_special_categories_of_personal_data: true
15941627
variable_status: DRAFT
1628+
measurement_type: "01"
15951629
valid_from: 2003-01-01
15961630
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
15971631
comment:
@@ -1683,7 +1717,7 @@ paths:
16831717
"subject_fields": ["he04"],
16841718
"contains_special_categories_of_personal_data": true,
16851719
"variable_status": "DRAFT",
1686-
"measurement_type": null,
1720+
"measurement_type": "01",
16871721
"valid_from": "2003-01-01",
16881722
"valid_until": null,
16891723
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -1770,6 +1804,7 @@ paths:
17701804
subject_fields:
17711805
- he04
17721806
contains_special_categories_of_personal_data: false
1807+
measurement_type: "01"
17731808
valid_from: 2026-01-02
17741809
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
17751810
comment:
@@ -1833,6 +1868,7 @@ paths:
18331868
- he04
18341869
contains_special_categories_of_personal_data: true
18351870
variable_status: DRAFT
1871+
measurement_type: "01"
18361872
valid_from: 2003-01-01
18371873
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
18381874
comment:
@@ -2155,7 +2191,7 @@ components:
21552191
subject_fields:
21562192
- he04
21572193
contains_special_categories_of_personal_data: true
2158-
measurement_type: null
2194+
measurement_type: "01"
21592195
valid_from: 2003-01-01
21602196
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
21612197
comment:
@@ -2288,7 +2324,7 @@ components:
22882324
subject_fields:
22892325
- he04
22902326
contains_special_categories_of_personal_data: false
2291-
measurement_type: null
2327+
measurement_type: "01"
22922328
valid_until: 2026-01-01
22932329
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
22942330
comment:
@@ -2394,7 +2430,7 @@ components:
23942430
subject_fields:
23952431
- he04
23962432
contains_special_categories_of_personal_data: false
2397-
measurement_type: null
2433+
measurement_type: "01"
23982434
valid_from: 2026-01-02
23992435
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
24002436
comment:
@@ -2613,7 +2649,10 @@ components:
26132649
title: Innvandrere
26142650
contains_special_categories_of_personal_data: true
26152651
variable_status: PUBLISHED_INTERNAL
2616-
measurement_type: null
2652+
measurement_type:
2653+
reference_uri: https://www.ssb.no/klass/klassifikasjoner/303
2654+
code: "01"
2655+
title: Andel
26172656
valid_from: 2003-01-01
26182657
valid_until: null
26192658
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
@@ -2769,7 +2808,7 @@ components:
27692808
subject_fields:
27702809
- he04
27712810
contains_special_categories_of_personal_data: true
2772-
measurement_type: null
2811+
measurement_type: "01"
27732812
valid_from: 2003-01-01
27742813
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
27752814
comment:

openapi/variable-definitions-public.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ paths:
8888
],
8989
"contains_special_categories_of_personal_data": true,
9090
"variable_status": "PUBLISHED_INTERNAL",
91-
"measurement_type": null,
91+
"measurement_type": {
92+
"reference_uri": "https://www.ssb.no/klass/klassifikasjoner/303",
93+
"code": "01",
94+
"title": "Andel"
95+
},
9296
"valid_from": "2003-01-01",
9397
"valid_until": null,
9498
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -189,6 +193,10 @@ paths:
189193
title: Innvandrere
190194
contains_special_categories_of_personal_data: true
191195
variable_status: PUBLISHED_INTERNAL
196+
measurement_type:
197+
reference_uri: https://www.ssb.no/klass/klassifikasjoner/303
198+
code: "01"
199+
title: Andel
192200
valid_from: 2003-01-01
193201
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
194202
comment: Fra og med 1.1.2003 ble definisjon endret til også å
@@ -229,6 +237,10 @@ paths:
229237
title: Innvandrere
230238
contains_special_categories_of_personal_data: true
231239
variable_status: PUBLISHED_INTERNAL
240+
measurement_type:
241+
reference_uri: https://www.ssb.no/klass/klassifikasjoner/303
242+
code: "01"
243+
title: Andel
232244
valid_from: 2003-01-01
233245
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb
234246
comment: Fra og med 1.1.2003 ble definisjon endret til også å
@@ -326,7 +338,11 @@ paths:
326338
],
327339
"contains_special_categories_of_personal_data": true,
328340
"variable_status": "PUBLISHED_INTERNAL",
329-
"measurement_type": null,
341+
"measurement_type": {
342+
"reference_uri": "https://www.ssb.no/klass/klassifikasjoner/303",
343+
"code": "01",
344+
"title": "Andel"
345+
},
330346
"valid_from": "2003-01-01",
331347
"valid_until": null,
332348
"external_reference_uri": "https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb",
@@ -536,7 +552,10 @@ components:
536552
title: Innvandrere
537553
contains_special_categories_of_personal_data: true
538554
variable_status: PUBLISHED_INTERNAL
539-
measurement_type: null
555+
measurement_type:
556+
reference_uri: https://www.ssb.no/klass/klassifikasjoner/303
557+
code: "01"
558+
title: Andel
540559
valid_from: 2003-01-01
541560
valid_until: null
542561
external_reference_uri: https://www.ssb.no/a/metadata/conceptvariable/vardok/1919/nb

src/main/kotlin/no/ssb/metadata/vardef/constants/SchemaExamples.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,14 @@ const val LIST_OF_COMPLETE_VIEW_EXAMPLE = """[
292292
$COMPLETE_VIEW_EXAMPLE
293293
]"""
294294

295-
const val VARDOK_ID_RESPONSE_EXAMPLE = """{
296-
"vardok_id": "25"
297-
}"""
295+
const val VARDOK_ID_RESPONSE_EXAMPLE = """1607"""
296+
297+
const val VARDEF_ID_MIGRATED_EXAMPLE = ID_EXAMPLE
298+
const val VARDEF_ID_NOT_MIGRATED_EXAMPLE = """Xy9_7-Az"""
298299

299300
const val VARDOK_VARDEF_ID_RESPONSE_EXAMPLE = """{
300-
"vardok_id": "25",
301-
"vardef_id": "A1699WWE"
301+
"vardok_id": $VARDOK_ID_RESPONSE_EXAMPLE,
302+
"vardef_id": $VARDEF_ID_MIGRATED_EXAMPLE
302303
}"""
303304

304305
const val VARDOK_VARDEF_ID_LIST_RESPONSE_EXAMPLE = """[

src/main/kotlin/no/ssb/metadata/vardef/controllers/internalapi/VarDokMigrationController.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.annotations.tags.Tag
2121
import kotlinx.coroutines.reactive.awaitFirst
2222
import kotlinx.coroutines.runBlocking
2323
import no.ssb.metadata.vardef.annotations.BadRequestApiResponse
24+
import no.ssb.metadata.vardef.annotations.NotFoundApiResponse
2425
import no.ssb.metadata.vardef.constants.*
2526
import no.ssb.metadata.vardef.integrations.vardok.models.VardefInput
2627
import no.ssb.metadata.vardef.integrations.vardok.models.VardokIdResponse
@@ -139,6 +140,7 @@ class VarDokMigrationController(
139140
* Get one variable definition by vardok id or get the vardok id by vardef id.
140141
*/
141142
@Get("/{id}")
143+
@NotFoundApiResponse
142144
@ApiResponse(
143145
content =
144146
[
@@ -165,7 +167,15 @@ class VarDokMigrationController(
165167
examples = [
166168
ExampleObject(
167169
name = "Vardok id",
168-
value = "1607",
170+
value = VARDOK_ID_RESPONSE_EXAMPLE,
171+
),
172+
ExampleObject(
173+
name = "Vardef id",
174+
value = VARDEF_ID_MIGRATED_EXAMPLE,
175+
),
176+
ExampleObject(
177+
name = NOT_FOUND_EXAMPLE_NAME,
178+
value = VARDEF_ID_NOT_MIGRATED_EXAMPLE,
169179
),
170180
],
171181
)
@@ -189,7 +199,10 @@ class VarDokMigrationController(
189199
vardokService
190200
.getVardokIdByVardefId(id)
191201
?.let { HttpResponse.ok(VardokIdResponse(it)) }
192-
?: HttpResponse.notFound(HttpStatus.NOT_FOUND)
202+
?: throw HttpStatusException(
203+
HttpStatus.NOT_FOUND,
204+
"No vardok mapping for vardef id $id",
205+
)
193206
}
194207

195208
/**

src/main/kotlin/no/ssb/metadata/vardef/integrations/vardok/services/VardokService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface VardokService {
3232

3333
fun getVardefIdByVardokId(vardokId: String): String?
3434

35-
fun getVardokIdByVardefId(vardokId: String): String?
35+
fun getVardokIdByVardefId(vardefId: String): String?
3636

3737
fun isAlreadyMigrated(vardokId: String): Boolean
3838

0 commit comments

Comments
 (0)