Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

152 implementierung wahlvorstandsdaten #315

Merged
merged 43 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
67ce338
draft impl for get and post
MrSebastian Jun 14, 2024
5dac61e
add example requests for wahlvorstaende
MrSebastian Jun 14, 2024
66843d5
update keycloak config for eai wahlvorstaende
MrSebastian Jun 14, 2024
bdcf03a
update example requests with invalid requests
MrSebastian Jun 17, 2024
54632f4
add global exception handler
MrSebastian Jun 17, 2024
4aee078
use ExceptionDataWrapper
MrSebastian Jun 17, 2024
6ae6388
remove auto validation
MrSebastian Jun 17, 2024
529a324
add validator and udpate authority to latest used
MrSebastian Jun 17, 2024
3e3ab51
preauthorized removed from controller
MrSebastian Jun 17, 2024
f8409f4
update SecurityConfigurationTest with wahlvorstand
MrSebastian Jun 17, 2024
c756413
create wahlvorstand controller unit test
MrSebastian Jun 17, 2024
c8e30e2
define authorities for wahlvorstaende service
MrSebastian Jun 17, 2024
1578309
wahlvorstand controller integration test for load
MrSebastian Jun 17, 2024
e666d6c
move mapper to service package
MrSebastian Jun 18, 2024
ae1b89a
create mapper test
MrSebastian Jun 18, 2024
35f0013
use optional in service
MrSebastian Jun 18, 2024
1c9ed71
use lambda expression instead of statement
MrSebastian Jun 18, 2024
8282585
created tests for wahlvorstandservice
MrSebastian Jun 18, 2024
2299985
remove unintended noSec and randomPort of test
MrSebastian Jun 18, 2024
d30355f
all constants with all authorities required to access service
MrSebastian Jun 18, 2024
d666cf2
create WahlvorstandServiceSecurityTest
MrSebastian Jun 18, 2024
a948e67
add lombok builder to dtos
MrSebastian Jun 18, 2024
350600c
add validator tests
MrSebastian Jun 18, 2024
d3b0934
implement 404 on loadWahlvorstand
MrSebastian Jun 18, 2024
6dab999
404 when wahlvorstand to update doesnt exists
MrSebastian Jun 18, 2024
0fdc552
add tests for setanwesenheit
MrSebastian Jun 18, 2024
2aacae9
spotless:apply
MrSebastian Jun 18, 2024
236fd6f
change resource for anwesenheit
MrSebastian Jun 18, 2024
3990e45
use put for update instead of post
MrSebastian Jun 18, 2024
bec3f6e
create test for global exception handler
MrSebastian Jun 18, 2024
14c98e7
fix missing joincolumn
MrSebastian Jun 19, 2024
49e0219
remove http status annotation because its default
MrSebastian Jun 19, 2024
5c35465
add operation description
MrSebastian Jun 19, 2024
545a106
Merge branch 'refs/heads/dev' into 152-implementierung-wahlvorstandsd…
MrSebastian Jun 19, 2024
b8f819f
fix testname
MrSebastian Jun 19, 2024
275031e
remove empty line
MrSebastian Jun 19, 2024
1bed2c8
ignore AbbreviationAsWordInName on method
MrSebastian Jun 19, 2024
6428189
Merge branch 'refs/heads/dev' into 152-implementierung-wahlvorstandsd…
MrSebastian Jun 19, 2024
af55421
add missing oracle sql files
MrSebastian Jun 21, 2024
c47f997
fix wrong method and path in example requests
MrSebastian Jun 21, 2024
612fc82
streamline naming in validator
MrSebastian Jun 21, 2024
a0a62d6
improve naming of class
MrSebastian Jun 21, 2024
e535dd6
remove unnecessary full qualified classname
MrSebastian Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions stack/keycloak/migration/add-authorities-eai-wahlvorstand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
id: add authorities eai wahlvorstand
author: MrSebastian
realm: ${SSO_REALM}
changes:
- addRole:
name: aoueai_BUSINESSACTION_LoadWahlvorstand
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allEaiAuthorities
role: aoueai_BUSINESSACTION_LoadWahlvorstand
clientId: ${SSO_CLIENT_ID}

