Skip to content

Commit

Permalink
Merge pull request #385 from it-at-m/146-reset-wahlen-19_07
Browse files Browse the repository at this point in the history
146 reset wahlen 19 07
  • Loading branch information
Nic12345678 authored Jul 30, 2024
2 parents ebd57c0 + db29c17 commit 9bf12f3
Show file tree
Hide file tree
Showing 18 changed files with 726 additions and 6 deletions.
58 changes: 58 additions & 0 deletions stack/keycloak/migration/add-authorities-basisdaten-wahlen.yml
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}

3 changes: 2 additions & 1 deletion stack/keycloak/migration/keycloak-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ includes:
- path: add-authorities-basisdaten-wahltage.yml
- path: add-authorities-basisdaten-ungueltigewahlscheine.yml
- path: add-authorities-eai-wahlbeteiligung.yml
- path: add-authorities-basisdaten-referendumvorlagen.yml
- path: add-authorities-basisdaten-referendumvorlagen.yml
- path: add-authorities-basisdaten-wahlen.yml
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;
}
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;
}
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);
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ExceptionConstants {
public static ExceptionDataWrapper POSTHANDBUCH_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("315", "postHandbuch: Suchkriterien unvollständig.");
public static ExceptionDataWrapper POSTHANDBUCH_SPEICHERN_NICHT_ERFOLGREICH = new ExceptionDataWrapper("316",
"postHandbuch: Das speichern des Handbuches war nicht erfolgreich.");
public static ExceptionDataWrapper RESET_WAHLEN_NICHT_ERFOLGREICH = new ExceptionDataWrapper("317",
"resetWahlen: Das Zurücksetzen der Wahlen war nicht erfolgreich.");

public static ExceptionDataWrapper GETUNGUELTIGEWAHLSCHEINE_PARAMETER_UNVOLLSTAENDIG = new ExceptionDataWrapper("331",
"getUngueltigews: Suchkriterien unvollständig.");
Expand Down
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();
}
}
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);
}
}
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)
);
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)
);
Loading

0 comments on commit 9bf12f3

Please sign in to comment.