diff --git a/docs/src/features/eai-service/index.md b/docs/src/features/eai-service/index.md index c1a665736..f73bb4250 100644 --- a/docs/src/features/eai-service/index.md +++ b/docs/src/features/eai-service/index.md @@ -31,4 +31,16 @@ Wahlbeteiligungen der Wahllokale kann mitgeteilt werden. ### Wahllokalstatus -Der Zustand in dem sich die Wahllokale befinden kann mitgeteilt werden. \ No newline at end of file +Der Zustand in dem sich die Wahllokale befinden kann mitgeteilt werden. + +## Zugriffsbeschränkungen + +Übersicht über die Endpunkte und die dafür benötigten Rechte: + +| Endpunkt | erforderliche Rechte | +| --- | --- | +| GET /wahldaten/wahlbezirke/{wahlbezirkID}/wahlberechtigte | aoueai_BUSINESSACTION_LoadWahlberechtigte +| GET /wahldaten/wahltage?includingSince | aoueai_BUSINESSACTION_LoadWahltage +| GET /wahldaten/wahlbezirk?forDate&withNummer | aoueai_BUSINESSACTION_LoadWahlbezirke +| GET /wahldaten/wahlen?forDate&withNummer | aoueai_BUSINESSACTION_LoadWahlen +| GET /wahldaten/basisdaten?forDate&withNummer | aoueai_BUSINESSACTION_LoadBasisdaten \ No newline at end of file diff --git a/stack/keycloak/migration/add-authorities-eai-wahldaten.yml b/stack/keycloak/migration/add-authorities-eai-wahldaten.yml new file mode 100644 index 000000000..c40c6a9d1 --- /dev/null +++ b/stack/keycloak/migration/add-authorities-eai-wahldaten.yml @@ -0,0 +1,48 @@ +id: add authorities eai wahldaten +author: MrSebastian +realm: ${SSO_REALM} +changes: + - addRole: + name: aoueai_BUSINESSACTION_LoadWahltage + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: aoueai_BUSINESSACTION_LoadWahltage + clientId: ${SSO_CLIENT_ID} + + - addRole: + name: aoueai_BUSINESSACTION_LoadWahlen + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: aoueai_BUSINESSACTION_LoadWahlen + clientId: ${SSO_CLIENT_ID} + + - addRole: + name: aoueai_BUSINESSACTION_LoadWahlbezirke + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: aoueai_BUSINESSACTION_LoadWahlbezirke + clientId: ${SSO_CLIENT_ID} + + - addRole: + name: aoueai_BUSINESSACTION_LoadWahlberechtigte + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: aoueai_BUSINESSACTION_LoadWahlberechtigte + clientId: ${SSO_CLIENT_ID} + + - addRole: + name: aoueai_BUSINESSACTION_LoadBasisdaten + clientRole: true + clientId: ${SSO_CLIENT_ID} + - assignRoleToGroup: + group: allEaiAuthorities + role: aoueai_BUSINESSACTION_LoadBasisdaten + clientId: ${SSO_CLIENT_ID} \ No newline at end of file diff --git a/stack/keycloak/migration/add-authorities-eai-wahlvorschlag.yml b/stack/keycloak/migration/add-authorities-eai-wahlvorschlag.yml index 0c71e006a..a189c8412 100644 --- a/stack/keycloak/migration/add-authorities-eai-wahlvorschlag.yml +++ b/stack/keycloak/migration/add-authorities-eai-wahlvorschlag.yml @@ -1,4 +1,4 @@ -id: add authorities eai wahlvorstand +id: add authorities eai wahlvorschlag author: dragonfly28 realm: ${SSO_REALM} changes: diff --git a/stack/keycloak/migration/keycloak-changelog.yml b/stack/keycloak/migration/keycloak-changelog.yml index f89904a2f..29ce735a7 100644 --- a/stack/keycloak/migration/keycloak-changelog.yml +++ b/stack/keycloak/migration/keycloak-changelog.yml @@ -32,4 +32,4 @@ includes: - path: create-group-all-basisdaten-authorities.yml - path: add-authorities-basisdaten-wahlvorschlaege.yml - path: add-authorities-eai-wahlvorschlag.yml - + - path: add-authorities-eai-wahldaten.yml \ No newline at end of file diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebiet.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebiet.java new file mode 100644 index 000000000..f3d767b22 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebiet.java @@ -0,0 +1,42 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +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 +@EqualsAndHashCode(callSuper = true) +@ToString(onlyExplicitlyIncluded = true, callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +public class Stimmzettelgebiet extends BaseEntity { + + @ToString.Include + private String nummer; + + @ToString.Include + private String name; + + @NotNull + @Enumerated(EnumType.STRING) + @ToString.Include + private Stimmzettelgebietsart stimmzettelgebietsart; + + @NotNull + @ManyToOne + @JoinColumn(name = "wahlID") + private Wahl wahl; + +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepository.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepository.java new file mode 100644 index 000000000..719e2c9d5 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepository.java @@ -0,0 +1,11 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import java.time.LocalDate; +import java.util.List; +import java.util.UUID; +import org.springframework.data.repository.CrudRepository; + +public interface StimmzettelgebietRepository extends CrudRepository { + + List findByWahlWahltagTagAndWahlWahltagNummer(LocalDate wahltag, String nummer); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebietsart.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebietsart.java new file mode 100644 index 000000000..aef400ed7 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Stimmzettelgebietsart.java @@ -0,0 +1,5 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +public enum Stimmzettelgebietsart { + SB, SG, SK, WK +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahl.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahl.java new file mode 100644 index 000000000..ce7e66e34 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahl.java @@ -0,0 +1,39 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +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 +@EqualsAndHashCode(callSuper = true) +@ToString(onlyExplicitlyIncluded = true, callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +public class Wahl extends BaseEntity { + + @NotNull + @ToString.Include + private String name; + + @NotNull + @ToString.Include + @Enumerated(EnumType.STRING) + private Wahlart wahlart; + + @NotNull + @ManyToOne + @JoinColumn(name = "wahltagID") + private Wahltag wahltag; +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepository.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepository.java new file mode 100644 index 000000000..230e6bb47 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepository.java @@ -0,0 +1,11 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import java.time.LocalDate; +import java.util.List; +import java.util.UUID; +import org.springframework.data.repository.CrudRepository; + +public interface WahlRepository extends CrudRepository { + + List findByWahltagTagAndWahltagNummer(LocalDate wahltag, String nummer); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlart.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlart.java new file mode 100644 index 000000000..b1bcf7dc9 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlart.java @@ -0,0 +1,5 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +public enum Wahlart { + BAW, BEB, BTW, BZW, EUW, LTW, MBW, OBW, SRW, SVW, VE +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlbezirk.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlbezirk.java new file mode 100644 index 000000000..4c5626461 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahlbezirk.java @@ -0,0 +1,48 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +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 +@EqualsAndHashCode(callSuper = true) +@ToString(onlyExplicitlyIncluded = true, callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +public class Wahlbezirk extends BaseEntity { + + @NotNull + @ToString.Include + @Enumerated(EnumType.STRING) + private WahlbezirkArt wahlbezirkArt; + + @NotNull + @ToString.Include + private String nummer; + + @NotNull + @ManyToOne + @JoinColumn(name = "stimmzettelgebietID") + private Stimmzettelgebiet stimmzettelgebiet; + + @ToString.Include + private long a1; + + @ToString.Include + private long a2; + + @ToString.Include + private long a3; +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkArt.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkArt.java new file mode 100644 index 000000000..26028722f --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkArt.java @@ -0,0 +1,5 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +public enum WahlbezirkArt { + UWB, BWB +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepository.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepository.java new file mode 100644 index 000000000..04c76d3da --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepository.java @@ -0,0 +1,20 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import java.time.LocalDate; +import java.util.List; +import java.util.UUID; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +public interface WahlbezirkRepository extends CrudRepository { + + @Query( + "SELECT wb FROM Wahlbezirk wb JOIN FETCH wb.stimmzettelgebiet sg JOIN FETCH sg.wahl w JOIN FETCH w.wahltag t WHERE t.tag = (:wahltag) AND t.nummer = (:nummer)" + ) + List findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(@Param("wahltag") LocalDate wahltag, + @Param("nummer") String nummer); + + @Query("SELECT wb FROM Wahlbezirk wb JOIN FETCH wb.stimmzettelgebiet sg JOIN FETCH sg.wahl w JOIN FETCH w.wahltag t WHERE wb.id = (:wahlbezirkID)") + List findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID(@Param("wahlbezirkID") UUID wahlbezirkID); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahltag.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahltag.java new file mode 100644 index 000000000..73a90005a --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/Wahltag.java @@ -0,0 +1,34 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity; +import jakarta.persistence.Entity; +import jakarta.validation.constraints.NotNull; +import java.time.LocalDate; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Entity +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +@ToString(onlyExplicitlyIncluded = true, callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +public class Wahltag extends BaseEntity { + + @NotNull + @ToString.Include + private LocalDate tag; + + @NotNull + @ToString.Include + private String beschreibung; + + @NotNull + @ToString.Include + private String nummer; +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepository.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepository.java new file mode 100644 index 000000000..810f0a8af --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepository.java @@ -0,0 +1,11 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import java.time.LocalDate; +import java.util.List; +import java.util.UUID; +import org.springframework.data.repository.CrudRepository; + +public interface WahltageRepository extends CrudRepository { + + List findByTagAfterOrTagEquals(LocalDate afterDate, LocalDate equalsDate); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/ExceptionConstants.java index fffb903a8..8e75ec0b0 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/ExceptionConstants.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/ExceptionConstants.java @@ -26,6 +26,25 @@ public class ExceptionConstants { public static final ExceptionDataWrapper LOADREFERENDUMVORLAGEN_WAHLID_FEHLT = new ExceptionDataWrapper( CODE_WAHLID_FEHLT, MESSAGE_WAHLID_FEHLT); + //loadBasisdaten + public static final ExceptionDataWrapper LOADBASISDATEN_TAG_FEHLT = new ExceptionDataWrapper("001", "Es ist kein Tag definiert"); + public static final ExceptionDataWrapper LOADBASISDATEN_NUMMER_FEHLT = new ExceptionDataWrapper("001_1", "Es ist keine Wahlnummer angegeben"); + + //loadWahlberechtigte + public static final ExceptionDataWrapper LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG = new ExceptionDataWrapper("001", + "Wahlberechtigtenkriterien sind nicht vollständig"); + + //loadWahltage + public static final ExceptionDataWrapper LOADWAHLTAGE_TAG_FEHLT = new ExceptionDataWrapper("001", "Es ist kein Tag definiert"); + + //loadWahlbezirke + public static final ExceptionDataWrapper LOADWAHLBEZIRKE_WAHLTAG_FEHLT = new ExceptionDataWrapper("001", "Es ist kein Wahltag angegeben"); + public static final ExceptionDataWrapper LOADWAHLBEZIRKE_NUMMER_FEHLT = new ExceptionDataWrapper("001_1", "Es ist keine Wahltag-Nummer angegeben"); + + //loadWahlen + public static final ExceptionDataWrapper LOADWAHLEN_WAHLTAG_FEHLT = new ExceptionDataWrapper("001", "Es ist kein Wahltag angegeben"); + public static final ExceptionDataWrapper LOADWAHLEN_NUMMER_FEHLT = new ExceptionDataWrapper("001_1", "Es ist keine Wahlnummer angegeben"); + /** * @throws IllegalAccessException when constructor is used */ diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java index c8ae9c951..48503d2ce 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/GlobalExceptionHandler.java @@ -1,22 +1,35 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.exception; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.AbstractExceptionHandler; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.DTOMapper; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ServiceIDFormatter; import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.context.request.ServletWebRequest; @ControllerAdvice @Slf4j public class GlobalExceptionHandler extends AbstractExceptionHandler { private final ServiceIDFormatter serviceIDFormatter; - public GlobalExceptionHandler(final ServiceIDFormatter serviceIDFormatter, final DTOMapper dtoMapper) { + private final MissingRequestParameterExceptionDataWrapperMapper missingRequestParameterExceptionDataWrapperMapper; + + public GlobalExceptionHandler(final ServiceIDFormatter serviceIDFormatter, final DTOMapper dtoMapper, + final MissingRequestParameterExceptionDataWrapperMapper missingRequestParameterExceptionDataWrapperMappers) { super(dtoMapper); this.serviceIDFormatter = serviceIDFormatter; + this.missingRequestParameterExceptionDataWrapperMapper = missingRequestParameterExceptionDataWrapperMappers; } @ExceptionHandler @@ -25,6 +38,21 @@ public ResponseEntity handleThrowables(final Throwable throwabl return createResponse(getWahlExceptionDTO(throwable)); } + @ExceptionHandler + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ResponseBody + public WlsExceptionDTO handleThrowable(final MissingServletRequestParameterException missingRequestParameter, + final ServletWebRequest webRequest) { + val requestParameterName = missingRequestParameter.getParameterName(); + val requestURI = webRequest.getRequest().getRequestURI(); + + log.info("missing request parameter -> {}", requestParameterName); + log.info("path > {}", requestURI); + + return missingRequestParameterExceptionDataWrapperMapper.getExceptionDataWrapperForMissingRequestParameterByName(requestURI, requestParameterName) + .map(this::createFachlicheWlsExceptionDTO).orElseGet(this::createGenericMissingParameterExceptionDTO); + } + @ExceptionHandler public ResponseEntity handleNotFoundException(final NotFoundException notFoundException) { log.debug("not found entity {} with id {}", notFoundException.getEntityClass(), notFoundException.getRequestedID()); @@ -42,4 +70,12 @@ public ResponseEntity handleNoSearchResultFoundException(final NoSearchRes protected String getService() { return serviceIDFormatter.getId(); } + + private WlsExceptionDTO createGenericMissingParameterExceptionDTO() { + return createFachlicheWlsExceptionDTO(ExceptionConstants.DATENALLGEMEIN_PARAMETER_FEHLEN); + } + + private WlsExceptionDTO createFachlicheWlsExceptionDTO(final ExceptionDataWrapper exceptionDataWrapper) { + return new WlsExceptionDTO(WlsExceptionCategory.F, exceptionDataWrapper.code(), getService(), exceptionDataWrapper.message()); + } } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/MissingRequestParameterExceptionDataWrapperMapper.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/MissingRequestParameterExceptionDataWrapperMapper.java new file mode 100644 index 000000000..68903c1d0 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/exception/MissingRequestParameterExceptionDataWrapperMapper.java @@ -0,0 +1,48 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.exception; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.WahldatenController; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Pattern; +import lombok.val; +import org.springframework.stereotype.Component; + +@Component +public class MissingRequestParameterExceptionDataWrapperMapper { + + private static final String WAHLDATEN_SERVLET_PATH = WahldatenController.WAHLDATEN_REQUEST_MAPPING; + + private static final String PATTERN_ANY_OTHER_CHAR = ".*"; + + final Map> mapMissingRequestParameters = new HashMap<>(); + + { + addExceptionDataWrapper("includingSince", WAHLDATEN_SERVLET_PATH + "/wahltage", ExceptionConstants.LOADWAHLTAGE_TAG_FEHLT); + addExceptionDataWrapper("forDate", WAHLDATEN_SERVLET_PATH + "/wahlbezirk", ExceptionConstants.LOADWAHLBEZIRKE_WAHLTAG_FEHLT); + addExceptionDataWrapper("withNummer", WAHLDATEN_SERVLET_PATH + "/wahlbezirk", ExceptionConstants.LOADWAHLBEZIRKE_NUMMER_FEHLT); + addExceptionDataWrapper("forDate", WAHLDATEN_SERVLET_PATH + "/wahlen", ExceptionConstants.LOADWAHLEN_WAHLTAG_FEHLT); + addExceptionDataWrapper("withNummer", WAHLDATEN_SERVLET_PATH + "/wahlen", ExceptionConstants.LOADWAHLEN_NUMMER_FEHLT); + addExceptionDataWrapper("forDate", WAHLDATEN_SERVLET_PATH + "/basisdaten", ExceptionConstants.LOADBASISDATEN_TAG_FEHLT); + addExceptionDataWrapper("withNummer", WAHLDATEN_SERVLET_PATH + "/basisdaten", ExceptionConstants.LOADBASISDATEN_NUMMER_FEHLT); + } + + public Optional getExceptionDataWrapperForMissingRequestParameterByName(final String servletPath, final String requestParameterName) { + val mappingsForParameter = mapMissingRequestParameters.get(requestParameterName); + if (mappingsForParameter == null) { + return Optional.empty(); + } + + val patternMapping = mappingsForParameter.keySet().stream().filter(pattern -> pattern.matcher(servletPath).matches()).findFirst(); + return patternMapping.map(mappingsForParameter::get); + } + + private void addExceptionDataWrapper(final String parameterName, final String pathPattern, final ExceptionDataWrapper exceptionDataWrapper) { + val mapForParameter = mapMissingRequestParameters.getOrDefault(parameterName, new HashMap<>()); + + mapForParameter.put(Pattern.compile(pathPattern), exceptionDataWrapper); + + mapMissingRequestParameters.put(parameterName, mapForParameter); + } +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenController.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenController.java index fca331e4e..373818249 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenController.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenController.java @@ -1,12 +1,15 @@ package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkeDTO; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlenDTO; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltageDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten.WahldatenService; import java.time.LocalDate; import java.util.List; +import java.util.Set; +import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -16,36 +19,41 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/wahldaten") +@RequestMapping(WahldatenController.WAHLDATEN_REQUEST_MAPPING) +@RequiredArgsConstructor public class WahldatenController { + public static final String WAHLDATEN_REQUEST_MAPPING = "/wahldaten"; + + private final WahldatenService wahldatenService; + @GetMapping("wahlbezirke/{wahlbezirkID}/wahlberechtigte") @ResponseStatus(HttpStatus.OK) public List loadWahlberechtigte(@PathVariable("wahlbezirkID") String wahlbezirkID) { - throw new UnsupportedOperationException("Not supported yet."); + return wahldatenService.getWahlberechtigte(wahlbezirkID); } @GetMapping("wahltage") @ResponseStatus(HttpStatus.OK) - public WahltageDTO loadWahltageSinceIncluding(@RequestParam("includingSince") LocalDate tag) { - throw new UnsupportedOperationException("Not supported yet."); + public Set loadWahltageSinceIncluding(@RequestParam("includingSince") LocalDate tag) { + return wahldatenService.getWahltage(tag); } @GetMapping("wahlbezirk") @ResponseStatus(HttpStatus.OK) - public WahlbezirkeDTO loadWahlbezirke(@RequestParam("forDate") LocalDate wahltag, @RequestParam("withNummer") String nummer) { - throw new UnsupportedOperationException("Not supported yet."); + public Set loadWahlbezirke(@RequestParam("forDate") LocalDate wahltag, @RequestParam("withNummer") String nummer) { + return wahldatenService.getWahlbezirke(wahltag, nummer); } @GetMapping("wahlen") @ResponseStatus(HttpStatus.OK) - public WahlenDTO loadWahlen(@RequestParam("forDate") LocalDate wahltag, @RequestParam("withNummer") String nummer) { - throw new UnsupportedOperationException("Not supported yet."); + public Set loadWahlen(@RequestParam("forDate") LocalDate wahltag, @RequestParam("withNummer") String nummer) { + return wahldatenService.getWahlen(wahltag, nummer); } @GetMapping("basisdaten") @ResponseStatus(HttpStatus.OK) public BasisdatenDTO loadBasisdaten(@RequestParam("forDate") LocalDate wahltag, @RequestParam("withNummer") String nummer) { - throw new UnsupportedOperationException("Not supported yet."); + return wahldatenService.getBasisdaten(wahltag, nummer); } } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/BasisstrukturdatenDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/BasisstrukturdatenDTO.java index 3e7953efe..2bd7754b8 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/BasisstrukturdatenDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/BasisstrukturdatenDTO.java @@ -2,7 +2,9 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDate; +import lombok.Builder; +@Builder public record BasisstrukturdatenDTO(@NotNull String wahlID, @NotNull String stimmzettelgebietID, @NotNull String wahlbezirkID, diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/StimmzettelgebietDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/StimmzettelgebietDTO.java index e513782a4..3c9c73826 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/StimmzettelgebietDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/StimmzettelgebietDTO.java @@ -2,10 +2,12 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDate; +import lombok.Builder; +@Builder public record StimmzettelgebietDTO(String identifikator, String nummer, String name, LocalDate wahltag, - @NotNull StimmzettelgebietsartDTO stimmzettelgebietart) { + @NotNull StimmzettelgebietsartDTO stimmzettelgebietsart) { } diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlDTO.java index e891e392a..48fb23e5d 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlDTO.java @@ -3,7 +3,9 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.dto.WahlartDTO; import jakarta.validation.constraints.NotNull; import java.time.LocalDate; +import lombok.Builder; +@Builder public record WahlDTO(@NotNull String identifikator, @NotNull String name, @NotNull WahlartDTO wahlart, diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlberechtigteDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlberechtigteDTO.java index fd8637765..7f566f420 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlberechtigteDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlberechtigteDTO.java @@ -2,7 +2,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; +import lombok.Builder; +@Builder public record WahlberechtigteDTO(@NotNull String wahlID, @NotNull String wahlbezirkID, @Schema(requiredMode = Schema.RequiredMode.REQUIRED) long a1, diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkDTO.java index 361b6d001..6ac560c53 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkDTO.java @@ -2,7 +2,9 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDate; +import lombok.Builder; +@Builder public record WahlbezirkDTO(@NotNull String identifikator, @NotNull WahlbezirkArtDTO wahlbezirkArt, @NotNull String nummer, diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkeDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkeDTO.java deleted file mode 100644 index c39dbc899..000000000 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlbezirkeDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.util.Set; - -public record WahlbezirkeDTO(@NotNull @Size(min = 1) Set wahlbezirke) { -} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlenDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlenDTO.java deleted file mode 100644 index c4ab289b9..000000000 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahlenDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.util.Set; - -public record WahlenDTO(@NotNull @Size(min = 1) Set wahlen) { -} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltagDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltagDTO.java index 0b3f90872..cb5a3726b 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltagDTO.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltagDTO.java @@ -2,7 +2,9 @@ import jakarta.validation.constraints.NotNull; import java.time.LocalDate; +import lombok.Builder; +@Builder public record WahltagDTO(@NotNull String identifikator, @NotNull LocalDate tag, @NotNull String beschreibung, diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltageDTO.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltageDTO.java deleted file mode 100644 index a3da99e17..000000000 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/dto/WahltageDTO.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.util.Set; - -public record WahltageDTO(@NotNull @Size(min = 1) Set wahltage) { -} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/exception/ExceptionConstants.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/exception/ExceptionConstants.java deleted file mode 100644 index a4b468bdb..000000000 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/exception/ExceptionConstants.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.exception; - -public class ExceptionConstants { - - //loadBasisdaten - public static final String CODE_LOADBASISDATEN_TAG_FEHLT = "001"; - public static final String MESSAGE_LOADBASISDATEN_TAG_FEHLT = "Es ist kein Tag definiert"; - - //loadWahlberechtigte - public static final String CODE_LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG = "001"; - public static final String MESSAGE_LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG = "Wahlberechtigtenkriterien sind nicht vollständig"; - - //loadWahltage - public static final String CODE_LOADWAHLTAGE_TAG_FEHLT = "001"; - public static final String MESSAGE_LOADWAHLTAGE_TAG_FEHLT = "Es ist kein Tag definiert"; - - //loadWahlbezirke - public static final String CODE_LOADWAHLBEZIRKE_WAHLTAG_FEHLT = "001"; - public static final String CODE_LOADWAHLBEZIRKE_NUMMER_FEHLT = "001_1"; - public static final String MESSAGE_LOADWAHLEBZIRKE_WAHLTAG_FEHLT = "Es ist kein Wahltag angegeben"; - public static final String MESSAGE_LOADWAHLEBZIRKE_NUMMER_FEHLT = "Es ist keine Wahltag-Nummer angegeben"; - - //loadWahlen - public static final String CODE_LOADWAHLEN_WAHLTAG_FEHLT = "001"; - public static final String MESSAGE_LOADWAHLEN_WAHLTAG_FEHLT = "Es ist kein Wahltag angegeben"; - public static final String CODE_LOADWAHLEN_NUMMER_FEHLT = "001_1"; - public static final String MESSAGE_LOADWAHLEN_NUMMER_FEHLT = "Es ist keine Wahlnummer angegeben"; - - /** - * @throws IllegalAccessException when constructor is used - */ - private ExceptionConstants() throws IllegalAccessException { - throw new IllegalAccessException("dont create instanced - it is just a holder for constants"); - } -} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverter.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverter.java new file mode 100644 index 000000000..aa2aa79d7 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverter.java @@ -0,0 +1,24 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class IDConverter { + + private final ExceptionFactory exceptionFactory; + + //CHECKSTYLE.OFF: AbbreviationAsWordInName - illegal match cause UUID should not be shortened + public UUID convertIDToUUIDOrThrow(final String id) { + //CHECKSTYLE.ON: AbbreviationAsWordInName + try { + return UUID.fromString(id); + } catch (final IllegalArgumentException illegalArgumentException) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR); + } + } +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapper.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapper.java new file mode 100644 index 000000000..145edbb35 --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapper.java @@ -0,0 +1,46 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebiet; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahl; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlbezirk; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahltag; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisstrukturdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.StimmzettelgebietDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface WahldatenMapper { + + @Mapping(target = "identifikator", source = "id") + WahltagDTO toDTO(Wahltag wahltag); + + @Mapping(target = "identifikator", source = "id") + @Mapping(target = "wahltag", source = "wahltag.tag") + @Mapping(target = "nummer", source = "wahltag.nummer") + WahlDTO toDTO(Wahl wahl); + + @Mapping(target = "identifikator", source = "id") + @Mapping(target = "wahltag", source = "stimmzettelgebiet.wahl.wahltag.tag") + @Mapping(target = "wahlID", source = "stimmzettelgebiet.wahl.id") + @Mapping(target = "wahlnummer", source = "stimmzettelgebiet.wahl.wahltag.nummer") + WahlbezirkDTO toDTO(Wahlbezirk wahlbezirk); + + @Mapping(target = "identifikator", source = "id") + @Mapping(target = "wahltag", source = "wahl.wahltag.tag") + StimmzettelgebietDTO toDTO(Stimmzettelgebiet stimmzettelgebiet); + + @Mapping(target = "wahlID", source = "stimmzettelgebiet.wahl.id") + @Mapping(target = "wahlbezirkID", source = "id") + WahlberechtigteDTO toWahlberechtigteDTO(Wahlbezirk wahlbezirk); + + @Mapping(target = "wahlID", source = "stimmzettelgebiet.wahl.id") + @Mapping(target = "wahltag", source = "stimmzettelgebiet.wahl.wahltag.tag") + @Mapping(target = "wahlbezirkID", source = "id") + @Mapping(target = "stimmzettelgebietID", source = "stimmzettelgebiet.id") + BasisstrukturdatenDTO toBasisstrukturdatenDTO(Wahlbezirk wahlbezirk); +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenService.java new file mode 100644 index 000000000..f3397597c --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenService.java @@ -0,0 +1,99 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.StimmzettelgebietRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlbezirk; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlbezirkRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahltag; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahltageRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.IDConverter; +import java.time.LocalDate; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +@Service +@RequiredArgsConstructor +@Validated +public class WahldatenService { + + private final WahldatenMapper wahldatenMapper; + + private final WahldatenValidator wahldatenValidator; + + private final IDConverter idConverter; + + private final WahltageRepository wahltageRepository; + + private final WahlRepository wahlRepository; + + private final WahlbezirkRepository wahlbezirkRepository; + + private final StimmzettelgebietRepository stimmzettelgebietRepository; + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahltage')") + public Set getWahltage(LocalDate wahltageIncludingSince) { + wahldatenValidator.validGetWahltageParameterOrThrow(wahltageIncludingSince); + + return getWahltageIncludingSince(wahltageIncludingSince).stream().map(wahldatenMapper::toDTO).collect(Collectors.toSet()); + } + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlen')") + public Set getWahlen(final LocalDate wahltag, final String nummer) { + wahldatenValidator.validGetWahlenParameterOrThrow(wahltag, nummer); + + return wahlRepository.findByWahltagTagAndWahltagNummer(wahltag, nummer).stream().map(wahldatenMapper::toDTO).collect(Collectors.toSet()); + } + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlbezirke')") + public Set getWahlbezirke(final LocalDate wahltag, final String nummer) { + wahldatenValidator.validGetWahlbezirkeParameterOrThrow(wahltag, nummer); + + return findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagById(wahltag, nummer).stream().map(wahldatenMapper::toDTO) + .collect(Collectors.toSet()); + } + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlberechtigte')") + public List getWahlberechtigte(final String wahlbezirkID) { + wahldatenValidator.validGetWahlberechtigteParameterOrThrow(wahlbezirkID); + + return wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID(idConverter.convertIDToUUIDOrThrow(wahlbezirkID)) + .stream() + .map(wahldatenMapper::toWahlberechtigteDTO) + .toList(); + } + + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadBasisdaten')") + public BasisdatenDTO getBasisdaten(final LocalDate wahltag, final String nummer) { + wahldatenValidator.validGetBasisdatenParameterOrThrow(wahltag, nummer); + + val wahlbezirkeWithParentEntities = findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagById(wahltag, nummer); + + val basisstrukturdaten = wahlbezirkeWithParentEntities.stream().map(wahldatenMapper::toBasisstrukturdatenDTO).collect(Collectors.toSet()); + val wahlen = getWahlen(wahltag, nummer); + val wahlbezirke = wahlbezirkeWithParentEntities.stream().map(wahldatenMapper::toDTO).collect(Collectors.toSet()); + val stimmzettelgebiete = stimmzettelgebietRepository.findByWahlWahltagTagAndWahlWahltagNummer(wahltag, nummer).stream().map(wahldatenMapper::toDTO) + .collect( + Collectors.toSet()); + + return new BasisdatenDTO(basisstrukturdaten, wahlen, wahlbezirke, stimmzettelgebiete); + } + + private List findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagById(final LocalDate wahltag, final String nummer) { + return wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(wahltag, nummer); + } + + private List getWahltageIncludingSince(LocalDate wahltageIncludingSince) { + return wahltageRepository.findByTagAfterOrTagEquals(wahltageIncludingSince, wahltageIncludingSince); + } +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidator.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidator.java new file mode 100644 index 000000000..437a50b3a --- /dev/null +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidator.java @@ -0,0 +1,58 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDate; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class WahldatenValidator { + + private final ExceptionFactory exceptionFactory; + + public void validGetWahltageParameterOrThrow(final LocalDate wahltag) { + if (wahltag == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLTAGE_TAG_FEHLT); + } + } + + public void validGetWahlenParameterOrThrow(final LocalDate wahltag, final String nummer) { + if (wahltag == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLEN_WAHLTAG_FEHLT); + } + + if (nummer == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLEN_NUMMER_FEHLT); + } + } + + public void validGetWahlbezirkeParameterOrThrow(final LocalDate wahltag, final String nummer) { + if (wahltag == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBEZIRKE_WAHLTAG_FEHLT); + } + + if (nummer == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBEZIRKE_NUMMER_FEHLT); + } + } + + public void validGetWahlberechtigteParameterOrThrow(final String wahlbezirkID) { + if (StringUtils.isBlank(wahlbezirkID)) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG); + } + } + + public void validGetBasisdatenParameterOrThrow(final LocalDate wahltag, final String nummer) { + if (wahltag == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADBASISDATEN_TAG_FEHLT); + } + + if (nummer == null) { + throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADBASISDATEN_NUMMER_FEHLT); + } + } + +} diff --git a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java index 3b2c971ca..9c3b913a2 100644 --- a/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java +++ b/wls-eai-service/src/main/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandService.java @@ -4,11 +4,10 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandRepository; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.IDConverter; import java.time.LocalDateTime; import java.util.UUID; import lombok.RequiredArgsConstructor; @@ -22,16 +21,16 @@ public class WahlvorstandService { private final WahlvorstandRepository wahlvorstandRepository; - private final ExceptionFactory exceptionFactory; - private final WahlvorstandMapper wahlvorstandMapper; private final WahlvorstandValidator wahlvorstandValidator; + private final IDConverter idConverter; + @PreAuthorize("hasAuthority('aoueai_BUSINESSACTION_LoadWahlvorstand')") public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { wahlvorstandValidator.validateWahlbezirkIDOrThrow(wahlbezirkID); - val wahlbezirkUUID = convertIDToUUIDOrThrow(wahlbezirkID); + val wahlbezirkUUID = idConverter.convertIDToUUIDOrThrow(wahlbezirkID); return wahlvorstandMapper.toDTO(findByWahlbezirkIDOrThrow(wahlbezirkUUID)); } @@ -39,7 +38,7 @@ public WahlvorstandDTO getWahlvorstandForWahlbezirk(final String wahlbezirkID) { public void setAnwesenheit(final WahlvorstandsaktualisierungDTO aktualisierung) { wahlvorstandValidator.validateSaveAnwesenheitDataOrThrow(aktualisierung); - val wahlvorstandToUpdate = findByWahlbezirkIDOrThrow(convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); + val wahlvorstandToUpdate = findByWahlbezirkIDOrThrow(idConverter.convertIDToUUIDOrThrow(aktualisierung.wahlbezirkID())); updateAnwesenheitOfWahlvorstand(aktualisierung, wahlvorstandToUpdate); wahlvorstandRepository.save(wahlvorstandToUpdate); } @@ -58,16 +57,6 @@ private void updateAnwesenheitOfWahlvorstandsmitglied(final LocalDateTime timeOf mitglied.setAnwesend(mitgliedUpdateData.anwesend()); } - //CHECKSTYLE.OFF: AbbreviationAsWordInName - illegal match cause UUID should not be shortened - private UUID convertIDToUUIDOrThrow(final String id) { - //CHECKSTYLE.ON: AbbreviationAsWordInName - try { - return UUID.fromString(id); - } catch (final IllegalArgumentException illegalArgumentException) { - throw exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR); - } - } - private Wahlvorstand findByWahlbezirkIDOrThrow(final UUID wahlbezirkID) { return wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID).orElseThrow(() -> new NotFoundException(wahlbezirkID, Wahlvorstand.class)); } diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_0_1__wahltageTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_0_1__wahltageTestdaten.sql new file mode 100644 index 000000000..64d2f0def --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_0_1__wahltageTestdaten.sql @@ -0,0 +1,5 @@ +INSERT INTO wahltag (id, tag, beschreibung, nummer) +values ('00000000-0000-0000-0000-000000000001', '2024-06-09', 'zehnte Direktwahl zum Europäischen Parlament', '0'); + +INSERT INTO wahltag (id, tag, beschreibung, nummer) +values ('00000000-0000-0000-0000-000000000002', '2020-03-15', 'Kommunalwahl 20', '0'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_1_1__wahlTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_1_1__wahlTestdaten.sql new file mode 100644 index 000000000..6c665d0b2 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_1_1__wahlTestdaten.sql @@ -0,0 +1,13 @@ +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000001', 'EU-Wahl 24', 'EUW', '00000000-0000-0000-0000-000000000001'); + +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000002', 'Stadtratswahl', 'SRW', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000003', 'Oberbürgermeisterwahl', 'OBW', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000004', 'Bezirksausschusswahl', 'BAW', + '00000000-0000-0000-0000-000000000002'); + +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000005', 'Volksentscheid', 'VE', '00000000-0000-0000-0000-000000000001'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_2_1__stimmzettelgebietTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_2_1__stimmzettelgebietTestdaten.sql new file mode 100644 index 000000000..0978db3d3 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_2_1__stimmzettelgebietTestdaten.sql @@ -0,0 +1,16 @@ +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000001', '101', 'Stimmzettelgebiet 101', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000002', '102', 'Stimmzettelgebiet 102', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000003', '103', 'Stimmzettelgebiet 103', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000004', '104', 'Stimmzettelgebiet 104', 'SK', + '00000000-0000-0000-0000-000000000001'); + +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000005', '101', 'VE-SZG-1', 'SK', + '00000000-0000-0000-0000-000000000005'); diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_3_1__wahlbezirkTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_3_1__wahlbezirkTestdaten.sql new file mode 100644 index 000000000..bef72b808 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_3_1__wahlbezirkTestdaten.sql @@ -0,0 +1,19 @@ +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000001', 'UWB', 'Wahlbezirk 1', '00000000-0000-0000-0000-000000000001', 30, 5, + 1); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000002', 'UWB', 'Wahlbezirk 2', '00000000-0000-0000-0000-000000000002', 32, 12, + 2); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000003', 'BWB', 'Wahlbezirk 3', '00000000-0000-0000-0000-000000000003', 17, 1, + 0); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000004', 'UWB', 'Wahlbezirk 4', '00000000-0000-0000-0000-000000000004', 42, 5, + 3); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000005', 'UWB', 'Wahlbezirk 4', '00000000-0000-0000-0000-000000000005', 42, 5, + 3); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql new file mode 100644 index 000000000..27130a68a --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql @@ -0,0 +1,8 @@ +DELETE kandidat; +DELETE wahlvorschlag; +DELETE wahlvorschlaege; +DELETE wahlvorschlaegeliste; + +DELETE referendumoption; +DELETE referendumvorlage; +DELETE referendumvorlagen; \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_2__createWahlvorschlaegeListen.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_2__createWahlvorschlaegeListen.sql new file mode 100644 index 000000000..a6891c64e --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_2__createWahlvorschlaegeListen.sql @@ -0,0 +1,7 @@ +-- für EU-Wahl +INSERT INTO wahlvorschlaegeliste (id, wahltag, wahlID) +VALUES ('00000001-0000-0000-0000-000000000001', '2024-06-09', '00000000-0000-0000-0000-000000000001'); + +-- für VE +INSERT INTO wahlvorschlaegeliste (id, wahltag, wahlID) +VALUES ('00000001-0000-0000-0000-000000000002', '2024-06-09', '00000000-0000-0000-0000-000000000005'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql new file mode 100644 index 000000000..0ae03276f --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql @@ -0,0 +1,321 @@ +-- ######################### +-- ## für EU-Wahl +-- ######################### +-- ## Wahlbezirk1 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000001', 1, 'Die Besten', true, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000001', 'Clapton', 1, false, 10, false, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000002', 'Jagger', 2, false, 11, false, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000003', 'Prince', 3, false, 15, false, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000004', 'Mac', 4, false, 16, true, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000005', 'Cool', 5, true, 25, true, + '00000000-0000-0000-0001-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000002', 2, 'Die Zweitbesten', true, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000006', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000007', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000008', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000009', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000010', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000002'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000003', 3, 'Die Drittbesten', true, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000011', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000012', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000013', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000014', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000015', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000003'); + +-- ######################### +-- ## Wahlbezirk2 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000002', '00000000-0000-0000-0000-000000000002', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000004', 1, 'Die Besten', true, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000016', 'Clapton', 1, false, 10, false, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000017', 'Jagger', 2, false, 11, false, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000018', 'Prince', 3, false, 15, false, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000019', 'Mac', 4, false, 16, true, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000020', 'Cool', 5, true, 25, true, + '00000000-0000-0000-0001-000000000004'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000005', 2, 'Die Zweitbesten', true, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000021', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000022', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000023', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000024', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000025', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000005'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000006', 3, 'Die Drittbesten', true, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000026', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000027', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000028', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000029', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000030', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000006'); + +-- ######################### +-- ## Wahlbezirk3 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000003', '00000000-0000-0000-0000-000000000003', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000003', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000007', 1, 'Die Besten', true, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000031', 'Clapton', 1, false, 10, false, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000032', 'Jagger', 2, false, 11, false, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000033', 'Prince', 3, false, 15, false, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000034', 'Mac', 4, false, 16, true, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000035', 'Cool', 5, true, 25, true, + '00000000-0000-0000-0001-000000000007'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000008', 2, 'Die Zweitbesten', true, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000036', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000037', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000038', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000039', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000040', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000008'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000009', 3, 'Die Drittbesten', true, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000041', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000042', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000043', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000044', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000045', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000009'); + +-- ######################### +-- ## Wahlbezirk4 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000004', '00000000-0000-0000-0000-000000000004', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000004', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000010', 1, 'Die Besten', true, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000046', 'Clapton', 1, false, 10, false, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000047', 'Jagger', 2, false, 11, false, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000048', 'Prince', 3, false, 15, false, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000049', 'Mac', 4, false, 16, true, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000050', 'Cool', 5, true, 25, true, + '00000000-0000-0000-0001-000000000010'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000011', 2, 'Die Zweitbesten', true, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000051', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000052', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000053', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000054', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000055', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000011'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000012', 3, 'Die Drittbesten', true, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000056', 'Bush', 1, false, 10, false, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000057', 'Clinton', 2, false, 11, false, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000058', 'Biden', 3, false, 15, false, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000059', 'Lincoln', 4, false, 16, true, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000060', 'Reagan', 5, true, 25, true, + '00000000-0000-0000-0001-000000000012'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_4__createReferendumVorlagenVE.sql b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_4__createReferendumVorlagenVE.sql new file mode 100644 index 000000000..702b2f038 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/h2/V3_5_4__createReferendumVorlagenVE.sql @@ -0,0 +1,45 @@ +-- Referendum (VE) am Wahltermin der auch die EU-Wahl hat +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005', + '00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005', + '00000001-0000-0000-0000-000000000002'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000013', 1, 'Vorschlag für Refendum', true, + '00000000-0000-0000-0000-000000000005'); + + +INSERT INTO referendumvorlagen (id, wahlbezirkID, wahlID, stimmzettelgebietID) +VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0000-0000-000000000005', + '00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005'); + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000001', '00000000-0000-0000-0001-000000000013', 1, 'kurzname1', 'frage1', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000001', 'name1', 1, + '00000000-0000-0002-0002-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000002', 'name2', 2, + '00000000-0000-0002-0002-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000003', 'name3', 3, + '00000000-0000-0002-0002-000000000001'); + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000002', '00000000-0000-0000-0001-000000000013', 2, 'kurzname2', 'frage2', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000004', 'name1', 1, + '00000000-0000-0002-0002-000000000002'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000005', 'name2', 2, + '00000000-0000-0002-0002-000000000002'); + + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000003', '00000000-0000-0000-0001-000000000013', 3, 'kurzname3', 'frage3', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000006', 'name1', 1, + '00000000-0000-0002-0002-000000000003'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_0_1__wahltageTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_0_1__wahltageTestdaten.sql new file mode 100644 index 000000000..0c6830b52 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_0_1__wahltageTestdaten.sql @@ -0,0 +1,6 @@ +INSERT INTO wahltag (id, tag, beschreibung, nummer) +values ('00000000-0000-0000-0000-000000000001', to_timestamp('2024-06-09', 'YYYY-MM-DD'), + 'zehnte Direktwahl zum Europäischen Parlament', '0'); + +INSERT INTO wahltag (id, tag, beschreibung, nummer) +values ('00000000-0000-0000-0000-000000000002', to_timestamp('2020-03-15', 'YYYY-MM-DD'), 'Kommunalwahl 20', '0'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_1_1__wahlTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_1_1__wahlTestdaten.sql new file mode 100644 index 000000000..3bfece0d7 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_1_1__wahlTestdaten.sql @@ -0,0 +1,12 @@ +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000001', 'EU-Wahl 24', 'EUW', '00000000-0000-0000-0000-000000000001'); + +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000002', 'Stadtratswahl', 'SRW', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000003', 'Oberbürgermeisterwahl', 'OBW', '00000000-0000-0000-0000-000000000002'); +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000004', 'Bezirksausschusswahl', 'BAW', '00000000-0000-0000-0000-000000000002'); + +INSERT INTO wahl (id, name, wahlart, wahltagID) +values ('00000000-0000-0000-0000-000000000005', 'Volksentscheid', 'VE', '00000000-0000-0000-0000-000000000001'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_2_1__stimmzettelgebietTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_2_1__stimmzettelgebietTestdaten.sql new file mode 100644 index 000000000..0978db3d3 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_2_1__stimmzettelgebietTestdaten.sql @@ -0,0 +1,16 @@ +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000001', '101', 'Stimmzettelgebiet 101', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000002', '102', 'Stimmzettelgebiet 102', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000003', '103', 'Stimmzettelgebiet 103', 'SK', + '00000000-0000-0000-0000-000000000001'); +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000004', '104', 'Stimmzettelgebiet 104', 'SK', + '00000000-0000-0000-0000-000000000001'); + +INSERT INTO stimmzettelgebiet (id, nummer, name, stimmzettelgebietsart, wahlID) +values ('00000000-0000-0000-0000-000000000005', '101', 'VE-SZG-1', 'SK', + '00000000-0000-0000-0000-000000000005'); diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_3_1__wahlbezirkTestdaten.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_3_1__wahlbezirkTestdaten.sql new file mode 100644 index 000000000..bef72b808 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_3_1__wahlbezirkTestdaten.sql @@ -0,0 +1,19 @@ +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000001', 'UWB', 'Wahlbezirk 1', '00000000-0000-0000-0000-000000000001', 30, 5, + 1); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000002', 'UWB', 'Wahlbezirk 2', '00000000-0000-0000-0000-000000000002', 32, 12, + 2); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000003', 'BWB', 'Wahlbezirk 3', '00000000-0000-0000-0000-000000000003', 17, 1, + 0); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000004', 'UWB', 'Wahlbezirk 4', '00000000-0000-0000-0000-000000000004', 42, 5, + 3); + +INSERT INTO wahlbezirk (id, wahlbezirkArt, nummer, stimmzettelgebietID, a1, a2, a3) +values ('00000000-0000-0000-0000-000000000005', 'UWB', 'Wahlbezirk 4', '00000000-0000-0000-0000-000000000005', 42, 5, + 3); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql new file mode 100644 index 000000000..27130a68a --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_1__cleanOldWahlvorschlaegeAndReferendumvorlagen.sql @@ -0,0 +1,8 @@ +DELETE kandidat; +DELETE wahlvorschlag; +DELETE wahlvorschlaege; +DELETE wahlvorschlaegeliste; + +DELETE referendumoption; +DELETE referendumvorlage; +DELETE referendumvorlagen; \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_2__createWahlvorschlaegeListen.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_2__createWahlvorschlaegeListen.sql new file mode 100644 index 000000000..66b6241f0 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_2__createWahlvorschlaegeListen.sql @@ -0,0 +1,9 @@ +-- für EU-Wahl +INSERT INTO wahlvorschlaegeliste (id, wahltag, wahlID) +VALUES ('00000001-0000-0000-0000-000000000001', TO_TIMESTAMP('2024-06-09', 'YYYY-MM-DD'), + '00000000-0000-0000-0000-000000000001'); + +-- für VE +INSERT INTO wahlvorschlaegeliste (id, wahltag, wahlID) +VALUES ('00000001-0000-0000-0000-000000000002', TO_TIMESTAMP('2024-06-09', 'YYYY-MM-DD'), + '00000000-0000-0000-0000-000000000005'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql new file mode 100644 index 000000000..93ceed79e --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_3__createWahlvorschlaegeAndKandidatenEUWahl.sql @@ -0,0 +1,321 @@ +-- ######################### +-- ## für EU-Wahl +-- ######################### +-- ## Wahlbezirk1 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000001', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000001', 1, 'Die Besten', 1, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000001', 'Clapton', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000002', 'Jagger', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000003', 'Prince', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000004', 'Mac', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000005', 'Cool', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000002', 2, 'Die Zweitbesten', 1, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000006', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000007', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000008', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000009', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000010', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000002'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000003', 3, 'Die Drittbesten', 1, + '00000000-0000-0000-0000-000000000001'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000011', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000012', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000013', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000014', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000015', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000003'); + +-- ######################### +-- ## Wahlbezirk2 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000002', '00000000-0000-0000-0000-000000000002', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000004', 1, 'Die Besten', 1, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000016', 'Clapton', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000017', 'Jagger', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000018', 'Prince', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000019', 'Mac', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000020', 'Cool', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000004'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000005', 2, 'Die Zweitbesten', 1, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000021', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000022', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000023', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000024', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000005'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000025', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000005'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000006', 3, 'Die Drittbesten', 1, + '00000000-0000-0000-0000-000000000002'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000026', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000027', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000028', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000029', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000006'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000030', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000006'); + +-- ######################### +-- ## Wahlbezirk3 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000003', '00000000-0000-0000-0000-000000000003', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000003', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000007', 1, 'Die Besten', 1, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000031', 'Clapton', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000032', 'Jagger', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000033', 'Prince', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000034', 'Mac', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000007'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000035', 'Cool', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000007'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000008', 2, 'Die Zweitbesten', 1, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000036', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000037', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000038', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000039', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000008'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000040', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000008'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000009', 3, 'Die Drittbesten', 1, + '00000000-0000-0000-0000-000000000003'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000041', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000042', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000043', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000044', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000009'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000045', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000009'); + +-- ######################### +-- ## Wahlbezirk4 - +-- ######################### +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000004', '00000000-0000-0000-0000-000000000004', + '00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000004', + '00000001-0000-0000-0000-000000000001'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000010', 1, 'Die Besten', 1, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000046', 'Clapton', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000047', 'Jagger', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000048', 'Prince', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000049', 'Mac', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000010'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000050', 'Cool', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000010'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000011', 2, 'Die Zweitbesten', 1, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000051', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000052', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000053', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000054', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000011'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000055', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000011'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000012', 3, 'Die Drittbesten', 1, + '00000000-0000-0000-0000-000000000004'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000056', 'Bush', 1, 0, 10, 0, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000057', 'Clinton', 2, 0, 11, 0, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000058', 'Biden', 3, 0, 15, 0, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000059', 'Lincoln', 4, 0, 16, 1, + '00000000-0000-0000-0001-000000000012'); +INSERT INTO kandidat (id, name, listenposition, direktkandidat, tabellenSpalteInNiederschrift, einzelbewerber, + wahlvorschlagID) +VALUES ('00000000-0000-0000-0001-000000000060', 'Reagan', 5, 1, 25, 1, + '00000000-0000-0000-0001-000000000012'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_4__createReferendumVorlagenVE.sql b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_4__createReferendumVorlagenVE.sql new file mode 100644 index 000000000..7efc66c6b --- /dev/null +++ b/wls-eai-service/src/main/resources/db/dummydata/oracle/V3_5_4__createReferendumVorlagenVE.sql @@ -0,0 +1,45 @@ +-- Referendum (VE) am Wahltermin der auch die EU-Wahl hat +INSERT INTO wahlvorschlaege (id, wahlbezirkID, wahlID, stimmzettelgebietID, wahlvorschlaegelisteID) +VALUES ('00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005', + '00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005', + '00000001-0000-0000-0000-000000000002'); + +INSERT INTO wahlvorschlag (id, ordnungszahl, kurzname, erhaeltStimmen, wahlvorschlaegeID) +VALUES ('00000000-0000-0000-0001-000000000013', 1, 'Vorschlag für Refendum', 1, + '00000000-0000-0000-0000-000000000005'); + + +INSERT INTO referendumvorlagen (id, wahlbezirkID, wahlID, stimmzettelgebietID) +VALUES ('00000000-0000-0000-0001-000000000001', '00000000-0000-0000-0000-000000000005', + '00000000-0000-0000-0000-000000000005', '00000000-0000-0000-0000-000000000005'); + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000001', '00000000-0000-0000-0001-000000000013', 1, 'kurzname1', 'frage1', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000001', 'name1', 1, + '00000000-0000-0002-0002-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000002', 'name2', 2, + '00000000-0000-0002-0002-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000003', 'name3', 3, + '00000000-0000-0002-0002-000000000001'); + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000002', '00000000-0000-0000-0001-000000000013', 2, 'kurzname2', 'frage2', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000004', 'name1', 1, + '00000000-0000-0002-0002-000000000002'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000005', 'name2', 2, + '00000000-0000-0002-0002-000000000002'); + + +INSERT INTO referendumvorlage (id, wahlvorschlagID, ordnungszahl, kurzname, frage, referendumvorlagenID) +VALUES ('00000000-0000-0002-0002-000000000003', '00000000-0000-0000-0001-000000000013', 3, 'kurzname3', 'frage3', + '00000000-0000-0000-0001-000000000001'); +INSERT INTO referendumoption (id, name, position, referendumvorlageid) +VALUES ('00000000-0002-0002-0002-000000000006', 'name1', 1, + '00000000-0000-0002-0002-000000000003'); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_0__createWahltag.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_0__createWahltag.sql new file mode 100644 index 000000000..508ce6682 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_0__createWahltag.sql @@ -0,0 +1,9 @@ +CREATE TABLE wahltag +( + id VARCHAR2(36) NOT NULL, + tag TIMESTAMP NOT NULL, + beschreibung VARCHAR2(1024) NOT NULL, + nummer VARCHAR2(10) NOT NULL, + + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_1__createWahl.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_1__createWahl.sql new file mode 100644 index 000000000..679fa802e --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_1__createWahl.sql @@ -0,0 +1,13 @@ +CREATE TABLE wahl +( + id VARCHAR2(36) NOT NULL, + name VARCHAR2(100) NOT NULL, + wahlart VARCHAR2(5) NOT NULL, + + wahltagID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (wahltagID) REFERENCES wahltag (id), + + PRIMARY KEY (id) + +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_2__createStimmzettelgebiet.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_2__createStimmzettelgebiet.sql new file mode 100644 index 000000000..1306de4e6 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_2__createStimmzettelgebiet.sql @@ -0,0 +1,13 @@ +CREATE TABLE stimmzettelgebiet +( + id VARCHAR2(36) NOT NULL, + nummer VARCHAR2(36), + name VARCHAR2(100), + stimmzettelgebietsart VARCHAR2(3) NOT NULL, + + wahlID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (wahlID) REFERENCES wahl (id), + + primary key (id) +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_3__createWahlbezirk.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_3__createWahlbezirk.sql new file mode 100644 index 000000000..fa0b87964 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_3__createWahlbezirk.sql @@ -0,0 +1,15 @@ +CREATE TABLE wahlbezirk +( + id VARCHAR2(36) NOT NULL, + wahlbezirkArt VARCHAR2(3) NOT NULL, + nummer VARCHAR2(36) NOT NULL, + a1 BIGINT NOT NULL, + a2 BIGINT NOT NULL, + a3 BIGINT NOT NULL, + + stimmzettelgebietID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id), + + PRIMARY KEY (id) +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_4__addWahlbezirkFKToWahlvorstand.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_4__addWahlbezirkFKToWahlvorstand.sql new file mode 100644 index 000000000..faae94787 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_4__addWahlbezirkFKToWahlvorstand.sql @@ -0,0 +1,2 @@ +ALTER TABLE wahlvorstand + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/h2/V3_6__addFKContraintsToWahlvorschlag.sql b/wls-eai-service/src/main/resources/db/migrations/h2/V3_6__addFKContraintsToWahlvorschlag.sql new file mode 100644 index 000000000..1127db8ac --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/h2/V3_6__addFKContraintsToWahlvorschlag.sql @@ -0,0 +1,18 @@ +ALTER TABLE wahlvorschlaegeliste + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); + +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id); +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id); + +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id); +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id); +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_0__createWahltag.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_0__createWahltag.sql new file mode 100644 index 000000000..508ce6682 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_0__createWahltag.sql @@ -0,0 +1,9 @@ +CREATE TABLE wahltag +( + id VARCHAR2(36) NOT NULL, + tag TIMESTAMP NOT NULL, + beschreibung VARCHAR2(1024) NOT NULL, + nummer VARCHAR2(10) NOT NULL, + + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_1__createWahl.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_1__createWahl.sql new file mode 100644 index 000000000..679fa802e --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_1__createWahl.sql @@ -0,0 +1,13 @@ +CREATE TABLE wahl +( + id VARCHAR2(36) NOT NULL, + name VARCHAR2(100) NOT NULL, + wahlart VARCHAR2(5) NOT NULL, + + wahltagID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (wahltagID) REFERENCES wahltag (id), + + PRIMARY KEY (id) + +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_2__createStimmzettelgebiet.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_2__createStimmzettelgebiet.sql new file mode 100644 index 000000000..1306de4e6 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_2__createStimmzettelgebiet.sql @@ -0,0 +1,13 @@ +CREATE TABLE stimmzettelgebiet +( + id VARCHAR2(36) NOT NULL, + nummer VARCHAR2(36), + name VARCHAR2(100), + stimmzettelgebietsart VARCHAR2(3) NOT NULL, + + wahlID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (wahlID) REFERENCES wahl (id), + + primary key (id) +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_3__createWahlbezirk.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_3__createWahlbezirk.sql new file mode 100644 index 000000000..a8267f9c1 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_3__createWahlbezirk.sql @@ -0,0 +1,15 @@ +CREATE TABLE wahlbezirk +( + id VARCHAR2(36) NOT NULL, + wahlbezirkArt VARCHAR2(3) NOT NULL, + nummer VARCHAR2(36) NOT NULL, + a1 NUMBER NOT NULL, + a2 NUMBER NOT NULL, + a3 NUMBER NOT NULL, + + stimmzettelgebietID VARCHAR2(36) NOT NULL, + + FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id), + + PRIMARY KEY (id) +) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_4__addWahlbezirkFKToWahlvorstand.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_4__addWahlbezirkFKToWahlvorstand.sql new file mode 100644 index 000000000..faae94787 --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_4__addWahlbezirkFKToWahlvorstand.sql @@ -0,0 +1,2 @@ +ALTER TABLE wahlvorstand + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id) \ No newline at end of file diff --git a/wls-eai-service/src/main/resources/db/migrations/oracle/V3_6__addFKContraintsToWahlvorschlag.sql b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_6__addFKContraintsToWahlvorschlag.sql new file mode 100644 index 000000000..ceb88a6bd --- /dev/null +++ b/wls-eai-service/src/main/resources/db/migrations/oracle/V3_6__addFKContraintsToWahlvorschlag.sql @@ -0,0 +1,16 @@ +ALTER TABLE wahlvorschlaegeliste + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); + +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id); +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); +ALTER TABLE wahlvorschlaege + ADD FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id); + +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (wahlbezirkID) REFERENCES wahlbezirk (id); +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (wahlID) REFERENCES wahl (id); +ALTER TABLE referendumvorlagen + ADD FOREIGN KEY (stimmzettelgebietID) REFERENCES stimmzettelgebiet (id); \ No newline at end of file diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java index b3539a11f..4f93b0647 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/Authorities.java @@ -12,6 +12,12 @@ public class Authorities { public static final String SERVICE_LOAD_WAHLVORSCHLAEGELISTE = "aoueai_BUSINESSACTION_LoadWahlvorschlaegeListe"; public static final String SERVICE_LOAD_REFERENDUMVORLAGEN = "aoueai_BUSINESSACTION_LoadReferendumvorlagen"; + public static final String SERVICE_LOAD_WAHLBERECHTIGTE = "aoueai_BUSINESSACTION_LoadWahlberechtigte"; + public static final String SERVICE_LOAD_WAHLTAGE = "aoueai_BUSINESSACTION_LoadWahltage"; + public static final String SERVICE_LOAD_WAHLBEZIRKE = "aoueai_BUSINESSACTION_LoadWahlbezirke"; + public static final String SERVICE_LOAD_WAHLEN = "aoueai_BUSINESSACTION_LoadWahlen"; + public static final String SERVICE_LOAD_BASISDATEN = "aoueai_BUSINESSACTION_LoadBasisdaten"; + public static final String[] ALL_AUTHORITIES_GETWAHLVORSTANDFORWAHLBEZIRK = { SERVICE_LOAD_WAHLVORSTAND }; diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplicationDummyDataIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplicationDummyDataIntegrationTest.java index dee088642..054270962 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplicationDummyDataIntegrationTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/MicroServiceApplicationDummyDataIntegrationTest.java @@ -7,8 +7,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -@SpringBootTest(classes = MicroServiceApplication.class) -@ActiveProfiles({ TestConstants.SPRING_TEST_PROFILE, TestConstants.SPRING_NO_SECURITY_PROFILE, "db-h2", "db-dummydata" }) +@SpringBootTest(classes = MicroServiceApplication.class, properties = "spring.datasource.url=jdbc:h2:mem:wls-eai-service-dummydata") +@ActiveProfiles({ "db-h2", "db-dummydata" }) class MicroServiceApplicationDummyDataIntegrationTest { @Autowired diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepositoryTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepositoryTest.java new file mode 100644 index 000000000..457cfc409 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/StimmzettelgebietRepositoryTest.java @@ -0,0 +1,67 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import java.time.LocalDate; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = MicroServiceApplication.class) +class StimmzettelgebietRepositoryTest { + + @Autowired + WahltageRepository wahltageRepository; + + @Autowired + WahlRepository wahlRepository; + + @Autowired + StimmzettelgebietRepository stimmzettelgebietRepository; + + @AfterEach + void tearDown() { + stimmzettelgebietRepository.deleteAll(); + wahlRepository.deleteAll(); + wahltageRepository.deleteAll(); + } + + @Nested + class FindByWahlWahltagTagAndWahlNummer { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val wahltag1 = wahltageRepository.save(new Wahltag(wahltag, "", nummer)); + val wahltag2 = wahltageRepository.save(new Wahltag(wahltag.minusDays(1), "", nummer)); + val wahltag3 = wahltageRepository.save(new Wahltag(wahltag.plusDays(1), "", nummer)); + val wahltag4 = wahltageRepository.save(new Wahltag(wahltag, "", nummer + "x")); + + val wahl1 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag1)); + val wahl2 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag2)); + val wahl3 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag3)); + val wahl4 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag4)); + + val sgz1ToFind = stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "", Stimmzettelgebietsart.SK, wahl1)); + val sgz2ToFind = stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz2", "", Stimmzettelgebietsart.SK, wahl1)); + stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "", Stimmzettelgebietsart.SK, wahl2)); + stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "", Stimmzettelgebietsart.SK, wahl3)); + stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "", Stimmzettelgebietsart.SK, wahl4)); + + val result = stimmzettelgebietRepository.findByWahlWahltagTagAndWahlWahltagNummer(wahltag, nummer); + + val expectedResult = new Stimmzettelgebiet[] { + sgz1ToFind, + sgz2ToFind + }; + + Assertions.assertThat(result).containsOnly(expectedResult); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepositoryTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepositoryTest.java new file mode 100644 index 000000000..269518f73 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlRepositoryTest.java @@ -0,0 +1,58 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import java.time.LocalDate; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = MicroServiceApplication.class) +class WahlRepositoryTest { + + @Autowired + WahltageRepository wahltageRepository; + + @Autowired + WahlRepository wahlRepository; + + @AfterEach + void tearDown() { + wahlRepository.deleteAll(); + wahltageRepository.deleteAll(); + } + + @Nested + class FindByWahltagTagAndWahltagNummer { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "1"; + + val wahltag1 = wahltageRepository.save(new Wahltag(wahltag, "", nummer)); + val wahltag2 = wahltageRepository.save(new Wahltag(wahltag.minusDays(1), "", nummer)); + val wahltag3 = wahltageRepository.save(new Wahltag(wahltag.plusDays(1), "", nummer)); + val wahltag4 = wahltageRepository.save(new Wahltag(wahltag, "", nummer + "x")); + + val wahl1ToFind = wahlRepository.save(new Wahl("wahl1", Wahlart.BTW, wahltag1)); + val wahl2ToFind = wahlRepository.save(new Wahl("wahl2", Wahlart.BTW, wahltag1)); + wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag2)); + wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag3)); + wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag4)); + + val result = wahlRepository.findByWahltagTagAndWahltagNummer(wahltag, nummer); + + val expectedResult = new Wahl[] { + wahl1ToFind, + wahl2ToFind + }; + + Assertions.assertThat(result).containsOnly(expectedResult); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepositoryTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepositoryTest.java new file mode 100644 index 000000000..ea66e6a02 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahlbezirkRepositoryTest.java @@ -0,0 +1,95 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import java.time.LocalDate; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest(classes = MicroServiceApplication.class) +@ActiveProfiles({ "db-h2" }) +class WahlbezirkRepositoryTest { + + @Autowired + WahltageRepository wahltageRepository; + + @Autowired + WahlRepository wahlRepository; + + @Autowired + StimmzettelgebietRepository stimmzettelgebietRepository; + + @Autowired + WahlbezirkRepository unitUnderTest; + + @AfterEach + void tearDown() { + unitUnderTest.deleteAll(); + stimmzettelgebietRepository.deleteAll(); + wahlRepository.deleteAll(); + wahltageRepository.deleteAll(); + } + + @Nested + class FindWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val wahltag1 = wahltageRepository.save(new Wahltag(wahltag, "", nummer)); + val wahltag2 = wahltageRepository.save(new Wahltag(wahltag.minusDays(1), "", nummer)); + val wahltag3 = wahltageRepository.save(new Wahltag(wahltag.plusDays(1), "", nummer)); + val wahltag4 = wahltageRepository.save(new Wahltag(wahltag, "", nummer + "x")); + + val wahl1 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag1)); + val wahl2 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag2)); + val wahl3 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag3)); + val wahl4 = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag4)); + + val szg1 = stimmzettelgebietRepository.save(new Stimmzettelgebiet("", "", Stimmzettelgebietsart.SK, wahl1)); + val szg2 = stimmzettelgebietRepository.save(new Stimmzettelgebiet("", "", Stimmzettelgebietsart.SK, wahl2)); + val szg3 = stimmzettelgebietRepository.save(new Stimmzettelgebiet("", "", Stimmzettelgebietsart.SK, wahl3)); + val szg4 = stimmzettelgebietRepository.save(new Stimmzettelgebiet("", "", Stimmzettelgebietsart.SK, wahl4)); + + val wahlbezirk1ToFind = unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz1", szg1, 0, 0, 0)); + val wahlbezirk2ToFind = unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz2", szg1, 0, 0, 0)); + unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz3", szg2, 0, 0, 0)); + unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz4", szg3, 0, 0, 0)); + unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz5", szg4, 0, 0, 0)); + + val result = unitUnderTest.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(wahltag, nummer); + + val expectedResult = new Wahlbezirk[] { + wahlbezirk1ToFind, + wahlbezirk2ToFind + }; + Assertions.assertThat(result).containsOnly(expectedResult); + } + } + + @Nested + class FindWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID { + + @Test + void dataFound() { + val wahltag = wahltageRepository.save(new Wahltag(LocalDate.now(), "", "nummer")); + val wahl = wahlRepository.save(new Wahl("", Wahlart.BTW, wahltag)); + val szg = stimmzettelgebietRepository.save(new Stimmzettelgebiet("", "", Stimmzettelgebietsart.SK, wahl)); + + val wahlbezirkToFind = unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "nummer1", szg, 1, 2, 3)); + unitUnderTest.save(new Wahlbezirk(WahlbezirkArt.UWB, "nummer2", szg, 1, 2, 3)); + + val result = unitUnderTest.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID(wahlbezirkToFind.getId()); + + Assertions.assertThat(result).containsOnly(wahlbezirkToFind); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepositoryTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepositoryTest.java new file mode 100644 index 000000000..616e870e5 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/domain/wahldaten/WahltageRepositoryTest.java @@ -0,0 +1,46 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import java.time.LocalDate; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = MicroServiceApplication.class) +class WahltageRepositoryTest { + + @Autowired + WahltageRepository wahltageRepository; + + @AfterEach + void tearDown() { + wahltageRepository.deleteAll(); + } + + @Nested + class FindByTagAfterOrTagEquals { + + @Test + void dataFound() { + val equalsDateString = "2024-07-03"; + val afterDateString = "2024-08-02"; + + val wahltag1ToFind = wahltageRepository.save(new Wahltag(LocalDate.parse("2024-07-03"), "beschreibung", "1")); + val wahltag2ToFind = wahltageRepository.save(new Wahltag(LocalDate.parse("2024-08-03"), "beschreibung", "1")); + wahltageRepository.save(new Wahltag(LocalDate.parse("2024-08-02"), "beschreibung", "3")); + wahltageRepository.save(new Wahltag(LocalDate.parse("2024-07-02"), "beschreibung", "4")); + wahltageRepository.save(new Wahltag(LocalDate.parse("2024-07-04"), "beschreibung", "5")); + + val result = wahltageRepository.findByTagAfterOrTagEquals(LocalDate.parse(afterDateString), LocalDate.parse(equalsDateString)); + + val expectedResult = new Wahltag[] { wahltag1ToFind, wahltag2ToFind }; + + Assertions.assertThat(result).containsOnly(expectedResult); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerIntegrationTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerIntegrationTest.java new file mode 100644 index 000000000..06e24d831 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerIntegrationTest.java @@ -0,0 +1,400 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; +import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebiet; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.StimmzettelgebietRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebietsart; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahl; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlart; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlbezirk; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlbezirkArt; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlbezirkRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahltag; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahltageRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten.WahldatenMapper; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionCategory; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO; +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.util.Set; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest(classes = MicroServiceApplication.class) +@AutoConfigureMockMvc +@ActiveProfiles({ TestConstants.SPRING_TEST_PROFILE }) +public class WahldatenControllerIntegrationTest { + + private static final String EMPTY_ARRAY_JSON = "[]"; + + @Value("${service.info.oid}") + String serviceID; + + @Autowired + MockMvc mockMvc; + + @Autowired + WahltageRepository wahltageRepository; + + @Autowired + WahlRepository wahlRepository; + + @Autowired + StimmzettelgebietRepository stimmzettelgebietRepository; + + @Autowired + WahlbezirkRepository wahlbezirkRepository; + + @Autowired + WahldatenMapper wahldatenMapper; + + @Autowired + ObjectMapper objectMapper; + + @AfterEach + public void tearDown() { + wahlbezirkRepository.deleteAll(); + stimmzettelgebietRepository.deleteAll(); + wahlRepository.deleteAll(); + wahltageRepository.deleteAll(); + } + + @Nested + class LoadWahlberechtigte { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBERECHTIGTE) + void dataFound() throws Exception { + val wahltag = wahltageRepository.save(new Wahltag(LocalDate.now(), "beschreibung wahltag", "nummer")); + val wahl = wahlRepository.save(new Wahl("wahl", Wahlart.BTW, wahltag)); + val stimmzettelgebiet = stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "sgz1", Stimmzettelgebietsart.SK, wahl)); + val wahlbezirkToFind = wahlbezirkRepository.save(new Wahlbezirk(WahlbezirkArt.UWB, "nummer", stimmzettelgebiet, 10, 11, 12)); + + wahlbezirkRepository.save(new Wahlbezirk(WahlbezirkArt.UWB, "nummer", stimmzettelgebiet, 10, 11, 12)); + + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirke/" + wahlbezirkToFind.getId() + "/wahlberechtigte"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WahlberechtigteDTO[].class); + + val expectedResponseBody = new WahlberechtigteDTO[] { wahldatenMapper.toWahlberechtigteDTO(wahlbezirkToFind) }; + + Assertions.assertThat(responseBodyAsDTO).isEqualTo(expectedResponseBody); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBERECHTIGTE) + void noDataFound() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirke/" + UUID.randomUUID() + "/wahlberechtigte"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + + Assertions.assertThat(response.getResponse().getContentAsString()).isEqualTo(EMPTY_ARRAY_JSON); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBERECHTIGTE) + void wlsExceptionOnValidationFailed() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirke/ /wahlberechtigte"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG.code(), serviceID, + ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + } + + @Nested + class LoadWahltageSinceIncluding { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLTAGE) + void dataFound() throws Exception { + val wahltageSinceAsString = "2024-07-03"; + + val wahltag1ToFind = wahltageRepository.save(new Wahltag(LocalDate.of(2024, 12, 24), "wahltag1", "1")); + val wahltag2ToFind = wahltageRepository.save(new Wahltag(LocalDate.of(2024, 10, 3), "wahltag2", "2")); + val wahltag3ToFind = wahltageRepository.save(new Wahltag(LocalDate.parse(wahltageSinceAsString), "wahltag3", "3")); + wahltageRepository.save(new Wahltag(LocalDate.of(2024, 1, 1), "wahltagNotFound1", "0")); + wahltageRepository.save(new Wahltag(LocalDate.of(2024, 7, 2), "wahltagNotFound2", "0")); + + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahltage?includingSince=" + wahltageSinceAsString); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WahltagDTO[].class); + + val expectedResponseBody = new WahltagDTO[] { + wahldatenMapper.toDTO(wahltag1ToFind), + wahldatenMapper.toDTO(wahltag2ToFind), + wahldatenMapper.toDTO(wahltag3ToFind) + }; + Assertions.assertThat(responseBodyAsDTO).containsOnly(expectedResponseBody); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLTAGE) + void noDataFound() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahltage?includingSince=1900-01-01"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + + Assertions.assertThat(response.getResponse().getContentAsString()).isEqualTo(EMPTY_ARRAY_JSON); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLTAGE) + void wlsExceptionOnDateQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahltage?includingSince= "); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLTAGE_TAG_FEHLT.code(), serviceID, + ExceptionConstants.LOADWAHLTAGE_TAG_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + } + + @Nested + class LoadWahlbezirke { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBEZIRKE) + void dataFound() throws Exception { + val wahltagDate = "2024-07-03"; + val nummerToFind = "1"; + + val wahltag1 = wahltageRepository.save(new Wahltag(LocalDate.parse(wahltagDate), "wahltag1", "1")); + wahltageRepository.save(new Wahltag(LocalDate.parse(wahltagDate), "wahltag2", "2")); + + val wahl = wahlRepository.save(new Wahl("wahl", Wahlart.BTW, wahltag1)); + val stimmzettelgebiet = stimmzettelgebietRepository.save(new Stimmzettelgebiet("nummer", "name", Stimmzettelgebietsart.SK, wahl)); + + val wahlbezirk1 = wahlbezirkRepository.save(new Wahlbezirk(WahlbezirkArt.UWB, "wbz1", stimmzettelgebiet, 0, 0, 0)); + val wahlbezirk2 = wahlbezirkRepository.save(new Wahlbezirk(WahlbezirkArt.BWB, "wbz2", stimmzettelgebiet, 0, 0, 0)); + + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirk?forDate=" + wahltagDate + "&withNummer=" + nummerToFind); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WahlbezirkDTO[].class); + + val expectedResponseBody = new WahlbezirkDTO[] { + wahldatenMapper.toDTO(wahlbezirk1), + wahldatenMapper.toDTO(wahlbezirk2) + }; + Assertions.assertThat(responseBodyAsDTO).containsOnly(expectedResponseBody); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBEZIRKE) + void noDataFound() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirk?forDate=2024-07-03&withNummer=1"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + + Assertions.assertThat(response.getResponse().getContentAsString()).isEqualTo(EMPTY_ARRAY_JSON); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBEZIRKE) + void wlsExceptionOnNummerQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirk?forDate=2024-07-03"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLBEZIRKE_NUMMER_FEHLT.code(), serviceID, + ExceptionConstants.LOADWAHLBEZIRKE_NUMMER_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLBEZIRKE) + void wlsExceptionOnDateQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlbezirk?nummer=2"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLBEZIRKE_WAHLTAG_FEHLT.code(), serviceID, + ExceptionConstants.LOADWAHLBEZIRKE_WAHLTAG_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + } + + @Nested + class LoadWahlen { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLEN) + void dataFound() throws Exception { + val wahltagDate = "2024-07-03"; + val nummerToFind = "1"; + + val wahltag1 = wahltageRepository.save(new Wahltag(LocalDate.parse(wahltagDate), "wahltag1", "1")); + val wahltag2 = wahltageRepository.save(new Wahltag(LocalDate.parse(wahltagDate), "wahltag2", "2")); + + val wahl1ToFind = wahlRepository.save(new Wahl("wahl1", Wahlart.BTW, wahltag1)); + val wahl2ToFind = wahlRepository.save(new Wahl("wahl2", Wahlart.BTW, wahltag1)); + wahlRepository.save(new Wahl("wahl", Wahlart.BTW, wahltag2)); + + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlen?forDate=" + wahltagDate + "&withNummer=" + nummerToFind); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), WahlDTO[].class); + + val expectedResponseBody = new WahlDTO[] { + wahldatenMapper.toDTO(wahl1ToFind), + wahldatenMapper.toDTO(wahl2ToFind) + }; + Assertions.assertThat(responseBodyAsDTO).containsOnly(expectedResponseBody); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLEN) + void noDataFound() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlen?forDate=2024-07-03&withNummer=1"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + + Assertions.assertThat(response.getResponse().getContentAsString()).isEqualTo(EMPTY_ARRAY_JSON); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLEN) + void wlsExceptionOnNummerQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlen?forDate=2024-07-03"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLEN_NUMMER_FEHLT.code(), serviceID, + ExceptionConstants.LOADWAHLEN_NUMMER_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_WAHLEN) + void wlsExceptionOnDateQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/wahlen?withNummer=1"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADWAHLEN_WAHLTAG_FEHLT.code(), serviceID, + ExceptionConstants.LOADWAHLEN_WAHLTAG_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + } + + @Nested + class LoadBasisdaten { + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_BASISDATEN) + void dataFound() throws Exception { + val wahltagDateToFind = "2024-07-03"; + val nummerToFind = "1"; + + val wahltag = wahltageRepository.save(new Wahltag(LocalDate.parse(wahltagDateToFind), "beschreibung wahltag", nummerToFind)); + val wahl = wahlRepository.save(new Wahl("wahl", Wahlart.BTW, wahltag)); + val stimmzettelgebiet = stimmzettelgebietRepository.save(new Stimmzettelgebiet("sgz1", "sgz1", Stimmzettelgebietsart.SK, wahl)); + val wahlbezirkToFind = wahlbezirkRepository.save(new Wahlbezirk(WahlbezirkArt.UWB, "nummer", stimmzettelgebiet, 10, 11, 12)); + + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/basisdaten?forDate=" + wahltagDateToFind + "&withNummer=" + nummerToFind); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseBodyAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), BasisdatenDTO.class); + + val expectedResponseBody = new BasisdatenDTO(Set.of(wahldatenMapper.toBasisstrukturdatenDTO(wahlbezirkToFind)), + Set.of(wahldatenMapper.toDTO(wahl)), + Set.of(wahldatenMapper.toDTO(wahlbezirkToFind)), + Set.of(wahldatenMapper.toDTO(stimmzettelgebiet))); + Assertions.assertThat(responseBodyAsDTO).usingRecursiveComparison().ignoringCollectionOrder().isEqualTo(expectedResponseBody); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_BASISDATEN) + void noDataFound() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/basisdaten?forDate=2024-07-03&withNummer=1"); + + val response = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); + val responseAsDTO = objectMapper.readValue(response.getResponse().getContentAsString(), BasisdatenDTO.class); + + val expectedResponseDTO = new BasisdatenDTO(null, null, null, null); + + Assertions.assertThat(responseAsDTO).isEqualTo(expectedResponseDTO); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_BASISDATEN) + void wlsExceptionOnNummerQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/basisdaten?forDate=2024-07-03"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADBASISDATEN_NUMMER_FEHLT.code(), serviceID, + ExceptionConstants.LOADBASISDATEN_NUMMER_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + @Test + @WithMockUser(authorities = Authorities.SERVICE_LOAD_BASISDATEN) + void wlsExceptionOnDateQueryParameterIsMissing() throws Exception { + val request = get(WahldatenController.WAHLDATEN_REQUEST_MAPPING + "/basisdaten?withNummer=1"); + + val response = mockMvc.perform(request).andExpect(status().isBadRequest()).andReturn(); + val responseBodyAsWlsException = objectMapper.readValue(response.getResponse().getContentAsString(StandardCharsets.UTF_8), WlsExceptionDTO.class); + + val expectedWlsExceptionDTO = new WlsExceptionDTO(WlsExceptionCategory.F, + ExceptionConstants.LOADBASISDATEN_TAG_FEHLT.code(), serviceID, + ExceptionConstants.LOADBASISDATEN_TAG_FEHLT.message()); + + Assertions.assertThat(responseBodyAsWlsException).isEqualTo(expectedWlsExceptionDTO); + } + + } +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerTest.java new file mode 100644 index 000000000..9fd755ff5 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/rest/wahldaten/WahldatenControllerTest.java @@ -0,0 +1,106 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten; + +import static org.mockito.ArgumentMatchers.eq; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten.WahldatenService; +import java.time.LocalDate; +import java.util.List; +import java.util.Set; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahldatenControllerTest { + + @Mock + WahldatenService wahldatenService; + + @InjectMocks + WahldatenController unitUnderTest; + + @Nested + class LoadWahlberechtigte { + + @Test + void serviceIsCalled() { + val wahlbezirkID = "wahlbezirkID"; + + val mockedServiceResponse = List.of(WahlberechtigteDTO.builder().build()); + Mockito.when(wahldatenService.getWahlberechtigte(wahlbezirkID)).thenReturn(mockedServiceResponse); + + Assertions.assertThat(unitUnderTest.loadWahlberechtigte(wahlbezirkID)).isSameAs(mockedServiceResponse); + } + + } + + @Nested + class LoadWahltageSinceIncluding { + @Test + void serviceIsCalled() { + val includingSince = LocalDate.now(); + + val mockedServiceResponse = Set.of(WahltagDTO.builder().build()); + Mockito.when(wahldatenService.getWahltage(eq(includingSince))).thenReturn(mockedServiceResponse); + + Assertions.assertThat(unitUnderTest.loadWahltageSinceIncluding(includingSince)).isSameAs(mockedServiceResponse); + } + } + + @Nested + class LoadWahlbezirke { + + @Test + void serviceIsCalled() { + val forDate = LocalDate.now(); + val nummer = "nummer"; + + val mockedServiceResponse = Set.of(WahlbezirkDTO.builder().build()); + Mockito.when(wahldatenService.getWahlbezirke(eq(forDate), eq(nummer))).thenReturn(mockedServiceResponse); + + Assertions.assertThat(unitUnderTest.loadWahlbezirke(forDate, nummer)).isSameAs(mockedServiceResponse); + } + + } + + @Nested + class LoadWahlen { + + @Test + void serviceIsCalled() { + val forDate = LocalDate.now(); + val nummer = "nummer"; + + val mockedServiceResponse = Set.of(WahlDTO.builder().build()); + Mockito.when(wahldatenService.getWahlen(eq(forDate), eq(nummer))).thenReturn(mockedServiceResponse); + + Assertions.assertThat(unitUnderTest.loadWahlen(forDate, nummer)).isSameAs(mockedServiceResponse); + } + } + + @Nested + class LoadBasisdaten { + + @Test + void serviceIsCalled() { + val forDate = LocalDate.now(); + val nummer = "nummer"; + + val mockedServicResponse = new BasisdatenDTO(null, null, null, null); + Mockito.when(wahldatenService.getBasisdaten(eq(forDate), eq(nummer))).thenReturn(mockedServicResponse); + + Assertions.assertThat(unitUnderTest.loadBasisdaten(forDate, nummer)).isSameAs(mockedServicResponse); + } + } +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverterTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverterTest.java new file mode 100644 index 000000000..e0768f9c8 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/IDConverterTest.java @@ -0,0 +1,47 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service; + +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class IDConverterTest { + + @Mock + ExceptionFactory exceptionFactory; + + @InjectMocks + IDConverter unitUnderTest; + + @Nested + class ConvertIDToUUIDOrThrow { + + @Test + void stringIsConverted() { + val idToConvert = "7db3ebc6-d2f9-4b7d-a703-6d1677f3f305"; + + val result = unitUnderTest.convertIDToUUIDOrThrow(idToConvert); + + Assertions.assertThat(result.toString()).isEqualTo(idToConvert); + } + + @Test + void wlsExceptionWhenNotConvertable() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.convertIDToUUIDOrThrow("")).isSameAs(mockedWlsException); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapperTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapperTest.java new file mode 100644 index 000000000..e9a2575b5 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenMapperTest.java @@ -0,0 +1,153 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebiet; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebietsart; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahl; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlart; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlbezirk; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlbezirkArt; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahltag; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.dto.WahlartDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisstrukturdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.StimmzettelgebietDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.StimmzettelgebietsartDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkArtDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import java.time.LocalDate; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; + +class WahldatenMapperTest { + + private final WahldatenMapper unitUnderTest = Mappers.getMapper(WahldatenMapper.class); + + @Nested + class ToDTO { + + @Test + void ofWahltag() { + val tag = LocalDate.now(); + val beschreibung = "beschreibung"; + val nummer = "nummer"; + val id = UUID.randomUUID(); + + val entityToMap = new Wahltag(tag, beschreibung, nummer); + entityToMap.setId(id); + + val result = unitUnderTest.toDTO(entityToMap); + + val expectedResult = new WahltagDTO(id.toString(), tag, beschreibung, nummer); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + + @Test + void ofWahl() { + val wahlID = UUID.randomUUID(); + val wahltag = LocalDate.now(); + val name = "name"; + val nummer = "nummer"; + + val entityToMap = new Wahl(name, Wahlart.BTW, new Wahltag(wahltag, null, nummer)); + entityToMap.setId(wahlID); + + val result = unitUnderTest.toDTO(entityToMap); + + val expectedResult = new WahlDTO(wahlID.toString(), name, WahlartDTO.BTW, wahltag, nummer); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + + @Test + void ofWahlbezirk() { + val wahlbezirkID = UUID.randomUUID(); + val wahlID = UUID.randomUUID(); + val wahltag = LocalDate.now(); + val wahlbezirkNummer = "wahlbezirkNummer"; + val wahltagnummer = "wahltagnummer"; + + val wahlForWahlbezirk = new Wahl(null, null, new Wahltag(wahltag, null, wahltagnummer)); + wahlForWahlbezirk.setId(wahlID); + val entityToMap = new Wahlbezirk(WahlbezirkArt.UWB, wahlbezirkNummer, new Stimmzettelgebiet(null, null, null, wahlForWahlbezirk), 0, 0, 0); + entityToMap.setId(wahlbezirkID); + + val result = unitUnderTest.toDTO(entityToMap); + + val expectedResult = new WahlbezirkDTO(wahlbezirkID.toString(), WahlbezirkArtDTO.UWB, wahlbezirkNummer, wahltag, wahltagnummer, wahlID.toString()); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + + @Test + void ofStimmzettelgebiet() { + val szgID = UUID.randomUUID(); + val szgNummer = "szgNummer"; + val szgName = "szgName"; + val wahltag = LocalDate.now(); + + val entityToMap = new Stimmzettelgebiet(szgNummer, szgName, Stimmzettelgebietsart.SK, new Wahl(null, null, new Wahltag(wahltag, null, null))); + entityToMap.setId(szgID); + + val result = unitUnderTest.toDTO(entityToMap); + + val expectedResult = new StimmzettelgebietDTO(szgID.toString(), szgNummer, szgName, wahltag, StimmzettelgebietsartDTO.SK); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + } + + @Nested + class ToWahlberechtigteDTO { + + @Test + void isMapped() { + val wahlID = UUID.randomUUID(); + val wahlbezirkID = UUID.randomUUID(); + val a1 = 10; + val a2 = 20; + val a3 = 30; + + val wahlOfWahlbezirk = new Wahl(); + wahlOfWahlbezirk.setId(wahlID); + val entityToMap = new Wahlbezirk(null, null, new Stimmzettelgebiet(null, null, null, wahlOfWahlbezirk), a1, a2, a3); + entityToMap.setId(wahlbezirkID); + + val result = unitUnderTest.toWahlberechtigteDTO(entityToMap); + + val expectedResult = new WahlberechtigteDTO(wahlID.toString(), wahlbezirkID.toString(), a1, a2, a3); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + } + + @Nested + class ToBasisstrukturdatenDTO { + + @Test + void isMapped() { + val wahlID = UUID.randomUUID(); + val sgzID = UUID.randomUUID(); + val wbzID = UUID.randomUUID(); + val wahltag = LocalDate.now(); + + val wahl = new Wahl(); + wahl.setId(wahlID); + wahl.setWahltag(new Wahltag(wahltag, null, null)); + val stimmzettelgebiet = new Stimmzettelgebiet(); + stimmzettelgebiet.setId(sgzID); + stimmzettelgebiet.setWahl(wahl); + val entityToMap = new Wahlbezirk(); + entityToMap.setStimmzettelgebiet(stimmzettelgebiet); + entityToMap.setId(wbzID); + + val result = unitUnderTest.toBasisstrukturdatenDTO(entityToMap); + + val expectedResult = new BasisstrukturdatenDTO(wahlID.toString(), sgzID.toString(), wbzID.toString(), wahltag); + Assertions.assertThat(result).isEqualTo(expectedResult); + } + + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceSecurityTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceSecurityTest.java new file mode 100644 index 000000000..1726c5574 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceSecurityTest.java @@ -0,0 +1,121 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.Authorities; +import de.muenchen.oss.wahllokalsystem.eaiservice.MicroServiceApplication; +import de.muenchen.oss.wahllokalsystem.eaiservice.TestConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.testing.SecurityUtils; +import java.time.LocalDate; +import java.util.UUID; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest(classes = MicroServiceApplication.class) +@ActiveProfiles({ TestConstants.SPRING_TEST_PROFILE }) +public class WahldatenServiceSecurityTest { + + @Autowired + WahldatenService wahldatenService; + + @Nested + class GetWahltage { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.SERVICE_LOAD_WAHLTAGE); + + Assertions.assertThatNoException().isThrownBy(() -> wahldatenService.getWahltage(LocalDate.now())); + } + + @Test + void authorityIsMissing() { + SecurityUtils.runWith(); + + Assertions.assertThatException().isThrownBy(() -> wahldatenService.getWahltage(LocalDate.now())).isInstanceOf(AccessDeniedException.class); + } + + } + + @Nested + class GetWahlen { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.SERVICE_LOAD_WAHLEN); + + Assertions.assertThatNoException().isThrownBy(() -> wahldatenService.getWahlen(LocalDate.now(), "nummer")); + } + + @Test + void authorityIsMissing() { + SecurityUtils.runWith(); + + Assertions.assertThatException().isThrownBy(() -> wahldatenService.getWahlen(LocalDate.now(), "nummer")).isInstanceOf(AccessDeniedException.class); + } + + } + + @Nested + class GetWahlbezirke { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.SERVICE_LOAD_WAHLBEZIRKE); + + Assertions.assertThatNoException().isThrownBy(() -> wahldatenService.getWahlbezirke(LocalDate.now(), "nummer")); + } + + @Test + void authorityIsMissing() { + SecurityUtils.runWith(); + + Assertions.assertThatException().isThrownBy(() -> wahldatenService.getWahlbezirke(LocalDate.now(), "nummer")) + .isInstanceOf(AccessDeniedException.class); + } + + } + + @Nested + class GetWahlberechtigte { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.SERVICE_LOAD_WAHLBERECHTIGTE); + + Assertions.assertThatNoException().isThrownBy(() -> wahldatenService.getWahlberechtigte(UUID.randomUUID().toString())); + } + + @Test + void authorityIsMissing() { + SecurityUtils.runWith(); + + Assertions.assertThatException().isThrownBy(() -> wahldatenService.getWahlberechtigte(UUID.randomUUID().toString())) + .isInstanceOf(AccessDeniedException.class); + } + + } + + @Nested + class GetBasisdaten { + + @Test + void accessGranted() { + SecurityUtils.runWith(Authorities.SERVICE_LOAD_BASISDATEN); + + Assertions.assertThatNoException().isThrownBy(() -> wahldatenService.getBasisdaten(LocalDate.now(), "nummer")); + } + + @Test + void authorityIsMissing() { + SecurityUtils.runWith(); + + Assertions.assertThatException().isThrownBy(() -> wahldatenService.getBasisdaten(LocalDate.now(), "nummer")) + .isInstanceOf(AccessDeniedException.class); + } + + } +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceTest.java new file mode 100644 index 000000000..ed3bcfdf0 --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenServiceTest.java @@ -0,0 +1,307 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import static org.mockito.ArgumentMatchers.eq; + +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Stimmzettelgebiet; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.StimmzettelgebietRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahl; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahlbezirk; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahlbezirkRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.Wahltag; +import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahldaten.WahltageRepository; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.BasisstrukturdatenDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.StimmzettelgebietDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlberechtigteDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahlbezirkDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahldaten.dto.WahltagDTO; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.IDConverter; +import java.time.LocalDate; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahldatenServiceTest { + + @Mock + WahldatenMapper wahldatenMapper; + + @Mock + WahldatenValidator wahldatenValidator; + + @Mock + IDConverter idConverter; + + @Mock + WahltageRepository wahltageRepository; + + @Mock + WahlRepository wahlRepository; + + @Mock + WahlbezirkRepository wahlbezirkRepository; + + @Mock + StimmzettelgebietRepository stimmzettelgebietRepository; + + @InjectMocks + WahldatenService unitUnderTest; + + @Nested + class GetWahltage { + + @Test + void dataFound() { + val dateSince = LocalDate.now(); + + val mockedRepoEntity = new Wahltag(); + val mockedMappedEntity = WahltagDTO.builder().build(); + + Mockito.when(wahltageRepository.findByTagAfterOrTagEquals(eq(dateSince), eq(dateSince))).thenReturn(List.of(mockedRepoEntity)); + Mockito.when(wahldatenMapper.toDTO(mockedRepoEntity)).thenReturn(mockedMappedEntity); + + val result = unitUnderTest.getWahltage(dateSince); + + Assertions.assertThat(result).isEqualTo(Set.of(mockedMappedEntity)); + } + + @Test + void noDataFound() { + val dateSince = LocalDate.now(); + + Mockito.when(wahltageRepository.findByTagAfterOrTagEquals(eq(dateSince), eq(dateSince))).thenReturn(Collections.emptyList()); + + val result = unitUnderTest.getWahltage(dateSince); + + Assertions.assertThat(result).isEmpty(); + } + + @Test + void validationFailed() { + val dateSince = LocalDate.now(); + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahldatenValidator).validGetWahltageParameterOrThrow(dateSince); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahltage(dateSince)).isSameAs(mockedValidationException); + } + } + + @Nested + class GetWahlen { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedRepoEntity = new Wahl(); + val mockedMappedEntity = WahlDTO.builder().build(); + + Mockito.when(wahlRepository.findByWahltagTagAndWahltagNummer(eq(wahltag), eq(nummer))).thenReturn(List.of(mockedRepoEntity)); + Mockito.when(wahldatenMapper.toDTO(mockedRepoEntity)).thenReturn(mockedMappedEntity); + + val result = unitUnderTest.getWahlen(wahltag, nummer); + + Assertions.assertThat(result).isEqualTo(Set.of(mockedMappedEntity)); + } + + @Test + void noDataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + Mockito.when(wahlRepository.findByWahltagTagAndWahltagNummer(eq(wahltag), eq(nummer))).thenReturn(Collections.emptyList()); + + val result = unitUnderTest.getWahlen(wahltag, nummer); + + Assertions.assertThat(result).isEmpty(); + } + + @Test + void validationFailed() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahldatenValidator).validGetWahlenParameterOrThrow(wahltag, nummer); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlen(wahltag, nummer)).isSameAs(mockedValidationException); + } + + } + + @Nested + class GetWahlbezirke { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedRepoEntity = new Wahlbezirk(); + val mockedMappedEntity = WahlbezirkDTO.builder().build(); + + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(eq(wahltag), eq(nummer))) + .thenReturn(List.of(mockedRepoEntity)); + Mockito.when(wahldatenMapper.toDTO(mockedRepoEntity)).thenReturn(mockedMappedEntity); + + val result = unitUnderTest.getWahlbezirke(wahltag, nummer); + + Assertions.assertThat(result).isEqualTo(Set.of(mockedMappedEntity)); + } + + @Test + void noDataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(eq(wahltag), eq(nummer))) + .thenReturn(Collections.emptyList()); + + val result = unitUnderTest.getWahlbezirke(wahltag, nummer); + + Assertions.assertThat(result).isEmpty(); + } + + @Test + void validationFailed() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahldatenValidator).validGetWahlbezirkeParameterOrThrow(wahltag, nummer); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlbezirke(wahltag, nummer)).isSameAs(mockedValidationException); + } + + } + + @Nested + class GetWahlberechtigte { + + @Test + void dataFound() { + val wahlbezirkID = "wahlbezirkID"; + + val mockedWahlbezirkAsUUID = UUID.randomUUID(); + val mockedRepoEntity = new Wahlbezirk(); + val mockedMappedEntityAsWahlberechtigte = WahlberechtigteDTO.builder().build(); + + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID)).thenReturn(mockedWahlbezirkAsUUID); + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID(mockedWahlbezirkAsUUID)) + .thenReturn(List.of(mockedRepoEntity)); + Mockito.when(wahldatenMapper.toWahlberechtigteDTO(mockedRepoEntity)).thenReturn(mockedMappedEntityAsWahlberechtigte); + + val result = unitUnderTest.getWahlberechtigte(wahlbezirkID); + + Assertions.assertThat(result).isEqualTo(List.of(mockedMappedEntityAsWahlberechtigte)); + } + + @Test + void noDataFound() { + val wahlbezirkID = "wahlbezirkID"; + + val mockedWahlbezirkAsUUID = UUID.randomUUID(); + + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID)).thenReturn(mockedWahlbezirkAsUUID); + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByID(mockedWahlbezirkAsUUID)) + .thenReturn(Collections.emptyList()); + + val result = unitUnderTest.getWahlberechtigte(wahlbezirkID); + + Assertions.assertThat(result).isEmpty(); + } + + @Test + void validationFailed() { + val wahlbezirkID = "wahlbezirkID"; + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahldatenValidator).validGetWahlberechtigteParameterOrThrow(wahlbezirkID); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlberechtigte(wahlbezirkID)).isSameAs(mockedValidationException); + } + + } + + @Nested + class GetBasisdaten { + + @Test + void dataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedRepoWahlbezirk = new Wahlbezirk(); + val mockedRepoWahlbezirkMappedToDTO = WahlbezirkDTO.builder().build(); + val mockedRepoWahlbezirkAsStrukturdatemDTO = BasisstrukturdatenDTO.builder().build(); + val mockedRepoWahl = new Wahl(); + val mockedRepoWahlMappedToDTO = WahlDTO.builder().build(); + val mockedRepoStimmzettelgebiet = new Stimmzettelgebiet(); + val mockedRepoStimmzettelgebietMappedToDTO = StimmzettelgebietDTO.builder().build(); + + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(eq(wahltag), eq(nummer))) + .thenReturn(List.of(mockedRepoWahlbezirk)); + Mockito.when(wahlRepository.findByWahltagTagAndWahltagNummer(eq(wahltag), eq(nummer))).thenReturn(List.of(mockedRepoWahl)); + Mockito.when(stimmzettelgebietRepository.findByWahlWahltagTagAndWahlWahltagNummer(eq(wahltag), eq(nummer))) + .thenReturn(List.of(mockedRepoStimmzettelgebiet)); + Mockito.when(wahldatenMapper.toDTO(mockedRepoWahl)).thenReturn(mockedRepoWahlMappedToDTO); + Mockito.when(wahldatenMapper.toDTO(mockedRepoWahlbezirk)).thenReturn(mockedRepoWahlbezirkMappedToDTO); + Mockito.when(wahldatenMapper.toDTO(mockedRepoStimmzettelgebiet)).thenReturn(mockedRepoStimmzettelgebietMappedToDTO); + Mockito.when(wahldatenMapper.toBasisstrukturdatenDTO(mockedRepoWahlbezirk)).thenReturn(mockedRepoWahlbezirkAsStrukturdatemDTO); + + val result = unitUnderTest.getBasisdaten(wahltag, nummer); + + Assertions.assertThat(result) + .isEqualTo(new BasisdatenDTO(Set.of(mockedRepoWahlbezirkAsStrukturdatemDTO), Set.of(mockedRepoWahlMappedToDTO), + Set.of(mockedRepoWahlbezirkMappedToDTO), Set.of(mockedRepoStimmzettelgebietMappedToDTO))); + } + + @Test + void noDataFound() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + Mockito.when(wahlbezirkRepository.findWahlbezirkeWithStimmzettelgebietAndWahlAndWahltagByWahltagAndNummer(eq(wahltag), eq(nummer))) + .thenReturn(Collections.emptyList()); + Mockito.when(wahlRepository.findByWahltagTagAndWahltagNummer(eq(wahltag), eq(nummer))).thenReturn(Collections.emptyList()); + Mockito.when(stimmzettelgebietRepository.findByWahlWahltagTagAndWahlWahltagNummer(eq(wahltag), eq(nummer))).thenReturn(Collections.emptyList()); + + val result = unitUnderTest.getBasisdaten(wahltag, nummer); + + Assertions.assertThat(result) + .isEqualTo(new BasisdatenDTO(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet())); + } + + @Test + void validationFailed() { + val wahltag = LocalDate.now(); + val nummer = "nummer"; + + val mockedValidationException = new RuntimeException("validation failed"); + + Mockito.doThrow(mockedValidationException).when(wahldatenValidator).validGetBasisdatenParameterOrThrow(wahltag, nummer); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getBasisdaten(wahltag, nummer)).isSameAs(mockedValidationException); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidatorTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidatorTest.java new file mode 100644 index 000000000..c5129cfeb --- /dev/null +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahldaten/WahldatenValidatorTest.java @@ -0,0 +1,168 @@ +package de.muenchen.oss.wahllokalsystem.eaiservice.service.wahldaten; + +import de.muenchen.oss.wahllokalsystem.eaiservice.exception.ExceptionConstants; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; +import java.time.LocalDate; +import lombok.val; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class WahldatenValidatorTest { + + @Mock + ExceptionFactory exceptionFactory; + + @InjectMocks + WahldatenValidator unitUnderTest; + + @Nested + class ValidGetWahltageParameterOrThrow { + + @Test + void noExceptionWhenWahltagIsValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validGetWahltageParameterOrThrow(LocalDate.now())); + } + + @Test + void exceptionWhenWahltagIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLTAGE_TAG_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatThrownBy(() -> unitUnderTest.validGetWahltageParameterOrThrow(null)).isSameAs(mockedWlsException); + } + + } + + @Nested + class ValidGetWahlenParameterOrThrow { + + @Test + void noExceptionWhenGetWahlenParameterAreValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validGetWahlenParameterOrThrow(LocalDate.now(), "")); + } + + @Test + void exceptionWhenWahltagIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLEN_WAHLTAG_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlenParameterOrThrow(null, "")).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenNummerIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLEN_NUMMER_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlenParameterOrThrow(LocalDate.now(), null)).isSameAs(mockedWlsException); + } + } + + @Nested + class ValidGetWahlbezirkeParameterOrThrow { + + @Test + void noExceptionWhenGetWahlbezirkeParameterAreValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validGetWahlbezirkeParameterOrThrow(LocalDate.now(), "")); + } + + @Test + void exceptionWhenWahltagIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBEZIRKE_WAHLTAG_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlbezirkeParameterOrThrow(null, "")).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenNummerIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBEZIRKE_NUMMER_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlbezirkeParameterOrThrow(LocalDate.now(), null)) + .isSameAs(mockedWlsException); + } + + } + + @Nested + class ValidGetWahlberechtigteParameterOrThrow { + + @Test + void noExceptionWhenGetWahlberechtigteParameterAreValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validGetWahlberechtigteParameterOrThrow("wahlbezirkID")); + } + + @Test + void exceptionWhenWahlbezirkIDIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlberechtigteParameterOrThrow(null)).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenWahlbezirkIDIsEmptyString() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlberechtigteParameterOrThrow("")).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenWahlbezirkIDIsBlank() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADWAHLBERECHTIGTE_SUCHKRITERIEN_UNVOLLSTAENDIG)) + .thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetWahlberechtigteParameterOrThrow(" ")).isSameAs(mockedWlsException); + } + } + + @Nested + class ValidGetBasisdatenParameterOrThrow { + + @Test + void noExceptinWhenParametersAreValid() { + Assertions.assertThatNoException().isThrownBy(() -> unitUnderTest.validGetBasisdatenParameterOrThrow(LocalDate.now(), "nummer")); + } + + @Test + void exceptionWhenWahltagIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADBASISDATEN_TAG_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetBasisdatenParameterOrThrow(null, "nummer")).isSameAs(mockedWlsException); + } + + @Test + void exceptionWhenNummerIsNull() { + val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + + Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.LOADBASISDATEN_NUMMER_FEHLT)).thenReturn(mockedWlsException); + + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.validGetBasisdatenParameterOrThrow(LocalDate.now(), null)) + .isSameAs(mockedWlsException); + } + } + +} diff --git a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java index 6587d788c..98f7953db 100644 --- a/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java +++ b/wls-eai-service/src/test/java/de/muenchen/oss/wahllokalsystem/eaiservice/service/wahlvorstand/WahlvorstandServiceTest.java @@ -5,11 +5,10 @@ import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.Wahlvorstandsmitglied; import de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand.WahlvorstandsmitgliedsFunktion; import de.muenchen.oss.wahllokalsystem.eaiservice.exception.NotFoundException; -import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionConstants; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO; import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsmitgliedAktualisierungDTO; -import de.muenchen.oss.wahllokalsystem.wls.common.exception.FachlicheWlsException; +import de.muenchen.oss.wahllokalsystem.eaiservice.service.IDConverter; import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionFactory; import java.time.LocalDateTime; import java.util.Collections; @@ -42,6 +41,9 @@ class WahlvorstandServiceTest { @Mock WahlvorstandValidator wahlvorstandValidator; + @Mock + IDConverter idConverter; + @InjectMocks WahlvorstandService unitUnderTest; @@ -57,6 +59,7 @@ void foundData() { Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.of(mockedEntity)); Mockito.when(wahlvorstandMapper.toDTO(mockedEntity)).thenReturn(mockedMappedEntity); + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID.toString())).thenReturn(wahlbezirkID); val result = unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString()); @@ -68,6 +71,7 @@ void foundNoData() { val wahlbezirkID = UUID.randomUUID(); Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID.toString())).thenReturn(wahlbezirkID); Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID.toString())) .usingRecursiveComparison().isEqualTo(new NotFoundException(wahlbezirkID, Wahlvorstand.class)); @@ -77,11 +81,11 @@ void foundNoData() { void exceptionForMalformedWahlbezirkID() { val wahlbezirkID = "noAUUID"; - val mockedException = FachlicheWlsException.withCode("").buildWithMessage(""); + val idConverterException = new RuntimeException("id convert failed"); - Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedException); + Mockito.doThrow(idConverterException).when(idConverter).convertIDToUUIDOrThrow(wahlbezirkID); - Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID)).isSameAs(mockedException); + Assertions.assertThatException().isThrownBy(() -> unitUnderTest.getWahlvorstandForWahlbezirk(wahlbezirkID)).isSameAs(idConverterException); } @Test @@ -117,6 +121,7 @@ void existingDataIsUpdated() { val mockedEntity = new Wahlvorstand(wahlbezirkID, Set.of(mockedEntityMitglied1, mockedEntityMitglied3)); Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.of(mockedEntity)); + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID.toString())).thenReturn(wahlbezirkID); unitUnderTest.setAnwesenheit(aktualisierung); @@ -141,6 +146,7 @@ void exceptionWhenWahlvorstandDoesNotExists() { val aktualisierung = new WahlvorstandsaktualisierungDTO(wahlbezirkID.toString(), mitgliederAktualisierung, LocalDateTime.now()); Mockito.when(wahlvorstandRepository.findFirstByWahlbezirkID(wahlbezirkID)).thenReturn(Optional.empty()); + Mockito.when(idConverter.convertIDToUUIDOrThrow(wahlbezirkID.toString())).thenReturn(wahlbezirkID); Assertions.assertThatException().isThrownBy(() -> unitUnderTest.setAnwesenheit(aktualisierung)).usingRecursiveComparison() .isEqualTo(new NotFoundException(wahlbezirkID, Wahlvorstand.class)); @@ -161,13 +167,15 @@ void validationFailed() { @Test void exceptionBecauseOfWahlbezirkIDOfParameterIsInvalid() { - val mockedWlsException = FachlicheWlsException.withCode("").buildWithMessage(""); + val wahlbezirkID = "malformedID"; + + val idConverterException = new RuntimeException("id convert failed"); - Mockito.when(exceptionFactory.createFachlicheWlsException(ExceptionConstants.ID_NICHT_KONVERTIERBAR)).thenReturn(mockedWlsException); + Mockito.doThrow(idConverterException).when(idConverter).convertIDToUUIDOrThrow(wahlbezirkID); Assertions.assertThatException().isThrownBy( - () -> unitUnderTest.setAnwesenheit(new WahlvorstandsaktualisierungDTO("malformedID", Collections.emptySet(), LocalDateTime.now()))) - .isSameAs(mockedWlsException); + () -> unitUnderTest.setAnwesenheit(new WahlvorstandsaktualisierungDTO(wahlbezirkID, Collections.emptySet(), LocalDateTime.now()))) + .isSameAs(idConverterException); } } diff --git a/wls-eai-service/src/test/resources/httpRequests/wahldaten.http b/wls-eai-service/src/test/resources/httpRequests/wahldaten.http new file mode 100644 index 000000000..6d3d8695c --- /dev/null +++ b/wls-eai-service/src/test/resources/httpRequests/wahldaten.http @@ -0,0 +1,78 @@ +### get token for user wls_all +POST {{ SSO_URL }}/auth/realms/wls_realm/protocol/openid-connect/token +Content-Type: application/x-www-form-urlencoded + +password = test & +grant_type = password & +client_secret = top-secret & +client_id = wls & +username = wls_all + +> {% + client.global.set("auth_token", response.body.access_token); + client.global.set("token_type", response.body.token_type); +%} + +### get userinfo with auth_token +GET {{ SSO_URL }}/auth/realms/wls_realm/protocol/openid-connect/userinfo +Authorization: {{ token_type }} {{ auth_token }} + +### get Wahltag EU-Wahl +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahltage?includingSince=2024-01-01 +Authorization: {{ token_type }} {{ auth_token }} + +### get Wahltag since 2000 +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahltage?includingSince=2000-01-01 +Authorization: {{ token_type }} {{ auth_token }} + +### get Wahltag no hits +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahltage?includingSince=3024-01-01 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlen on EU-Wahl-Tag +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlen?forDate=2024-06-09&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlen on Kommunalwahl-Tag +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlen?forDate=2020-03-15&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlen on day without elections +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlen?forDate=2034-06-09&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlbezirke EU-Wahl +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirk?forDate=2024-06-09&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlbezirke Kommunalwahl (empty response) +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirk?forDate=2020-03-15&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlberechtigte wahlbezirk-1 +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirke/00000000-0000-0000-0000-000000000001/wahlberechtigte +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlberechtigte wahlbezirk-2 +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirke/00000000-0000-0000-0000-000000000002/wahlberechtigte +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlberechtigte wahlbezirk-3 +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirke/00000000-0000-0000-0000-000000000003/wahlberechtigte +Authorization: {{ token_type }} {{ auth_token }} + +### get wahlberechtigte wahlbezirk-4 +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/wahlbezirke/00000000-0000-0000-0000-000000000004/wahlberechtigte +Authorization: {{ token_type }} {{ auth_token }} + +### get Basistrukturdaten on EU-Wahl-Tag +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/basisdaten?forDate=2024-06-09&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get Basistrukturdaten on Kommunalwahl-Tag +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/basisdaten?forDate=2020-03-15&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} + +### get Basistrukturdaten on day without elections +GET {{ WLS_EAI_SERVICE_URL }}/wahldaten/basisdaten?forDate=2034-06-09&withNummer=0 +Authorization: {{ token_type }} {{ auth_token }} \ No newline at end of file diff --git a/wls-eai-service/src/test/resources/httpRequests/wahlvorschlag.http b/wls-eai-service/src/test/resources/httpRequests/wahlvorschlag.http index 9d792628a..86591c83b 100644 --- a/wls-eai-service/src/test/resources/httpRequests/wahlvorschlag.http +++ b/wls-eai-service/src/test/resources/httpRequests/wahlvorschlag.http @@ -16,34 +16,50 @@ username = wls_all GET {{ SSO_URL }}/auth/realms/wls_realm/protocol/openid-connect/userinfo Authorization: {{ token_type }} {{ auth_token }} -### GET Wahlvorschlaege -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID/wahlbezirkID +### GET Wahlvorschlaege - EU-Wahl - WBZ-1 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/00000000-0000-0000-0000-000000000001 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorschlaege - EU-Wahl - WBZ-2 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/00000000-0000-0000-0000-000000000002 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorschlaege - EU-Wahl - WBZ-3 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/00000000-0000-0000-0000-000000000003 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorschlaege - EU-Wahl - WBZ-4 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/00000000-0000-0000-0000-000000000004 Authorization: {{ token_type }} {{ auth_token }} ### GET Wahlvorschlaege with non existing 'wahlID' and 'wahlbezirkID' not found GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID_X/wahlbezirkID_X Authorization: {{ token_type }} {{ auth_token }} -### GET Wahlvorschlaegeliste -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID/liste?forDate=2024-10-10 +### GET Wahlvorschlaegeliste - EU-Wahl +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/liste?forDate=2024-06-09 +Authorization: {{ token_type }} {{ auth_token }} + +### GET Wahlvorschlaegeliste - VE +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000005/liste?forDate=2024-06-09 Authorization: {{ token_type }} {{ auth_token }} ### GET Wahlvorschlaegeliste for non existing 'wahlID' not found -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID_X/liste?forDate=2024-10-10 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID_X/liste?forDate=2024-06-09 Authorization: {{ token_type }} {{ auth_token }} ### GET Wahlvorschlaegeliste for non existing 'forDate'not found -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/wahlID/liste?forDate=2024-10-11 +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/wahl/00000000-0000-0000-0000-000000000001/liste?forDate=2024-10-11 Authorization: {{ token_type }} {{ auth_token }} ### GET Referendumvorlagen -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/wahlID/wahlbezirkID +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/00000000-0000-0000-0000-000000000005/00000000-0000-0000-0000-000000000005 Authorization: {{ token_type }} {{ auth_token }} ### GET Referendumvorlagen for non existing 'wahlID' not found -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/wahlID_X/wahlbezirkID +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/wahlID_X/00000000-0000-0000-0000-000000000005 Authorization: {{ token_type }} {{ auth_token }} ### GET Referendumvorlagen for non existing 'wahlbezirkID' not found -GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/wahlID/wahlbezirkID_X +GET {{ WLS_EAI_SERVICE_URL }}/vorschlaege/referendum/00000000-0000-0000-0000-000000000005/wahlbezirkID_X Authorization: {{ token_type }} {{ auth_token }} \ No newline at end of file