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 #385 from it-at-m/146-reset-wahlen-19_07
146 reset wahlen 19 07
- Loading branch information
Showing
18 changed files
with
726 additions
and
6 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
stack/keycloak/migration/add-authorities-basisdaten-wahlen.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,58 @@ | ||
id: add authorities basisdaten wahlen | ||
author: GerhardPx | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addRole: | ||
name: Basisdaten_BUSINESSACTION_GetWahlen | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_BUSINESSACTION_GetWahlen | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_BUSINESSACTION_PostWahlen | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_BUSINESSACTION_PostWahlen | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_BUSINESSACTION_ResetWahlen | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_BUSINESSACTION_ResetWahlen | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_READ_Wahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_READ_Wahl | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_WRITE_Wahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_WRITE_Wahl | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Basisdaten_DELETE_Wahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allBasisdatenAuthorities | ||
role: Basisdaten_DELETE_Wahl | ||
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
35 changes: 35 additions & 0 deletions
35
...ce/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/wahl/Farbe.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,35 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import jakarta.validation.constraints.Max; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Embeddable | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Farbe { | ||
|
||
@NotNull | ||
@Min(0) | ||
@Max(255) | ||
private long r; | ||
|
||
@NotNull | ||
@Min(0) | ||
@Max(255) | ||
private long g; | ||
|
||
@NotNull | ||
@Min(0) | ||
@Max(255) | ||
private long b; | ||
} |
56 changes: 56 additions & 0 deletions
56
...ice/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/wahl/Wahl.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,56 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl; | ||
|
||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import java.time.LocalDate; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.springframework.stereotype.Indexed; | ||
|
||
@Entity | ||
@Indexed | ||
@Data | ||
@EqualsAndHashCode | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "Wahl") | ||
public class Wahl { | ||
|
||
@Id | ||
@NotNull | ||
@Size(max = 1024) | ||
private String wahlID; | ||
|
||
@Size(max = 255) | ||
private String name; | ||
|
||
@NotNull | ||
private long reihenfolge; | ||
|
||
@NotNull | ||
@Min(1) | ||
private long waehlerverzeichnisnummer; | ||
|
||
@NotNull | ||
private LocalDate wahltag; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@NotNull | ||
private Wahlart wahlart; | ||
|
||
@Embedded | ||
private Farbe farbe; | ||
|
||
@Size(max = 255) | ||
private String nummer; | ||
} |
54 changes: 54 additions & 0 deletions
54
...in/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/wahl/WahlRepository.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,54 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
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_Wahl')") | ||
public interface WahlRepository extends CrudRepository<Wahl, String> { | ||
|
||
String CACHE = "WAHL_CACHE"; | ||
|
||
@Override | ||
List<Wahl> findAll(); | ||
|
||
@Override | ||
@Cacheable(value = CACHE, key = "#p0") | ||
Optional<Wahl> findById(String wahlID); | ||
|
||
@Override | ||
@CachePut(value = CACHE, key = "#p0.wahlID") | ||
@PreAuthorize("hasAuthority('Basisdaten_WRITE_Wahl')") | ||
<S extends Wahl> S save(S entity); | ||
|
||
@Override | ||
@PreAuthorize("hasAuthority('Basisdaten_WRITE_Wahl')") | ||
<S extends Wahl> Iterable<S> saveAll(Iterable<S> entities); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0") | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Wahl')") | ||
void deleteById(String wahlID); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, key = "#p0.wahlID") | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Wahl')") | ||
void delete(Wahl entity); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Wahl')") | ||
void deleteAll(Iterable<? extends Wahl> entities); | ||
|
||
@Override | ||
@CacheEvict(value = CACHE, allEntries = true) | ||
@PreAuthorize("hasAuthority('Basisdaten_DELETE_Wahl')") | ||
void deleteAll(); | ||
|
||
List<Wahl> findByWahltagOrderByReihenfolge(LocalDate wahltag); | ||
} |
5 changes: 5 additions & 0 deletions
5
.../src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/domain/wahl/Wahlart.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.wahl; | ||
|
||
public enum Wahlart { | ||
BAW, BEB, BTW, BZW, EUW, LTW, MBW, OBW, SRW, SVW, VE | ||
} |
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
36 changes: 36 additions & 0 deletions
36
.../java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahlen/WahlenController.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,36 @@ | ||
|
||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahlen; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen.WahlenService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/businessActions/resetWahlen") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class WahlenController { | ||
|
||
private final WahlenService wahlenService; | ||
|
||
@Operation( | ||
description = "Setzt die Attribute Farbe, Reihenfolge und Waehlerverzeichnis der vorhandenen Wahlen auf die Standardwerte.", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Die Wahlen wurden zurückgesetzt." | ||
) | ||
} | ||
) | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public void resetWahlen() { | ||
wahlenService.resetWahlen(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...java/de/muenchen/oss/wahllokalsystem/basisdatenservice/services/wahlen/WahlenService.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,44 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahlen; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Farbe; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.Wahl; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.domain.wahl.WahlRepository; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.exception.ExceptionConstants; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class WahlenService { | ||
|
||
private final WahlRepository wahlRepository; | ||
|
||
private final ExceptionFactory exceptionFactory; | ||
|
||
@PreAuthorize( | ||
"hasAuthority('Basisdaten_BUSINESSACTION_ResetWahlen')" | ||
) | ||
@Transactional | ||
public void resetWahlen() { | ||
log.info("#resetWahlen"); | ||
try { | ||
val existingWahlenToReset = wahlRepository.findAll(); | ||
existingWahlenToReset.forEach(this::resetWahl); | ||
wahlRepository.saveAll(existingWahlenToReset); | ||
} catch (final Exception e) { | ||
throw exceptionFactory.createTechnischeWlsException(ExceptionConstants.RESET_WAHLEN_NICHT_ERFOLGREICH); | ||
} | ||
} | ||
|
||
private void resetWahl(final Wahl wahl) { | ||
wahl.setFarbe(new Farbe(0, 0, 0)); | ||
wahl.setReihenfolge(0); | ||
wahl.setWaehlerverzeichnisnummer(1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
wls-basisdaten-service/src/main/resources/db/migrations/h2/V6_0__createWahlTable.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,15 @@ | ||
create table Wahl | ||
( | ||
wahlid varchar(1024) not null, | ||
name varchar(255) not null, | ||
reihenfolge bigint not null, | ||
waehlerverzeichnisnummer bigint not null, | ||
wahltag datetime not null, | ||
wahlart varchar(255) not null, | ||
r bigint not null, | ||
g bigint not null, | ||
b bigint not null, | ||
nummer varchar(255) not null, | ||
|
||
primary key (wahlid) | ||
); |
15 changes: 15 additions & 0 deletions
15
wls-basisdaten-service/src/main/resources/db/migrations/oracle/V6_0__createWahlTable.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,15 @@ | ||
create table Wahl | ||
( | ||
wahlid varchar(1024) not null, | ||
name varchar(255) not null, | ||
reihenfolge NUMBER(19, 0) not null, | ||
waehlerverzeichnisnummer NUMBER(19, 0) not null, | ||
wahltag TIMESTAMP not null, | ||
wahlart varchar(255) not null, | ||
r NUMBER(19, 0) not null, | ||
g NUMBER(19, 0) not null, | ||
b NUMBER(19, 0) not null, | ||
nummer varchar(255) not null, | ||
|
||
PRIMARY KEY (wahlid) | ||
); |
Oops, something went wrong.