Commit 10ea3bf Dominick Leppich
committed
1 parent b875428 commit 10ea3bf Copy full SHA for 10ea3bf
File tree 3 files changed +74
-0
lines changed
module-core/src/main/java/io/goobi/vocabulary
3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ package io .goobi .vocabulary .api ;
2
+
3
+ import io .goobi .vocabulary .api .assemblers .FieldDefinitionAssembler ;
4
+ import io .goobi .vocabulary .exchange .FieldDefinition ;
5
+ import io .goobi .vocabulary .service .manager .FieldDefinitionDTOManager ;
6
+ import org .springframework .hateoas .EntityModel ;
7
+ import org .springframework .web .bind .annotation .GetMapping ;
8
+ import org .springframework .web .bind .annotation .PathVariable ;
9
+ import org .springframework .web .bind .annotation .RequestMapping ;
10
+ import org .springframework .web .bind .annotation .RestController ;
11
+
12
+ @ RestController
13
+ @ RequestMapping ("/api/v1" )
14
+ public class FieldDefinitionController {
15
+ private final FieldDefinitionDTOManager manager ;
16
+ private final FieldDefinitionAssembler assembler ;
17
+
18
+ public FieldDefinitionController (FieldDefinitionDTOManager manager , FieldDefinitionAssembler assembler ) {
19
+ this .manager = manager ;
20
+ this .assembler = assembler ;
21
+ }
22
+
23
+ @ GetMapping ("/fieldDefinitions/{id}" )
24
+ public EntityModel <FieldDefinition > one (@ PathVariable long id ) {
25
+ return assembler .toModel (manager .get (id ));
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ package io .goobi .vocabulary .api .assemblers ;
2
+
3
+ import io .goobi .vocabulary .api .FieldTypeController ;
4
+ import io .goobi .vocabulary .api .VocabularySchemaController ;
5
+ import io .goobi .vocabulary .exchange .FieldDefinition ;
6
+ import org .springframework .hateoas .EntityModel ;
7
+ import org .springframework .hateoas .server .RepresentationModelAssembler ;
8
+ import org .springframework .stereotype .Component ;
9
+
10
+ import static org .springframework .hateoas .server .mvc .WebMvcLinkBuilder .linkTo ;
11
+ import static org .springframework .hateoas .server .mvc .WebMvcLinkBuilder .methodOn ;
12
+
13
+ @ Component
14
+ public class FieldDefinitionAssembler implements RepresentationModelAssembler <FieldDefinition , EntityModel <FieldDefinition >> {
15
+ @ Override
16
+ public EntityModel <FieldDefinition > toModel (FieldDefinition entity ) {
17
+ return EntityModel .of (entity ,
18
+ linkTo (methodOn (FieldTypeController .class ).one (entity .getId ())).withSelfRel (),
19
+ linkTo (methodOn (VocabularySchemaController .class ).one (entity .getSchemaId ())).withRel ("schema" )
20
+ );
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ package io .goobi .vocabulary .service .manager ;
2
+
3
+ import io .goobi .vocabulary .exception .EntityNotFoundException ;
4
+ import io .goobi .vocabulary .exchange .FieldDefinition ;
5
+ import io .goobi .vocabulary .repositories .FieldDefinitionRepository ;
6
+ import io .goobi .vocabulary .service .exchange .DTOMapper ;
7
+ import org .springframework .stereotype .Service ;
8
+
9
+ @ Service
10
+ public class FieldDefinitionDTOManager {
11
+ private final FieldDefinitionRepository fieldDefinitionRepository ;
12
+ private final DTOMapper modelMapper ;
13
+
14
+ public FieldDefinitionDTOManager (FieldDefinitionRepository fieldDefinitionRepository , DTOMapper modelMapper ) {
15
+ this .fieldDefinitionRepository = fieldDefinitionRepository ;
16
+ this .modelMapper = modelMapper ;
17
+ }
18
+
19
+ public FieldDefinition get (long id ) {
20
+ return modelMapper .toDTO (
21
+ fieldDefinitionRepository .findById (id )
22
+ .orElseThrow (() -> new EntityNotFoundException (FieldDefinition .class , id ))
23
+ );
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments