generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from it-at-m/169-implementierung-monitoring-w…
…ahlbeteiligung 169 implementierung monitoring wahlbeteiligung
- Loading branch information
Showing
51 changed files
with
1,605 additions
and
421 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
stack/keycloak/migration/add-authorities-monitoring-waehleranzahl.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
id: add authorities monitoring waehleranzahl | ||
author: dragonfly28 | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addRole: | ||
name: Monitoring_BUSINESSACTION_GetWahlbeteiligung | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allMonitoringAuthorities | ||
role: Monitoring_BUSINESSACTION_GetWahlbeteiligung | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Monitoring_BUSINESSACTION_PostWahlbeteiligung | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allMonitoringAuthorities | ||
role: Monitoring_BUSINESSACTION_PostWahlbeteiligung | ||
clientId: ${SSO_CLIENT_ID} | ||
|
||
- addRole: | ||
name: Monitoring_READ_Waehleranzahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allMonitoringAuthorities | ||
role: Monitoring_READ_Waehleranzahl | ||
clientId: ${SSO_CLIENT_ID} | ||
- addRole: | ||
name: Monitoring_WRITE_Waehleranzahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allMonitoringAuthorities | ||
role: Monitoring_WRITE_Waehleranzahl | ||
clientId: ${SSO_CLIENT_ID} | ||
- addRole: | ||
name: Monitoring_DELETE_Waehleranzahl | ||
clientRole: true | ||
clientId: ${SSO_CLIENT_ID} | ||
- assignRoleToGroup: | ||
group: allMonitoringAuthorities | ||
role: Monitoring_DELETE_Waehleranzahl | ||
clientId: ${SSO_CLIENT_ID} |
15 changes: 15 additions & 0 deletions
15
stack/keycloak/migration/create-group-all-monitoring-authorities.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
id: create group allMonitoringAuthorities and link wls_all* | ||
author: dragonfly28 | ||
realm: ${SSO_REALM} | ||
changes: | ||
- addGroup: | ||
name: allMonitoringAuthorities | ||
- assignGroup: | ||
user: wls_all | ||
group: allMonitoringAuthorities | ||
- assignGroup: | ||
user: wls_all_uwb | ||
group: allMonitoringAuthorities | ||
- assignGroup: | ||
user: wls_all_bwb | ||
group: allMonitoringAuthorities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../muenchen/oss/wahllokalsystem/monitoringservice/client/waehleranzahl/DummyClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl; | ||
|
||
import de.muenchen.oss.wahllokalsystem.monitoringservice.configuration.Profiles; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlClient; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Profile(Profiles.DUMMY_CLIENTS) | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class DummyClientImpl implements WaehleranzahlClient { | ||
|
||
@Override | ||
public void postWahlbeteiligung(WaehleranzahlModel waehleranzahlModel) throws WlsException { | ||
log.info("Dummy client postWahlbeteiligung() called instead of EAI with: {}", waehleranzahlModel); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...n/oss/wahllokalsystem/monitoringservice/client/waehleranzahl/WaehleranzahlClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl; | ||
|
||
import de.muenchen.oss.wahllokalsystem.monitoringservice.configuration.Profiles; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.client.WahlbeteiligungControllerApi; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlClient; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.WlsException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Profile(Profiles.NOT + Profiles.DUMMY_CLIENTS) | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class WaehleranzahlClientImpl implements WaehleranzahlClient { | ||
|
||
private final WahlbeteiligungControllerApi wahlbeteiligungControllerApi; | ||
private final WaehleranzahlClientMapper waehleranzahlClientMapper; | ||
|
||
@Override | ||
public void postWahlbeteiligung(final WaehleranzahlModel waehleranzahlModel) throws WlsException { | ||
val wahlbeteiligungsMeldungDTO = waehleranzahlClientMapper.fromModelToRemoteClientDTO(waehleranzahlModel); | ||
try { | ||
wahlbeteiligungControllerApi.saveWahlbeteiligung(wahlbeteiligungsMeldungDTO); | ||
} catch (final Exception exception) { | ||
log.error("Wahllokalzustand nicht gesendet. Exception: ", exception); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...oss/wahllokalsystem/monitoringservice/client/waehleranzahl/WaehleranzahlClientMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.muenchen.oss.wahllokalsystem.monitoringservice.client.waehleranzahl; | ||
|
||
import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.model.WahlbeteiligungsMeldungDTO; | ||
import de.muenchen.oss.wahllokalsystem.monitoringservice.service.waehleranzahl.WaehleranzahlModel; | ||
import java.time.LocalDateTime; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
import lombok.val; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public interface WaehleranzahlClientMapper { | ||
|
||
ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); | ||
|
||
@Mapping(target = "wahlID", ignore = true) | ||
@Mapping(target = "wahlbezirkID", source = "bezirkUndWahlID.wahlbezirkID") | ||
@Mapping(target = "meldeZeitpunkt", source = "uhrzeit") | ||
WahlbeteiligungsMeldungDTO fromModelToRemoteClientDTO(WaehleranzahlModel waehleranzahlModel); | ||
|
||
default OffsetDateTime localDateTimeToOffsetDateTime(LocalDateTime localDateTime) { | ||
return localDateTimeToOffsetDateTime(localDateTime, DEFAULT_ZONE_ID); | ||
} | ||
|
||
default OffsetDateTime localDateTimeToOffsetDateTime(LocalDateTime localDateTime, ZoneId zoneId) { | ||
val zoneOffset = zoneId.getRules().getOffset(localDateTime); | ||
return localDateTime.atOffset(zoneOffset); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...e/muenchen/oss/wahllokalsystem/monitoringservice/configuration/BasePathConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package de.muenchen.oss.wahllokalsystem.monitoringservice.configuration; | ||
|
||
import de.muenchen.oss.wahllokalsystem.monitoringservice.eai.aou.ApiClient; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class BasePathConfiguration { | ||
|
||
@Value("${app.clients.eai.basePath}") | ||
String eaiBasePath; | ||
|
||
private final ApiClient eaiApiClient; | ||
|
||
@PostConstruct | ||
public void updateBasePaths() { | ||
eaiApiClient.setBasePath(eaiBasePath); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../de/muenchen/oss/wahllokalsystem/monitoringservice/configuration/ClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.muenchen.oss.wahllokalsystem.monitoringservice.configuration; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.WlsResponseErrorHandler; | ||
import lombok.val; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.core.AbstractOAuth2Token; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class ClientConfiguration { | ||
|
||
@Bean | ||
public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { | ||
return new WlsResponseErrorHandler(objectMapper); | ||
} | ||
|
||
@Bean | ||
public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { | ||
val restTemplate = new RestTemplate(); | ||
|
||
restTemplate.setErrorHandler(wlsResponseErrorHandler); | ||
restTemplate.getInterceptors().add((request, body, execution) -> { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication == null) { | ||
return execution.execute(request, body); | ||
} | ||
|
||
if (!(authentication.getCredentials() instanceof AbstractOAuth2Token token)) { | ||
return execution.execute(request, body); | ||
} | ||
|
||
request.getHeaders().setBearerAuth(token.getTokenValue()); | ||
return execution.execute(request, body); | ||
}); | ||
|
||
return restTemplate; | ||
} | ||
} |
Oops, something went wrong.