generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #744 from it-at-m/193-lesen-und-schreiben-von-ausd…
…rucken 193 lesen und schreiben von ausdrucken
- Loading branch information
Showing
37 changed files
with
1,752 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...rvice/src/main/resources/db/migrations/h2/V6_0__addErgebnismeldungPermissionsAusdruck.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
INSERT INTO Permission | ||
VALUES ('00000000-0000-0006-0000-000000000001', 'Ergebnismeldung_BUSINESSACTION_GetAusdruck'); | ||
INSERT INTO Secauthorities_Secpermissions | ||
VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0006-0000-000000000001'); | ||
|
||
INSERT INTO Permission | ||
VALUES ('00000000-0000-0006-0000-000000000002', 'Ergebnismeldung_BUSINESSACTION_PostAusdruck'); | ||
INSERT INTO Secauthorities_Secpermissions | ||
VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0006-0000-000000000002'); |
9 changes: 9 additions & 0 deletions
9
...e/src/main/resources/db/migrations/oracle/V6_0__addErgebnismeldungPermissionsAusdruck.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
INSERT INTO Permission | ||
VALUES ('00000000-0000-0006-0000-000000000001', 'Ergebnismeldung_BUSINESSACTION_GetAusdruck'); | ||
INSERT INTO Secauthorities_Secpermissions | ||
VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0006-0000-000000000001'); | ||
|
||
INSERT INTO Permission | ||
VALUES ('00000000-0000-0006-0000-000000000002', 'Ergebnismeldung_BUSINESSACTION_PostAusdruck'); | ||
INSERT INTO Secauthorities_Secpermissions | ||
VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0006-0000-000000000002'); |
31 changes: 31 additions & 0 deletions
31
...java/de/muenchen/oss/wahllokalsystem/ergebnismeldungservice/domain/ausdruck/Ausdruck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EmbeddedId; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Lob; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.Instant; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Ausdruck { | ||
|
||
@Valid | ||
@NotNull | ||
@EmbeddedId | ||
private WahlUndBezirkIDUndMeldungsart wahlUndBezirkIDUndMeldungsart; | ||
|
||
@Lob | ||
private String content; | ||
|
||
@NotNull | ||
@Column(name = "erstellt_am") | ||
private Instant erstelltAm; | ||
} |
12 changes: 12 additions & 0 deletions
12
...enchen/oss/wahllokalsystem/ergebnismeldungservice/domain/ausdruck/AusdruckRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface AusdruckRepository extends CrudRepository<Ausdruck, WahlUndBezirkIDUndMeldungsart> { | ||
|
||
@Query("SELECT a FROM Ausdruck a WHERE a.wahlUndBezirkIDUndMeldungsart.wahlID = :wahlID AND a.wahlUndBezirkIDUndMeldungsart.wahlbezirkID = :wahlbezirkID") | ||
List<Ausdruck> findByWahlIdAndWahlbezirkId(@Param("wahlID") String wahlID, @Param("wahlbezirkID") String wahlbezirkID); | ||
} |
12 changes: 12 additions & 0 deletions
12
...a/de/muenchen/oss/wahllokalsystem/ergebnismeldungservice/domain/ausdruck/Meldungsart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck; | ||
|
||
public enum Meldungsart { | ||
/** | ||
* Niederschrift | ||
*/ | ||
V1, | ||
/** | ||
* Schnellmeldung | ||
*/ | ||
V3 | ||
} |
29 changes: 29 additions & 0 deletions
29
...wahllokalsystem/ergebnismeldungservice/domain/ausdruck/WahlUndBezirkIDUndMeldungsart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck; | ||
|
||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import java.io.Serializable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class WahlUndBezirkIDUndMeldungsart implements Serializable { | ||
|
||
@NotBlank | ||
@Size(max = 1024) | ||
private String wahlbezirkID; | ||
|
||
@NotBlank | ||
@Size(max = 1024) | ||
private String wahlID; | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
private Meldungsart meldungsart; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...muenchen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/AusdruckController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck.Meldungsart; | ||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck.WahlUndBezirkIDUndMeldungsart; | ||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.ausdruck.AusdruckService; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/businessActions/ausdruck") | ||
@RequiredArgsConstructor | ||
public class AusdruckController { | ||
|
||
private final AusdruckService ausdruckService; | ||
|
||
private final AusdruckReadDTOMapper ausdruckReadDTOMapper; | ||
|
||
private final AusdruckWriteDTOMapper ausdruckWriteDTOMapper; | ||
|
||
@Operation(description = "Lesen eines Ausdrucks einer bestimmten Meldungsart für einen Wahlbezirk einer Wahl") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Es existiert ein Ausdruck", | ||
content = { @Content(mediaType = "text/html; charset=utf-8", schema = @Schema(implementation = AusdruckReadDTO.class)) } | ||
), | ||
@ApiResponse( | ||
responseCode = "204", description = "Es existiert kein Ausdruck zu den entsprechenden Kriterien", | ||
content = { @Content() } | ||
), | ||
@ApiResponse( | ||
responseCode = "400", description = "Validierung der Anfrage war nicht erfolgreich", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
), | ||
@ApiResponse( | ||
responseCode = "500", description = "Probleme bei der Verarbeitung der Anfrage", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
) | ||
} | ||
) | ||
@GetMapping("{wahlID}/{wahlbezirkID}/{meldungsart}/html") | ||
public ResponseEntity<String> getAusdruck(@PathVariable("wahlID") final String wahlID, @PathVariable("wahlbezirkID") final String wahlbezirkID, | ||
@PathVariable("meldungsart") final Meldungsart meldungsart) { | ||
val ausdruckModel = ausdruckService.getAusdruck(new WahlUndBezirkIDUndMeldungsart(wahlbezirkID, wahlID, meldungsart)); | ||
|
||
if (ausdruckModel.isEmpty()) { | ||
return new ResponseEntity<>(HttpStatus.NOT_FOUND); | ||
} else { | ||
val result = ausdruckReadDTOMapper.toDTO(ausdruckModel.get()); | ||
val responseHeaders = new HttpHeaders(); | ||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, "text/html; charset=utf-8"); | ||
return new ResponseEntity<>(result.content(), responseHeaders, HttpStatus.OK); | ||
} | ||
} | ||
|
||
@Operation(description = "Lesen aller Ausdrucke für einen Wahlbezirk einer Wahl") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Es existiert ein Ausdruck", | ||
content = { | ||
@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = AusdruckReadDTO.class))) } | ||
), | ||
@ApiResponse( | ||
responseCode = "204", description = "Es existiert kein Ausdruck zu den entsprechenden Kriterien", | ||
content = { @Content() } | ||
), | ||
@ApiResponse( | ||
responseCode = "400", description = "Validierung der Anfrage war nicht erfolgreich", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
), | ||
@ApiResponse( | ||
responseCode = "500", description = "Probleme bei der Verarbeitung der Anfrage", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
) | ||
} | ||
) | ||
@GetMapping("{wahlID}/{wahlbezirkID}") | ||
public ResponseEntity<List<AusdruckReadDTO>> getAllAusdrucke(@PathVariable("wahlID") final String wahlID, | ||
@PathVariable("wahlbezirkID") final String wahlbezirkID) { | ||
val ausdrucke = ausdruckService.getAllAusdrucke(wahlID, wahlbezirkID); | ||
return ResponseEntity.ok(ausdrucke.stream().map(ausdruckReadDTOMapper::toDTO).toList()); | ||
} | ||
|
||
@Operation(description = "Speichern eines Ausdrucks einer bestimmten Meldungsart für einen Wahlbezirk einer Wahl") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Ausdruck erfolgreich gespeichert" | ||
), | ||
@ApiResponse( | ||
responseCode = "400", description = "Validierung der Anfrage war nicht erfolgreich", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
), | ||
@ApiResponse( | ||
responseCode = "500", description = "Probleme bei der Verarbeitung der Anfrage", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) } | ||
) | ||
} | ||
) | ||
@PostMapping("{wahlID}/{wahlbezirkID}/{meldungsart}/html") | ||
public ResponseEntity<?> postAusdruck(@PathVariable("wahlID") final String wahlID, | ||
@PathVariable("wahlbezirkID") final String wahlbezirkID, @PathVariable("meldungsart") final Meldungsart meldungsart, | ||
@RequestBody final AusdruckWriteDTO ausdruck) { | ||
val ausdruckModel = ausdruckWriteDTOMapper.toModel(ausdruck, new WahlUndBezirkIDUndMeldungsart(wahlbezirkID, wahlID, meldungsart)); | ||
ausdruckService.saveAusdruck(ausdruckModel); | ||
return new ResponseEntity<>(HttpStatus.OK); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...de/muenchen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/AusdruckReadDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import java.time.Instant; | ||
|
||
public record AusdruckReadDTO(@NotNull String wahlbezirkID, | ||
@NotNull String wahlID, | ||
@NotNull MeldungsartDTO meldungsart, | ||
String content, | ||
@NotNull Instant erstelltAm) { | ||
} |
14 changes: 14 additions & 0 deletions
14
...nchen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/AusdruckReadDTOMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.ausdruck.AusdruckModel; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface AusdruckReadDTOMapper { | ||
|
||
@Mapping(source = "wahlUndBezirkIDUndMeldungsart.wahlID", target = "wahlID") | ||
@Mapping(source = "wahlUndBezirkIDUndMeldungsart.wahlbezirkID", target = "wahlbezirkID") | ||
@Mapping(source = "wahlUndBezirkIDUndMeldungsart.meldungsart", target = "meldungsart") | ||
AusdruckReadDTO toDTO(AusdruckModel ausdruckModel); | ||
} |
4 changes: 4 additions & 0 deletions
4
...e/muenchen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/AusdruckWriteDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
public record AusdruckWriteDTO(String content) { | ||
} |
14 changes: 14 additions & 0 deletions
14
...chen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/AusdruckWriteDTOMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck.WahlUndBezirkIDUndMeldungsart; | ||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.ausdruck.AusdruckModel; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface AusdruckWriteDTOMapper { | ||
|
||
@Mapping(target = "erstelltAm", ignore = true) | ||
AusdruckModel toModel(AusdruckWriteDTO ausdruckWriteDTO, WahlUndBezirkIDUndMeldungsart wahlUndBezirkIDUndMeldungsart); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../de/muenchen/oss/wahllokalsystem/ergebnismeldungservice/rest/ausdruck/MeldungsartDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.ausdruck; | ||
|
||
public enum MeldungsartDTO { | ||
V1, V3 | ||
} |
11 changes: 11 additions & 0 deletions
11
...e/muenchen/oss/wahllokalsystem/ergebnismeldungservice/service/ausdruck/AusdruckModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.ausdruck; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck.WahlUndBezirkIDUndMeldungsart; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.Instant; | ||
|
||
public record AusdruckModel(@Valid @NotNull WahlUndBezirkIDUndMeldungsart wahlUndBezirkIDUndMeldungsart, | ||
String content, | ||
Instant erstelltAm) { | ||
} |
15 changes: 15 additions & 0 deletions
15
...chen/oss/wahllokalsystem/ergebnismeldungservice/service/ausdruck/AusdruckModelMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.ausdruck; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.ausdruck.Ausdruck; | ||
import java.time.Instant; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface AusdruckModelMapper { | ||
|
||
AusdruckModel toModel(Ausdruck entity); | ||
|
||
@Mapping(target = "erstelltAm", source = "erstelltAm") | ||
Ausdruck toEntity(AusdruckModel model, Instant erstelltAm); | ||
} |
Oops, something went wrong.