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 #663 from it-at-m/191-lesen-und-schreiben-der-stim…
…mzettelumschläge 191 lesen und schreiben der stimmzettelumschläge
- Loading branch information
Showing
30 changed files
with
1,498 additions
and
5 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
46 changes: 46 additions & 0 deletions
46
stack/keycloak/migration/add-authorities-ergebnismeldung-stimmzettelumschlaege.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,46 @@ | ||
id: add authorities ergebnismeldung stimmzettelumschlaege | ||
author: dragonfly28 | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addRole: | ||
name: Ergebnismeldung_BUSINESSACTION_GetStimmzettelumschlaege | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allErgebnismeldungAuthorities | ||
role: Ergebnismeldung_BUSINESSACTION_GetStimmzettelumschlaege | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Ergebnismeldung_BUSINESSACTION_PostStimmzettelumschlaege | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allErgebnismeldungAuthorities | ||
role: Ergebnismeldung_BUSINESSACTION_PostStimmzettelumschlaege | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Ergebnismeldung_READ_Stimmzettelumschlaege | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allErgebnismeldungAuthorities | ||
role: Ergebnismeldung_READ_Stimmzettelumschlaege | ||
clientId: ${SSO_CLIENT_ID} | ||
- addRole: | ||
name: Ergebnismeldung_WRITE_Stimmzettelumschlaege | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allErgebnismeldungAuthorities | ||
role: Ergebnismeldung_WRITE_Stimmzettelumschlaege | ||
clientId: ${SSO_CLIENT_ID} | ||
- addRole: | ||
name: Ergebnismeldung_DELETE_Stimmzettelumschlaege | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allErgebnismeldungAuthorities | ||
role: Ergebnismeldung_DELETE_Stimmzettelumschlaege | ||
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
21 changes: 21 additions & 0 deletions
21
...muenchen/oss/wahllokalsystem/ergebnismeldungservice/common/security/AnonymousHandler.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,21 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.common.security; | ||
|
||
import java.util.Optional; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.security.authentication.AnonymousAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Profile("no-security") | ||
public class AnonymousHandler implements AuthenticationHandler { | ||
@Override | ||
public boolean canHandle(Authentication authentication) { | ||
return authentication instanceof AnonymousAuthenticationToken; | ||
} | ||
|
||
@Override | ||
public Optional<String> getDetail(String detailKey, Authentication authentication) { | ||
return Optional.empty(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...hen/oss/wahllokalsystem/ergebnismeldungservice/common/security/AuthenticationHandler.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.common.security; | ||
|
||
import java.util.Optional; | ||
import org.springframework.security.core.Authentication; | ||
|
||
public interface AuthenticationHandler { | ||
|
||
boolean canHandle(Authentication authentication); | ||
|
||
Optional<String> getDetail(String detailKey, Authentication authentication); | ||
} |
23 changes: 23 additions & 0 deletions
23
...va/de/muenchen/oss/wahllokalsystem/ergebnismeldungservice/common/security/JWTHandler.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.ergebnismeldungservice.common.security; | ||
|
||
import java.util.Optional; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class JWTHandler implements AuthenticationHandler { | ||
|
||
@Override | ||
public boolean canHandle(final Authentication authentication) { | ||
return authentication instanceof JwtAuthenticationToken; | ||
} | ||
|
||
public Optional<String> getDetail(final String detailKey, final Authentication authentication) { | ||
if (authentication instanceof JwtAuthenticationToken jwtToken) { | ||
return Optional.ofNullable(jwtToken.getToken().getClaimAsString(detailKey)); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...okalsystem/ergebnismeldungservice/domain/stimmzettelumschlaege/Stimmzettelumschlaege.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,27 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; | ||
import jakarta.persistence.EmbeddedId; | ||
import jakarta.persistence.Entity; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Stimmzettelumschlaege { | ||
|
||
@EmbeddedId | ||
private BezirkUndWahlID bezirkUndWahlID; | ||
|
||
private LocalDateTime urneneroeffnungsUhrzeit; | ||
|
||
@NotNull | ||
private long anzahlWaehler; | ||
|
||
private Long anzahlWaehler2; | ||
} |
47 changes: 47 additions & 0 deletions
47
.../ergebnismeldungservice/domain/stimmzettelumschlaege/StimmzettelumschlaegeRepository.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,47 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; | ||
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('Ergebnismeldung_READ_Stimmzettelumschlaege')") | ||
public interface StimmzettelumschlaegeRepository extends CrudRepository<Stimmzettelumschlaege, BezirkUndWahlID> { | ||
|
||
String CACHE = "STIMMZETTELUMSCHLAEGE_CACHE"; | ||
|
||
@Override | ||
Iterable<Stimmzettelumschlaege> findAll(); | ||
|
||
@Override | ||
@Cacheable(value = CACHE, key = "#p0") | ||
Optional<Stimmzettelumschlaege> findById(BezirkUndWahlID bezirkUndWahlID); | ||
|
||
@Override | ||
@CachePut(value = CACHE, key = "#p0.bezirkUndWahlID") | ||
@PreAuthorize("hasAuthority('Ergebnismeldung_WRITE_Stimmzettelumschlaege')") | ||
<S extends Stimmzettelumschlaege> S save(S stimmzettelumschlaege); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0") | ||
@PreAuthorize("hasAuthority('Ergebnismeldung_DELETE_Stimmzettelumschlaege')") | ||
void deleteById(BezirkUndWahlID bezirkUndWahlID); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0.bezirkUndWahlID") | ||
@PreAuthorize("hasAuthority('Ergebnismeldung_DELETE_Stimmzettelumschlaege')") | ||
void delete(Stimmzettelumschlaege entity); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Ergebnismeldung_DELETE_Stimmzettelumschlaege')") | ||
void deleteAll(Iterable<? extends Stimmzettelumschlaege> entities); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Ergebnismeldung_DELETE_Stimmzettelumschlaege')") | ||
void deleteAll(); | ||
} |
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
80 changes: 80 additions & 0 deletions
80
...em/ergebnismeldungservice/rest/stimmzettelumschlaege/StimmzettelumschlaegeController.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,80 @@ | ||
package de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.rest.AbstractController; | ||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.stimmzettelumschlaege.StimmzettelumschlaegeService; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; | ||
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 io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
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/stimmzettelumschlaege") | ||
@RequiredArgsConstructor | ||
public class StimmzettelumschlaegeController extends AbstractController { | ||
|
||
private final StimmzettelumschlaegeService stimmzettelumschlaegeService; | ||
private final StimmzettelumschlaegeDTOMapper stimmzettelumschlaegeDTOMapper; | ||
|
||
@Operation(description = "Lesen der Anzahl an Stimmzettelumschlaegen eines Wahlbezirkes für eine Wahl") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Es existiert eine Anzahl an Stimmzettelumschlaegen", | ||
content = { @Content(mediaType = "application/json", schema = @Schema(implementation = StimmzettelumschlaegeDTO.class)) } | ||
), | ||
@ApiResponse( | ||
responseCode = "204", description = "Es existiert keine Anzahl an Stimmzettelumschlaegen 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<StimmzettelumschlaegeDTO> getStimmzettelumschlaege(@PathVariable("wahlID") final String wahlID, | ||
@PathVariable("wahlbezirkID") final String wahlbezirkID) { | ||
val stimmzettelumschlaege = stimmzettelumschlaegeService.getStimmzettelumschlaege(new BezirkUndWahlID(wahlID, wahlbezirkID)); | ||
return okWithBodyOrNoContent(stimmzettelumschlaege.map(stimmzettelumschlaegeDTOMapper::toDTO)); | ||
} | ||
|
||
@Operation(description = "Setzen der Anzahl an Stimmzettelumschlaegen eines Wahlbezirkes für eine Wahl") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Anzahl an Stimmzettelumschlaegen 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}") | ||
public void postStimmzettelumschlaege(@PathVariable("wahlID") final String wahlID, @PathVariable("wahlbezirkID") final String wahlbezirkID, | ||
@RequestBody final StimmzettelumschlaegeDTO stimmzettelumschlaegeDTO) { | ||
stimmzettelumschlaegeService.setStimmzettelumschlaege(new BezirkUndWahlID(wahlID, wahlbezirkID), | ||
stimmzettelumschlaegeDTOMapper.toModel(stimmzettelumschlaegeDTO)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...kalsystem/ergebnismeldungservice/rest/stimmzettelumschlaege/StimmzettelumschlaegeDTO.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.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
|
||
public record StimmzettelumschlaegeDTO(@NotNull BezirkUndWahlID bezirkUndWahlID, | ||
LocalDateTime urneneroeffnungsUhrzeit, | ||
@NotNull long anzahlWaehler, | ||
Long anzahlWaehler2) { | ||
} |
12 changes: 12 additions & 0 deletions
12
...tem/ergebnismeldungservice/rest/stimmzettelumschlaege/StimmzettelumschlaegeDTOMapper.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.rest.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.service.stimmzettelumschlaege.StimmzettelumschlaegeModel; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper | ||
public interface StimmzettelumschlaegeDTOMapper { | ||
|
||
StimmzettelumschlaegeDTO toDTO(StimmzettelumschlaegeModel stimmzettelumschlaegeModel); | ||
|
||
StimmzettelumschlaegeModel toModel(StimmzettelumschlaegeDTO stimmzettelumschlaegeDTO); | ||
} |
11 changes: 11 additions & 0 deletions
11
...stem/ergebnismeldungservice/service/stimmzettelumschlaege/StimmzettelumschlaegeModel.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.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.wls.common.security.domain.BezirkUndWahlID; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.time.LocalDateTime; | ||
|
||
public record StimmzettelumschlaegeModel(@NotNull BezirkUndWahlID bezirkUndWahlID, | ||
LocalDateTime urneneroeffnungsUhrzeit, | ||
@NotNull long anzahlWaehler, | ||
long anzahlWaehler2) { | ||
} |
12 changes: 12 additions & 0 deletions
12
...rgebnismeldungservice/service/stimmzettelumschlaege/StimmzettelumschlaegeModelMapper.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.service.stimmzettelumschlaege; | ||
|
||
import de.muenchen.oss.wahllokalsystem.ergebnismeldungservice.domain.stimmzettelumschlaege.Stimmzettelumschlaege; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper | ||
public interface StimmzettelumschlaegeModelMapper { | ||
|
||
StimmzettelumschlaegeModel toModel(Stimmzettelumschlaege entity); | ||
|
||
Stimmzettelumschlaege toEntity(StimmzettelumschlaegeModel model); | ||
} |
Oops, something went wrong.