- addRole:
name: aoueai_BUSINESSACTION_SaveAnwesenheit
clientRole: true
clientId: ${SSO_CLIENT_ID}
- assignRoleToGroup:
group: allEaiAuthorities
role: aoueai_BUSINESSACTION_SaveAnwesenheit
clientId: ${SSO_CLIENT_ID}
15 changes: 15 additions & 0 deletions stack/keycloak/migration/create-group-all-eai-authorities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: create group allEaiAuthorities and link wls_all*
author: MrSebastian
realm: ${SSO_REALM}
changes:
- addGroup:
name: allEaiAuthorities
- assignGroup:
user: wls_all
group: allEaiAuthorities
- assignGroup:
user: wls_all_uwb
group: allEaiAuthorities
- assignGroup:
user: wls_all_bwb
group: allEaiAuthorities
2 changes: 2 additions & 0 deletions stack/keycloak/migration/keycloak-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ includes:
- path: add-authorities-wahlvorbereitung-fortsetzungsuhrzeit.yml
- path: add-authorities-wahlvorbereitung-eroeffnungsuhrzeit.yml
- path: add-authorities-wahlvorbereitung-urnenwahlschliessungsuhrzeit.yml
- path: create-group-all-eai-authorities.yml
- path: add-authorities-eai-wahlvorstand.yml
5 changes: 5 additions & 0 deletions wls-eai-service/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
</module>

<module name="TreeWalker">
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF: ([\w\|]+)"/>
<property name="onCommentFormat" value="CHECKSTYLE.ON: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
<module name="OuterTypeFilename"/>
<module name="NoLineWrap">
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@ComponentScan(
basePackages = {
"org.springframework.data.jpa.convert.threeten",
"de.muenchen.oss.wahllokalsystem.eaiservice"
"de.muenchen.oss.wahllokalsystem.eaiservice",
"de.muenchen.oss.wahllokalsystem.wls.common.exception"
}
)
@EntityScan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import static java.sql.Types.VARCHAR;

import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
Expand All @@ -17,24 +16,24 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.UuidGenerator;

