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 #349 from it-at-m/139-implementierung-von-speicher…
…n-und-lesen-für-handbuch-endpunkt 139 implementierung von speichern und lesen für handbuch endpunkt
- Loading branch information
Showing
29 changed files
with
1,215 additions
and
2 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
48 changes: 48 additions & 0 deletions
48
stack/keycloak/migration/add-authorities-basisdaten-handbuch.yml
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,48 @@ | ||
id: add authorities basisdaten handbuch | ||
author: MrSebastian | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addRole: | ||
name: Basisdaten_BUSINESSACTION_GetHandbuch | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_BUSINESSACTION_GetHandbuch | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_BUSINESSACTION_PostHandbuch | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_BUSINESSACTION_PostHandbuch | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_READ_Handbuch | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_READ_Handbuch | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_WRITE_Handbuch | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_WRITE_Handbuch | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_DELETE_Handbuch | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_DELETE_Handbuch | ||
clientId: ${SSO_CLIENT_ID} |
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
30 changes: 30 additions & 0 deletions
30
...vice/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/Handbuch.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,30 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain; | ||
|
||
import jakarta.persistence.EmbeddedId; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Lob; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
@ToString(onlyExplicitlyIncluded = true) | ||
public class Handbuch { | ||
|
||
@EmbeddedId | ||
@ToString.Include | ||
private WahltagIdUndWahlbezirksart wahltagIdUndWahlbezirksart; | ||
|
||
@NotNull | ||
@Lob | ||
private byte[] handbuch; | ||
} |
46 changes: 46 additions & 0 deletions
46
...ain/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/HandbuchRepository.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,46 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain; | ||
|
||
import java.util.Optional; | ||
import org.springframework.cache.annotation.CacheEvict; | ||
import org.springframework.cache.annotation.CachePut; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
||
@PreAuthorize("hasAuthority('Basisdaten_READ_Handbuch')") | ||
public interface HandbuchRepository extends CrudRepository<Handbuch, WahltagIdUndWahlbezirksart> { | ||
|
||
String CACHE = "HANDBUCH_CACHE"; | ||
|
||
@Override | ||
Iterable<Handbuch> findAll(); | ||
|
||
@Override | ||
@Cacheable(value = CACHE, key = "#p0") | ||
Optional<Handbuch> findById(WahltagIdUndWahlbezirksart wahltagIdUndWahlbezirksart); | ||
|
||
@Override | ||
@CachePut(value = CACHE, key = "#p0.wahltagIdUndWahlbezirksart") | ||
@PreAuthorize("hasAuthority('Basisdaten_WRITE_Handbuch')") | ||
<S extends Handbuch> S save(S handbuch); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0") | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Handbuch')") | ||
void deleteById(WahltagIdUndWahlbezirksart wahltagIdUndWahlbezirksart); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0.wahltagIdUndWahlbezirksart") | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Handbuch')") | ||
void delete(Handbuch entity); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Handbuch')") | ||
void deleteAll(Iterable<? extends Handbuch> entities); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Handbuch')") | ||
void deleteAll(); | ||
} |
5 changes: 5 additions & 0 deletions
5
...src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahlbezirkArt.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.basisdatenservice.domain; | ||
|
||
public enum WahlbezirkArt { | ||
UWB, BWB | ||
} |
23 changes: 23 additions & 0 deletions
23
.../de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/WahltagIdUndWahlbezirksart.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,23 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain; | ||
|
||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class WahltagIdUndWahlbezirksart { | ||
|
||
@NotNull | ||
@Size(max = 1024) | ||
private String wahltagID; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@NotNull | ||
private WahlbezirkArt wahlbezirksart; | ||
} |
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
102 changes: 102 additions & 0 deletions
102
...a/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/handbuch/HandbuchController.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,102 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.handbuch; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.handbuch.HandbuchService; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
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 java.io.IOException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Value; | ||
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.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartHttpServletRequest; | ||
|
||
@RestController | ||
@RequestMapping("/businessActions/handbuch") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class HandbuchController { | ||
|
||
@Value("${service.config.manual.filenamesuffix:Handbuch.pdf}") | ||
String manualFileNameSuffix; | ||
|
||
private final HandbuchService handbuchService; | ||
|
||
private final ExceptionFactory exceptionFactory; | ||
|
||
private final HandbuchDTOMapper handbuchDTOMapper; | ||
|
||
@GetMapping("{wahltagID}/{wahlbezirksart}") | ||
@Operation( | ||
description = "Abrufen des Handbuches einer Wahl für eine bestimmte Wahlbezirksart", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "500", description = "Handbuch ist nicht abrufbar. Entweder fehlt es oder es gab technische Probleme", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "400", description = "Anfrageparameter sind fehlerhaft", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) | ||
) | ||
} | ||
) | ||
public ResponseEntity<byte[]> getHandbuch(@PathVariable("wahltagID") String wahltagID, | ||
@PathVariable("wahlbezirksart") WahlbezirkArtDTO wahlbezirkArtDTO) { | ||
val handbuchData = handbuchService.getHandbuch(handbuchDTOMapper.toModel(wahltagID, wahlbezirkArtDTO)); | ||
return createPDFResponse(handbuchData, wahlbezirkArtDTO); | ||
} | ||
|
||
@PostMapping("{wahltagID}/{wahlbezirksart}") | ||
@Operation( | ||
description = "Speichern eines Handbuches einer Wahl für eine bestimmte Wahlbezirksart", | ||
responses = { | ||
@ApiResponse(responseCode = "500", description = "Handbuch kann nicht gespeichert werden"), | ||
@ApiResponse( | ||
responseCode = "400", description = "Anfrageparameter sind fehlerhaft", | ||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = WlsExceptionDTO.class)) | ||
) | ||
} | ||
) | ||
public void setHandbuch(@PathVariable("wahltagID") String wahltagID, @PathVariable("wahlbezirksart") WahlbezirkArtDTO wahlbezirkArtDTO, | ||
final MultipartHttpServletRequest request) { | ||
try { | ||
val handbuchData = getHandbuchFromRequest(request); | ||
val modelToSet = handbuchDTOMapper.toModel(handbuchDTOMapper.toModel(wahltagID, wahlbezirkArtDTO), handbuchData); | ||
handbuchService.setHandbuch(modelToSet); | ||
} catch (final IOException e) { | ||
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.POSTHANDBUCH_SPEICHERN_NICHT_ERFOLGREICH); | ||
} | ||
} | ||
|
||
private byte[] getHandbuchFromRequest(final MultipartHttpServletRequest request) throws IOException { | ||
val fileName = request.getFileNames().next(); | ||
log.debug("using filename > {}", fileName); | ||
val file = request.getFile(fileName); | ||
|
||
if (file == null) { | ||
throw new IOException("No file was uploaded"); | ||
} | ||
|
||
return file.getBytes(); | ||
} | ||
|
||
private ResponseEntity<byte[]> createPDFResponse(final byte[] responseBody, final WahlbezirkArtDTO wahlbezirkArtDTO) { | ||
val responseHeaders = new HttpHeaders(); | ||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, "application/pdf"); | ||
responseHeaders.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + wahlbezirkArtDTO + manualFileNameSuffix); | ||
|
||
return new ResponseEntity<>(responseBody, responseHeaders, HttpStatus.OK); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...va/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/handbuch/HandbuchDTOMapper.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,13 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.handbuch; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.handbuch.HandbuchReferenceModel; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.handbuch.HandbuchWriteModel; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper | ||
public interface HandbuchDTOMapper { | ||
|
||
HandbuchWriteModel toModel(HandbuchReferenceModel handbuchReferenceModel, byte[] handbuchData); | ||
|
||
HandbuchReferenceModel toModel(String wahltagID, WahlbezirkArtDTO wahlbezirksart); | ||
} |
5 changes: 5 additions & 0 deletions
5
...ava/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/handbuch/WahlbezirkArtDTO.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.basisdatenservice.rest.handbuch; | ||
|
||
public enum WahlbezirkArtDTO { | ||
UWB, BWB | ||
} |
17 changes: 17 additions & 0 deletions
17
...muenchen/oss/wahllokalsystem/basisdatenservice/services/handbuch/HandbuchModelMapper.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,17 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.handbuch; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.Handbuch; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.WahltagIdUndWahlbezirksart; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface HandbuchModelMapper { | ||
|
||
WahltagIdUndWahlbezirksart toEntityID(HandbuchReferenceModel handbuchReferenceModel); | ||
|
||
@Mapping(target = "wahltagIdUndWahlbezirksart.wahltagID", source = "handbuchReferenceModel.wahltagID") | ||
@Mapping(target = "wahltagIdUndWahlbezirksart.wahlbezirksart", source = "handbuchReferenceModel.wahlbezirksart") | ||
@Mapping(target = "handbuch", source = "handbuchData") | ||
Handbuch toEntity(HandbuchWriteModel handbuchWriteModel); | ||
} |
9 changes: 9 additions & 0 deletions
9
...nchen/oss/wahllokalsystem/basisdatenservice/services/handbuch/HandbuchReferenceModel.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,9 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.handbuch; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record HandbuchReferenceModel(@NotNull String wahltagID, | ||
@NotNull WahlbezirkArtModel wahlbezirksart) { | ||
} |
Oops, something went wrong.