@MappedSuperclass
@NoArgsConstructor
@Getter
@Setter
@ToString
@ToString(onlyExplicitlyIncluded = true)
@EqualsAndHashCode
public abstract class BaseEntity implements Cloneable, Serializable {

private static final long serialVersionUID = 1L;

@Column(name = "id", length = 36)
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@UuidGenerator
@JdbcTypeCode(VARCHAR)
@ToString.Include
private UUID id;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand;

import static java.sql.Types.VARCHAR;

import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotNull;
import java.util.Collection;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.JdbcTypeCode;

@Entity
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString(onlyExplicitlyIncluded = true, callSuper = true)
public class Wahlvorstand extends BaseEntity {

@NotNull
@ToString.Include
@JdbcTypeCode(VARCHAR)
private UUID wahlbezirkID;

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "wahlvorstandid")
private Collection<Wahlvorstandsmitglied> mitglieder;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand;

import java.util.Optional;
import java.util.UUID;
import org.springframework.data.repository.CrudRepository;

public interface WahlvorstandRepository extends CrudRepository<Wahlvorstand, UUID> {

Optional<Wahlvorstand> findFirstByWahlbezirkID(UUID wahlbezirkID);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand;

import de.muenchen.oss.wahllokalsystem.eaiservice.domain.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString(onlyExplicitlyIncluded = true)
public class Wahlvorstandsmitglied extends BaseEntity {

@NotNull
@ToString.Include
private String vorname;

@NotNull
@ToString.Include
private String nachname;

@NotNull
@ToString.Include
@Enumerated(EnumType.STRING)
private WahlvorstandsmitgliedsFunktion funktion;

@ToString.Include
private boolean anwesend;

@ToString.Include
private LocalDateTime anwesenheitUpdatedOn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.domain.wahlvorstand;

public enum WahlvorstandsmitgliedsFunktion {
W, //Wahlvorsteher*in
SB, //Schriftführer*in
SWB, //Stellvertretung Wahlvorsteher*in
SSB, //Stellvertretung Schriftführer*in
B //Beisitzer*in
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.exception;

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.WlsExceptionDTO;
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ServiceIDFormatter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends AbstractExceptionHandler {
private final ServiceIDFormatter serviceIDFormatter;

public GlobalExceptionHandler(final ServiceIDFormatter serviceIDFormatter, final DTOMapper dtoMapper) {
super(dtoMapper);
this.serviceIDFormatter = serviceIDFormatter;
}

@ExceptionHandler
public ResponseEntity<WlsExceptionDTO> handleThrowables(final Throwable throwable) {
log.info("handling throwable", throwable);
return createResponse(getWahlExceptionDTO(throwable));
}

@ExceptionHandler
public ResponseEntity<Void> handleNotFoundException(final NotFoundException notFoundException) {
log.debug("not found entity {} with id {}", notFoundException.getEntityClass(), notFoundException.getRequestedID());
return ResponseEntity.notFound().build();
}

@Override
protected String getService() {
return serviceIDFormatter.getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.exception;

import java.util.UUID;
import lombok.Getter;

@Getter
public class NotFoundException extends RuntimeException {

private final UUID requestedID;

private final Class<?> entityClass;

public NotFoundException(UUID requestID, Class<?> entityClass) {
this.requestedID = requestID;
this.entityClass = entityClass;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception;

public class ExceptionConstants {
import de.muenchen.oss.wahllokalsystem.wls.common.exception.util.ExceptionDataWrapper;

public static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103";
public class ExceptionConstants {

public static final String CODE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "901";
public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM = "Fremdsystem hat Fehler geworfen";
public static final String MESSAGE_FEHLER_BEI_KOMMUNIKATIONS_MIT_FREMDSYSTEM_MIT_MESSAGE = "Fremdsystem hat Fehler geworfen: %s";

public static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102";
public static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen";
private static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102";
private static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen";
public static final ExceptionDataWrapper DATENALLGEMEIN_PARAMETER_FEHLEN = new ExceptionDataWrapper(CODE_DATENALLGEMEIN_PARAMETER_FEHLEN,
MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN);

private static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103";
public static final ExceptionDataWrapper ID_NICHT_KONVERTIERBAR = new ExceptionDataWrapper(
CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR, "");

/**
* @throws IllegalAccessException when constructor is used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@

import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandDTO;
import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto.WahlvorstandsaktualisierungDTO;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import de.muenchen.oss.wahllokalsystem.eaiservice.service.wahlvorstand.WahlvorstandService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wahlvorstaende")
@RequiredArgsConstructor
public class WahlvorstandController {

private final WahlvorstandService wahlvorstandService;

@GetMapping
@ResponseStatus(HttpStatus.OK)
public WahlvorstandDTO loadWahlvorstand(@RequestParam("wahlbezirkID") String wahlbezirkID) {
throw new UnsupportedOperationException("Not supported yet.");
@Operation(description = "Abrufen des Wahlvorstandes für einen bestimmten Wahlbezirk")
public WahlvorstandDTO loadWahlvorstand(final @RequestParam("wahlbezirkID")
String wahlbezirkID) {
return wahlvorstandService.getWahlvorstandForWahlbezirk(wahlbezirkID);
}

@PostMapping
@ResponseStatus(HttpStatus.OK)
public void saveAnwesenheit(@Valid @RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) {
throw new UnsupportedOperationException("Not supported yet.");
@PutMapping("anwesenheit")
@Operation(description = "Aktualisieren der Anwesenheit der Wahlvorstandsmitglieder eines bestimmten Wahlbezirkes")
public void saveAnwesenheit(@RequestBody WahlvorstandsaktualisierungDTO wahlvorstand) {
wahlvorstandService.setAnwesenheit(wahlvorstand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.Set;

public record WahlvorstandDTO(@NotNull LocalDateTime anwesenheitBeginn,
@NotNull String wahlbezirkID,
public record WahlvorstandDTO(@NotNull String wahlbezirkID,
@NotNull @Size(min = 1) Set<WahlvorstandsmitgliedDTO> mitglieder) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.Set;
import lombok.Builder;

@Builder
public record WahlvorstandsaktualisierungDTO(@NotNull String wahlbezirkID,
@NotNull @Size(min = 1) Set<WahlvorstandsmitgliedAktualisierungDTO> mitglieder,
@NotNull LocalDateTime anwesenheitBeginn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder
public record WahlvorstandsmitgliedAktualisierungDTO(@NotNull String identifikator,
@Schema(requiredMode = Schema.RequiredMode.REQUIRED) boolean anwesend) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder
public record WahlvorstandsmitgliedDTO(@NotNull String identifikator,
@NotNull String vorname,
@NotNull String nachname,
@NotNull String funktion,
@NotNull WahlvorstandsmitgliedsFunktionDTO funktion,
@Schema(requiredMode = Schema.RequiredMode.REQUIRED) boolean anwesend) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlvorstand.dto;

public enum WahlvorstandsmitgliedsFunktionDTO {
W, //Wahlvorsteher*in
SB, //Schriftführer*in
SWB, //Stellvertretung Wahlvorsteher*in
SSB, //Stellvertretung Schriftführer*in
B //Beisitzer*in
}
Loading