Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08a9ac3584
|
||
|
|
64faaa3c4a
|
||
|
|
32581e9cc8
|
||
|
|
93016dabfa
|
||
|
|
6fb144ef43
|
||
|
|
04bec53671
|
||
|
|
40ed9b8fba
|
||
|
|
a8d2aaef09
|
||
|
|
6add2baa40
|
||
|
|
6c13815fc3
|
||
|
|
1443dfce1b
|
||
|
|
ddf24b42e2
|
||
|
|
f2c1d1ea49
|
||
|
|
aaec4e940a
|
||
|
|
a02dfa100c
|
||
|
|
0082305a5a
|
||
|
|
11345c94a5
|
||
|
|
f5f773a90b | ||
|
|
323337ed64 | ||
|
|
b04d6f4389 | ||
|
|
517f2b4f1b | ||
|
|
f089d70d5f | ||
|
|
2a78b47d83 | ||
|
|
84baee6ebb | ||
|
|
35a1b49412 | ||
|
|
9453e10803 | ||
|
|
a2b85f402d | ||
|
|
3a9c70932d | ||
|
|
7e87623b0e | ||
|
|
1b71ef0614 | ||
|
|
9aa199103d | ||
|
|
904bc60ed7 | ||
|
|
d5691e3081 | ||
|
|
538b1badec | ||
|
|
d34ca9aff2 | ||
|
|
cd79f15d5b | ||
|
|
37506b6c83 | ||
|
|
406a891849 | ||
|
|
b411c97f53 |
+8
-25
@@ -118,10 +118,13 @@ steps:
|
|||||||
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
||||||
- git clone ssh://giteajim@git.2martens.de:22/2martens/cloud-configuration.git .
|
- git clone ssh://giteajim@git.2martens.de:22/2martens/cloud-configuration.git .
|
||||||
- git checkout main
|
- git checkout main
|
||||||
- name: modify deployed image
|
- name: update image version
|
||||||
image: alpine
|
image: alpine
|
||||||
commands:
|
commands:
|
||||||
- sed -i -r "s/(wahlrecht_image_version:).*/\1\ ${DRONE_SEMVER}/" ansible/inventories/host_vars/api-server/public.yaml
|
- mkdir $HOME/bin
|
||||||
|
- wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_arm64 -O $HOME/bin/yq && chmod +x $HOME/bin/yq
|
||||||
|
- sed -i -r "s/(tag:).*/\1\ \"${DRONE_SEMVER}\"/" argocd/wahlrecht/${DRONE_DEPLOY_TO}/overwrite_values.yaml
|
||||||
|
- cd argocd/wahlrecht/${DRONE_DEPLOY_TO} && $HOME/bin/yq '. *= load("overwrite_values.yaml")' default_values.yaml > values.yaml
|
||||||
- name: save modified variable file
|
- name: save modified variable file
|
||||||
image: alpine/git
|
image: alpine/git
|
||||||
environment:
|
environment:
|
||||||
@@ -134,34 +137,14 @@ steps:
|
|||||||
- touch $HOME/.ssh/known_hosts
|
- touch $HOME/.ssh/known_hosts
|
||||||
- chmod 600 $HOME/.ssh/known_hosts
|
- chmod 600 $HOME/.ssh/known_hosts
|
||||||
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
- ssh-keyscan -H git.2martens.de > $HOME/.ssh/known_hosts 2>/dev/null
|
||||||
- git add ansible/inventories/host_vars/api-server/public.yaml
|
- git add argocd/wahlrecht/${DRONE_DEPLOY_TO}/*
|
||||||
- git diff-index --quiet HEAD || git commit -m "[Drone] Changed wahlrecht_image_version to ${DRONE_SEMVER}"
|
- git diff-index --quiet HEAD || git commit -m "[Drone] Changed wahlrecht_image_version to ${DRONE_SEMVER}"
|
||||||
- git push origin main
|
- git push origin main
|
||||||
- name: deploy image
|
|
||||||
image: plugins/ansible:latest
|
|
||||||
volumes:
|
|
||||||
- name: cache
|
|
||||||
path: /root/.ansible
|
|
||||||
settings:
|
|
||||||
playbook: ansible/deploy_spring.yaml
|
|
||||||
inventory: ansible/inventories/production
|
|
||||||
galaxy: ansible/requirements.yaml
|
|
||||||
galaxy_force: false
|
|
||||||
private_key:
|
|
||||||
from_secret: private_ssh_key
|
|
||||||
vault_password:
|
|
||||||
from_secret: vault_password
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
- name: cache
|
|
||||||
host:
|
|
||||||
path: /var/lib/drone/cache/.ansible
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
# target:
|
target:
|
||||||
# - production
|
- test
|
||||||
event:
|
event:
|
||||||
include:
|
include:
|
||||||
- promote
|
- promote
|
||||||
- rollback
|
- rollback
|
||||||
- custom
|
|
||||||
|
|||||||
+3
-3
@@ -543,9 +543,9 @@ ij_html_space_inside_empty_tag = false
|
|||||||
ij_html_text_wrap = normal
|
ij_html_text_wrap = normal
|
||||||
|
|
||||||
[{*.kt,*.kts}]
|
[{*.kt,*.kts}]
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
tab_width = 4
|
tab_width = 2
|
||||||
ij_continuation_indent_size = 8
|
ij_continuation_indent_size = 4
|
||||||
ij_kotlin_align_in_columns_case_branch = false
|
ij_kotlin_align_in_columns_case_branch = false
|
||||||
ij_kotlin_align_multiline_binary_operation = false
|
ij_kotlin_align_multiline_binary_operation = false
|
||||||
ij_kotlin_align_multiline_extends_list = false
|
ij_kotlin_align_multiline_extends_list = false
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
name: Build image
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker
|
||||||
|
uses: docker/setup-docker-action@v4
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: 17
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v4
|
||||||
|
- name: Build and push container
|
||||||
|
run: ./gradlew -Prelease.useLastTag=true final jib
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="MainApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
|
|
||||||
<module name="wahlrecht.server.main" />
|
|
||||||
<option name="SPRING_BOOT_MAIN_CLASS" value="de.twomartens.wahlrecht.MainApplication" />
|
|
||||||
<extension name="net.ashald.envfile">
|
|
||||||
<option name="IS_ENABLED" value="true" />
|
|
||||||
<option name="IS_SUBST" value="false" />
|
|
||||||
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
|
|
||||||
<option name="IS_IGNORE_MISSING_FILES" value="false" />
|
|
||||||
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
|
|
||||||
<ENTRIES>
|
|
||||||
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
|
|
||||||
<ENTRY IS_ENABLED="true" PARSER="env" IS_EXECUTABLE="false" PATH=".env" />
|
|
||||||
</ENTRIES>
|
|
||||||
</extension>
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
@@ -54,7 +54,7 @@ normalization.runtimeClasspath.metaInf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("cleanLibs") {
|
tasks.register("cleanLibs") {
|
||||||
delete("${buildDir}/libs")
|
delete("${layout.buildDirectory}/libs")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.build {
|
tasks.build {
|
||||||
|
|||||||
@@ -8,9 +8,6 @@ val libs = the<LibrariesForLibs>()
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.kotlin.logging)
|
implementation(libs.kotlin.logging)
|
||||||
implementation(libs.kotlin.reactor)
|
|
||||||
implementation(libs.kotlin.coroutines)
|
|
||||||
implementation(libs.kotlin.coroutines.reactor)
|
|
||||||
implementation(kotlin("reflect"))
|
implementation(kotlin("reflect"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ apply(plugin="com.netflix.nebula.release")
|
|||||||
tasks.register("writeVersionProperties") {
|
tasks.register("writeVersionProperties") {
|
||||||
group = "version"
|
group = "version"
|
||||||
mustRunAfter("release")
|
mustRunAfter("release")
|
||||||
outputs.file("$buildDir/version.properties")
|
outputs.file("${layout.buildDirectory}/version.properties")
|
||||||
val directory = buildDir
|
val directory = layout.buildDirectory.asFile
|
||||||
doLast {
|
doLast {
|
||||||
Files.createDirectories(directory.toPath())
|
Files.createDirectories(directory.get().toPath())
|
||||||
File("$buildDir/version.properties").writeText("VERSION=${project.version}\n")
|
File("${layout.buildDirectory}/version.properties").writeText("VERSION=${project.version}\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ val libs = the<LibrariesForLibs>()
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(platform(libs.spring.cloud))
|
implementation(platform(libs.spring.cloud))
|
||||||
implementation(libs.bundles.spring.boot.server)
|
implementation(libs.bundles.spring.boot.server)
|
||||||
|
implementation(libs.spring.openapi)
|
||||||
|
|
||||||
implementation(libs.httpclient)
|
implementation(libs.httpclient)
|
||||||
implementation(libs.prometheus)
|
implementation(libs.prometheus)
|
||||||
|
|||||||
+19
-29
@@ -1,25 +1,23 @@
|
|||||||
[versions]
|
[versions]
|
||||||
spring-boot = "3.1.2"
|
spring-boot = "3.5.4"
|
||||||
spring-doc = "2.1.0"
|
spring-doc = "2.8.9"
|
||||||
spring-doc-webflux = "1.7.0"
|
spring-cloud = "2025.0.0"
|
||||||
spring-cloud = "2022.0.4"
|
|
||||||
spring-grpc = "2.14.0.RELEASE"
|
spring-grpc = "2.14.0.RELEASE"
|
||||||
grpc = "1.57.0"
|
grpc = "1.57.0"
|
||||||
tomcat-annotations = "6.0.53"
|
tomcat-annotations = "6.0.53"
|
||||||
httpclient = "5.2.1"
|
httpclient = "5.5"
|
||||||
slf4j = "2.0.7"
|
slf4j = "2.0.17"
|
||||||
log4j = "2.20.0"
|
log4j = "2.25.1"
|
||||||
log4j-ecs = "1.5.0"
|
log4j-ecs = "1.7.0"
|
||||||
mapstruct = "1.5.5.Final"
|
mapstruct = "1.6.3"
|
||||||
junit = "5.10.0"
|
junit = "5.13.4"
|
||||||
assertj = "3.24.2"
|
assertj = "3.27.3"
|
||||||
mockito = "5.4.0"
|
mockito = "5.18.0"
|
||||||
keycloak = "22.0.1"
|
keycloak = "26.3.2"
|
||||||
|
keycloak-policy-enforcer = "26.0.6"
|
||||||
kotlin-logging = "3.0.5"
|
kotlin-logging = "3.0.5"
|
||||||
kotlin-reflect = "1.9.0"
|
kotlin-reflect = "2.2.0"
|
||||||
kotlin-lombok = "1.9.0"
|
kotlin-lombok = "1.9.0"
|
||||||
kotlin-reactor = "1.2.2"
|
|
||||||
kotlin-coroutines = "1.7.3"
|
|
||||||
plugin-nebula-release = "17.2.2"
|
plugin-nebula-release = "17.2.2"
|
||||||
plugin-lombok = "8.0.1"
|
plugin-lombok = "8.0.1"
|
||||||
plugin-gradle-versions = "0.46.0"
|
plugin-gradle-versions = "0.46.0"
|
||||||
@@ -34,12 +32,10 @@ spring-boot-web = { module = "org.springframework.boot:spring-boot-starter-web"
|
|||||||
spring-boot-log4j = { module = "org.springframework.boot:spring-boot-starter-log4j2" }
|
spring-boot-log4j = { module = "org.springframework.boot:spring-boot-starter-log4j2" }
|
||||||
spring-boot-thymeleaf = { module = "org.springframework.boot:spring-boot-starter-thymeleaf" }
|
spring-boot-thymeleaf = { module = "org.springframework.boot:spring-boot-starter-thymeleaf" }
|
||||||
spring-boot-mongo = { module = "org.springframework.boot:spring-boot-starter-data-mongodb" }
|
spring-boot-mongo = { module = "org.springframework.boot:spring-boot-starter-data-mongodb" }
|
||||||
spring-boot-mongo-reactive = { module = "org.springframework.boot:spring-boot-starter-data-mongodb-reactive" }
|
|
||||||
spring-boot-validation = { module = "org.springframework.boot:spring-boot-starter-validation" }
|
spring-boot-validation = { module = "org.springframework.boot:spring-boot-starter-validation" }
|
||||||
spring-boot-test = { module = "org.springframework.boot:spring-boot-starter-test" }
|
spring-boot-test = { module = "org.springframework.boot:spring-boot-starter-test" }
|
||||||
spring-boot-security = { module = "org.springframework.boot:spring-boot-starter-security" }
|
spring-boot-security = { module = "org.springframework.boot:spring-boot-starter-security" }
|
||||||
spring-boot-oauth2-resource-server = { module = "org.springframework.boot:spring-boot-starter-oauth2-resource-server" }
|
spring-boot-oauth2-resource-server = { module = "org.springframework.boot:spring-boot-starter-oauth2-resource-server" }
|
||||||
spring-boot-webflux = { module = "org.springframework.boot:spring-boot-starter-webflux" }
|
|
||||||
spring-boot-config = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "spring-boot" }
|
spring-boot-config = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "spring-boot" }
|
||||||
spring-cloud = { module = "org.springframework.cloud:spring-cloud-dependencies", version.ref = "spring-cloud" }
|
spring-cloud = { module = "org.springframework.cloud:spring-cloud-dependencies", version.ref = "spring-cloud" }
|
||||||
spring-cloud-starter = { module = "org.springframework.cloud:spring-cloud-starter" }
|
spring-cloud-starter = { module = "org.springframework.cloud:spring-cloud-starter" }
|
||||||
@@ -49,11 +45,10 @@ spring-cloud-config-server = { module = "org.springframework.cloud:spring-cloud-
|
|||||||
spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter" }
|
spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter" }
|
||||||
spring-grpc = { module = "net.devh:grpc-spring-boot-starter", version.ref = "spring-grpc" }
|
spring-grpc = { module = "net.devh:grpc-spring-boot-starter", version.ref = "spring-grpc" }
|
||||||
spring-ui = { module = "org.springdoc:springdoc-openapi-starter-webmvc-ui", version.ref = "spring-doc" }
|
spring-ui = { module = "org.springdoc:springdoc-openapi-starter-webmvc-ui", version.ref = "spring-doc" }
|
||||||
spring-openapi-starter = { module = "org.springdoc:springdoc-openapi-starter-common", version.ref = "spring-doc" }
|
spring-sec = { module = "org.springdoc:springdoc-openapi-starter-common", version.ref = "spring-doc" }
|
||||||
spring-openapi-webmvc = { module = "org.springdoc:springdoc-openapi-starter-webmvc-api", version.ref = "spring-doc" }
|
spring-openapi = { module = "org.springdoc:springdoc-openapi-starter-webmvc-api", version.ref = "spring-doc" }
|
||||||
spring-openapi-webflux = { module = "org.springdoc:springdoc-openapi-webflux-ui", version.ref = "spring-doc-webflux" }
|
|
||||||
keycloak-core = { module = "org.keycloak:keycloak-core", version.ref = "keycloak" }
|
keycloak-core = { module = "org.keycloak:keycloak-core", version.ref = "keycloak" }
|
||||||
keycloak-policy-enforcer = { module = "org.keycloak:keycloak-policy-enforcer", version.ref = "keycloak" }
|
keycloak-policy-enforcer = { module = "org.keycloak:keycloak-policy-enforcer", version.ref = "keycloak-policy-enforcer" }
|
||||||
grpc-api = { module = "io.grpc:grpc-api", version.ref = "grpc" }
|
grpc-api = { module = "io.grpc:grpc-api", version.ref = "grpc" }
|
||||||
grpc-context = { module = "io.grpc:grpc-context", version.ref = "grpc" }
|
grpc-context = { module = "io.grpc:grpc-context", version.ref = "grpc" }
|
||||||
grpc-core = { module = "io.grpc:grpc-core", version.ref = "grpc" }
|
grpc-core = { module = "io.grpc:grpc-core", version.ref = "grpc" }
|
||||||
@@ -84,9 +79,6 @@ mockito-inline = "org.mockito:mockito-inline:5.2.0"
|
|||||||
mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }
|
mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }
|
||||||
kotlin-logging = { module = "io.github.microutils:kotlin-logging-jvm", version.ref = "kotlin-logging" }
|
kotlin-logging = { module = "io.github.microutils:kotlin-logging-jvm", version.ref = "kotlin-logging" }
|
||||||
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin-reflect" }
|
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin-reflect" }
|
||||||
kotlin-reactor = { module = "io.projectreactor.kotlin:reactor-kotlin-extensions", version.ref = "kotlin-reactor" }
|
|
||||||
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlin-coroutines-core", version.ref = "kotlin-coroutines" }
|
|
||||||
kotlin-coroutines-reactor = { module = "org.jetbrains.kotlinx:kotlin-coroutines-reactor", version.ref = "kotlin-coroutines" }
|
|
||||||
plugin-nebula-release = { module = "com.netflix.nebula:nebula-release-plugin", version.ref = "plugin-nebula-release" }
|
plugin-nebula-release = { module = "com.netflix.nebula:nebula-release-plugin", version.ref = "plugin-nebula-release" }
|
||||||
plugin-springboot = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "spring-boot" }
|
plugin-springboot = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "spring-boot" }
|
||||||
plugin-lombok = { module = "io.freefair.gradle:lombok-plugin", version.ref = "plugin-lombok" }
|
plugin-lombok = { module = "io.freefair.gradle:lombok-plugin", version.ref = "plugin-lombok" }
|
||||||
@@ -121,14 +113,12 @@ spring-boot = [
|
|||||||
spring-boot-server = [
|
spring-boot-server = [
|
||||||
"spring-boot-actuator",
|
"spring-boot-actuator",
|
||||||
"spring-boot-log4j",
|
"spring-boot-log4j",
|
||||||
"spring-boot-mongo-reactive",
|
"spring-boot-mongo",
|
||||||
"spring-boot-thymeleaf",
|
"spring-boot-thymeleaf",
|
||||||
"spring-boot-validation",
|
"spring-boot-validation",
|
||||||
"spring-boot-web",
|
"spring-boot-web",
|
||||||
"spring-boot-webflux",
|
|
||||||
"spring-cloud-starter",
|
"spring-cloud-starter",
|
||||||
"spring-openapi-starter",
|
"spring-sec",
|
||||||
"spring-openapi-webflux",
|
|
||||||
"spring-ui",
|
"spring-ui",
|
||||||
]
|
]
|
||||||
spring-boot-security = [
|
spring-boot-security = [
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
|||||||
|
PUT http://localhost:12000/wahlrecht/v1/election
|
||||||
|
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkalp3QzZGZEZ4eHl4R0RfX3JRYVhIMzNCc0Fxa29fYXZoelRlX19IYUxRIn0.eyJleHAiOjE3MTQ5ODE3NDUsImlhdCI6MTcxNDk4MDg0NSwiYXV0aF90aW1lIjoxNzE0OTc5Njk1LCJqdGkiOiIyMzcwNTU4My1mYTE2LTQ4NWYtODNlMC0xMWIyZjg0ODEyM2YiLCJpc3MiOiJodHRwczovL2lkLjJtYXJ0ZW5zLmRlL3JlYWxtcy8ybWFydGVucyIsImF1ZCI6WyJ0c3ctdGltZXRhYmxlLWZyb250ZW5kIiwiYWNjb3VudCIsInRpbWV0YWJsZSJdLCJzdWIiOiJkOTRiMzU3My05ZjdhLTRjYmMtYTg5MS1kZGRjYWQ1MjE0YjMiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJ3YWhscmVjaHQiLCJzZXNzaW9uX3N0YXRlIjoiZGIxNmVmNzItZTUyMi00ZWE4LThjNjAtYjRjYmRiMTEzNjEyIiwiYWNyIjoiMCIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovL2FwaS4ybWFydGVucy5kZSIsImh0dHA6Ly9sb2NhbGhvc3Q6MTIwMDAiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwiQ09SRV9FTEVDVElPTl9EQVRBX0NPTlRSSUJVVE9SIiwiZGVmYXVsdC1yb2xlcy13YWhscmVjaHQiLCJBRE1JTiIsInVtYV9hdXRob3JpemF0aW9uIiwiVVNFUiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InRzdy10aW1ldGFibGUtZnJvbnRlbmQiOnsicm9sZXMiOlsiQUNUSVZFX1BMQU4iLCJQRVJTT05BTF9QTEFOIiwiRlJFRV9QTEFOIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX0sInRpbWV0YWJsZSI6eyJyb2xlcyI6WyJBRE1JTiIsIlBFUlNPTkFMX1BMQU4iLCJGUkVFX1BMQU4iXX19LCJzY29wZSI6InByb2ZpbGUgZW1haWwiLCJzaWQiOiJkYjE2ZWY3Mi1lNTIyLTRlYTgtOGM2MC1iNGNiZGIxMTM2MTIiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6IkppbSBNYXJ0ZW5zIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiZ2l0aHViQDJtYXJ0ZW5zLmRlIiwiZ2l2ZW5fbmFtZSI6IkppbSIsImxvY2FsZSI6ImVuIiwiZmFtaWx5X25hbWUiOiJNYXJ0ZW5zIiwiZW1haWwiOiJnaXRodWJAMm1hcnRlbnMuZGUifQ.VWDniNAGZOdBbQ3rIia81VqchT9fL0PbT4TS8ORpueRTVe8j2gatwDEPz3ocIFNevNh5hv0gQpjcYT8XGh5rk8oNbHrFg48uJZC5SfINzEEq9JYUQCLf_LGiXmfCODwKaRZc6EVFYU34t7d-SXrN0qNcFooFnV7erD57GJB--19nVOAv1zsQKDV_lJYz6SHGlPZol0PBOHwRaREjgsS1zw8kNOBZYFiuaAbHCOl3rrZb0YZevB1_qtPWtdCOCEjCIlGURIU6Wn6xTNUG1MkE2yytArJS1yGUfBnDDg1mAck5q_fl0a9T7lucyhakSNjauFGUWIsJP4ADdJZhn8CDVQ
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Bezirkswahl 2024",
|
||||||
|
"day": "2024-06-09",
|
||||||
|
"votingThreshold": "THREE",
|
||||||
|
"totalNumberOfSeats": 51,
|
||||||
|
"constituencies": [
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 5,
|
||||||
|
"name": "Niendorf",
|
||||||
|
"numberOfSeats": 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 6,
|
||||||
|
"name": "Schnelsen",
|
||||||
|
"numberOfSeats": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 7,
|
||||||
|
"name": "Eidelstedt",
|
||||||
|
"numberOfSeats": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 8,
|
||||||
|
"name": "Stellingen",
|
||||||
|
"numberOfSeats": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 4,
|
||||||
|
"name": "Lokstedt",
|
||||||
|
"numberOfSeats": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 3,
|
||||||
|
"name": "Rotherbaum/Harvestehude",
|
||||||
|
"numberOfSeats": 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 1,
|
||||||
|
"name": "Eimsbüttel-Nord",
|
||||||
|
"numberOfSeats": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"electionName": "Bezirkswahl 2024",
|
||||||
|
"number": 2,
|
||||||
|
"name": "Eimsbüttel-Süd/Hoheluft-West",
|
||||||
|
"numberOfSeats": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+804
-645
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ dependencies {
|
|||||||
|
|
||||||
jib {
|
jib {
|
||||||
from {
|
from {
|
||||||
image = "amazoncorretto:" + properties["projectSourceCompatibility"]
|
image = "amazoncorretto:" + properties["projectSourceCompatibility"] + "-alpine"
|
||||||
platforms {
|
platforms {
|
||||||
platform {
|
platform {
|
||||||
architecture = "amd64"
|
architecture = "amd64"
|
||||||
|
|||||||
@@ -9,6 +9,4 @@ dependencies {
|
|||||||
implementation(libs.bundles.spring.boot.security)
|
implementation(libs.bundles.spring.boot.security)
|
||||||
annotationProcessor(libs.mapstruct.processor)
|
annotationProcessor(libs.mapstruct.processor)
|
||||||
kapt(libs.mapstruct.processor)
|
kapt(libs.mapstruct.processor)
|
||||||
implementation(libs.spring.cloud.starter.config)
|
|
||||||
implementation(libs.spring.cloud.starter.bus.kafka)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ package de.twomartens.wahlrecht
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
import org.springframework.data.mongodb.config.EnableMongoAuditing
|
import org.springframework.data.mongodb.config.EnableMongoAuditing
|
||||||
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories
|
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
|
|
||||||
@EnableMongoAuditing
|
@EnableMongoAuditing
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableReactiveMongoRepositories
|
|
||||||
open class MainApplication
|
open class MainApplication
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package de.twomartens.wahlrecht.configuration
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.web.filter.ForwardedHeaderFilter
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
open class FilterConfiguration {
|
||||||
|
@Bean
|
||||||
|
open fun forwardedFilter(): ForwardedHeaderFilter {
|
||||||
|
return ForwardedHeaderFilter()
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -8,13 +8,13 @@ import java.time.Clock
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
open class InterceptorConfiguration {
|
open class InterceptorConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
open fun loggingInterceptorRest(clock: Clock): LoggingInterceptorRest {
|
open fun loggingInterceptorRest(clock: Clock): LoggingInterceptorRest {
|
||||||
return LoggingInterceptorRest(clock)
|
return LoggingInterceptorRest(clock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
open fun headerInterceptorRest(): HeaderInterceptorRest {
|
open fun headerInterceptorRest(): HeaderInterceptorRest {
|
||||||
return HeaderInterceptorRest()
|
return HeaderInterceptorRest()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-6
@@ -6,7 +6,6 @@ import io.swagger.v3.oas.annotations.security.OAuthFlows
|
|||||||
import io.swagger.v3.oas.annotations.security.SecurityScheme
|
import io.swagger.v3.oas.annotations.security.SecurityScheme
|
||||||
import io.swagger.v3.oas.models.OpenAPI
|
import io.swagger.v3.oas.models.OpenAPI
|
||||||
import io.swagger.v3.oas.models.info.Info
|
import io.swagger.v3.oas.models.info.Info
|
||||||
import io.swagger.v3.oas.models.servers.Server
|
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
@@ -16,9 +15,9 @@ import org.springframework.context.annotation.Configuration
|
|||||||
name = "oauth2",
|
name = "oauth2",
|
||||||
type = SecuritySchemeType.OAUTH2,
|
type = SecuritySchemeType.OAUTH2,
|
||||||
flows = OAuthFlows(
|
flows = OAuthFlows(
|
||||||
implicit = OAuthFlow(
|
authorizationCode = OAuthFlow(
|
||||||
authorizationUrl = "https://id.2martens.de/realms/2martens/protocol/openid-connect/auth",
|
authorizationUrl = "https://id.2martens.de/realms/twomartens/protocol/openid-connect/auth",
|
||||||
tokenUrl = "https://id.2martens.de/realms/2martens/protocol/openid-connect/token"
|
tokenUrl = "https://id.2martens.de/realms/twomartens/protocol/openid-connect/token"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -36,7 +35,5 @@ open class OpenApiConfiguration {
|
|||||||
.version(apiVersion)
|
.version(apiVersion)
|
||||||
.description(apiDescription)
|
.description(apiDescription)
|
||||||
)
|
)
|
||||||
.addServersItem(Server().url("http://localhost:12000"))
|
|
||||||
.addServersItem(Server().url("https://api.2martens.de"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-5
@@ -11,13 +11,10 @@ import org.springframework.beans.factory.annotation.Value
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import org.springframework.http.HttpMethod
|
import org.springframework.http.HttpMethod
|
||||||
import org.springframework.security.config.Customizer
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
||||||
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer
|
|
||||||
import org.springframework.security.oauth2.jwt.JwtDecoder
|
import org.springframework.security.oauth2.jwt.JwtDecoder
|
||||||
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder
|
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder
|
||||||
import org.springframework.security.oauth2.server.resource.web.authentication.BearerTokenAuthenticationFilter
|
|
||||||
import org.springframework.security.web.SecurityFilterChain
|
import org.springframework.security.web.SecurityFilterChain
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -38,8 +35,6 @@ open class WebSecurityConfiguration {
|
|||||||
.authorizeHttpRequests { it.requestMatchers(*PERMITTED_PATHS.toTypedArray<String>()).permitAll() }
|
.authorizeHttpRequests { it.requestMatchers(*PERMITTED_PATHS.toTypedArray<String>()).permitAll() }
|
||||||
.authorizeHttpRequests { it.requestMatchers(HttpMethod.OPTIONS).permitAll() }
|
.authorizeHttpRequests { it.requestMatchers(HttpMethod.OPTIONS).permitAll() }
|
||||||
.authorizeHttpRequests { it.anyRequest().authenticated() }
|
.authorizeHttpRequests { it.anyRequest().authenticated() }
|
||||||
.oauth2ResourceServer { obj: OAuth2ResourceServerConfigurer<HttpSecurity?> -> obj.jwt(Customizer.withDefaults()) }
|
|
||||||
.addFilterAfter(createPolicyEnforcerFilter(), BearerTokenAuthenticationFilter::class.java)
|
|
||||||
return http.build()
|
return http.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.PostMapping
|
|||||||
import org.springframework.web.bind.annotation.RequestBody
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = ["/wahlrecht/v1"])
|
@RequestMapping(value = ["/wahlrecht/v1"])
|
||||||
@@ -48,12 +47,12 @@ class CalculationController(private val service: CalculationService) {
|
|||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun calculateResult(
|
fun calculateResult(
|
||||||
@RequestBody electionResult: ElectionResult
|
@RequestBody electionResult: ElectionResult
|
||||||
): ResponseEntity<Mono<ElectedCandidates>> {
|
): ResponseEntity<ElectedCandidates> {
|
||||||
val result = electedCandidatesMapper.mapToExternal(
|
val result = electedCandidatesMapper.mapToExternal(
|
||||||
service.determineElectedCandidates(electionResultMapper.mapToInternal(electionResult))
|
service.determineElectedCandidates(electionResultMapper.mapToInternal(electionResult))
|
||||||
)
|
)
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(Mono.just(result))
|
.body(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-32
@@ -14,11 +14,10 @@ import io.swagger.v3.oas.annotations.tags.Tag
|
|||||||
import org.mapstruct.factory.Mappers
|
import org.mapstruct.factory.Mappers
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.http.ResponseEntity.created
|
||||||
|
import org.springframework.http.ResponseEntity.ok
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.util.UriComponentsBuilder
|
import org.springframework.web.util.UriComponentsBuilder
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuples
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = ["/wahlrecht/v1"])
|
@RequestMapping(value = ["/wahlrecht/v1"])
|
||||||
@@ -28,7 +27,7 @@ class ElectionController(private val service: ElectionService) {
|
|||||||
|
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@GetMapping(value = ["/elections"])
|
@GetMapping(value = ["/elections"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Returns all stored elections",
|
summary = "Returns all stored elections",
|
||||||
responses = [ApiResponse(
|
responses = [ApiResponse(
|
||||||
@@ -44,12 +43,13 @@ class ElectionController(private val service: ElectionService) {
|
|||||||
)]
|
)]
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
fun getElections(): Flux<Election> {
|
fun getElections(): ResponseEntity<Collection<Election>> {
|
||||||
val elections = service.getElections()
|
val elections = service.elections.asSequence()
|
||||||
.map {
|
.map { mapper.mapToExternal(it.value) }
|
||||||
mapper.mapToExternal(it)
|
.toList()
|
||||||
}
|
return ResponseEntity.ok()
|
||||||
return elections
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(elections)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
@@ -64,11 +64,10 @@ class ElectionController(private val service: ElectionService) {
|
|||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun getElectionByName(
|
fun getElectionByName(
|
||||||
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String
|
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String?
|
||||||
): ResponseEntity<Mono<Election>> {
|
): ResponseEntity<Election> {
|
||||||
val election = service.findElectionByName(electionName)
|
val election = mapper.mapToExternal(service.elections[electionName]!!)
|
||||||
.map { mapper.mapToExternal(it) }
|
return ok()
|
||||||
return ResponseEntity.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(election)
|
.body(election)
|
||||||
}
|
}
|
||||||
@@ -87,22 +86,14 @@ class ElectionController(private val service: ElectionService) {
|
|||||||
@PutMapping("/election")
|
@PutMapping("/election")
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun putElection(@RequestBody election: Election, uriComponentsBuilder: UriComponentsBuilder): Mono<ResponseEntity<Election>> {
|
fun putElection(@RequestBody election: Election?, uriComponentsBuilder: UriComponentsBuilder):
|
||||||
return service.storeElection(mapper.mapToDB(election))
|
ResponseEntity<Void> {
|
||||||
.map { tuple ->
|
val createdNew = service.storeElection(mapper.mapToDB(election!!))
|
||||||
Tuples.of(tuple.t1, mapper.mapToExternal(tuple.t2))
|
return if (createdNew) {
|
||||||
}
|
created(uriComponentsBuilder.path("/elections/{electionName}")
|
||||||
.map { tuple ->
|
.buildAndExpand(election.name).toUri())
|
||||||
if (tuple.t1) {
|
.build()
|
||||||
ResponseEntity.created(uriComponentsBuilder.path("/elections/{electionName}")
|
}
|
||||||
.buildAndExpand(tuple.t2.name).toUri())
|
else ok().build()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
} else {
|
|
||||||
ResponseEntity.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-67
@@ -16,10 +16,10 @@ import lombok.extern.slf4j.Slf4j
|
|||||||
import org.mapstruct.factory.Mappers
|
import org.mapstruct.factory.Mappers
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.http.ResponseEntity.created
|
||||||
|
import org.springframework.http.ResponseEntity.ok
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.util.UriComponentsBuilder
|
import org.springframework.web.util.UriComponentsBuilder
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuples
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@@ -27,72 +27,57 @@ import reactor.util.function.Tuples
|
|||||||
@RequestMapping(value = ["/wahlrecht/v1"])
|
@RequestMapping(value = ["/wahlrecht/v1"])
|
||||||
@Tag(name = "ElectionResults", description = "all requests relating to election results")
|
@Tag(name = "ElectionResults", description = "all requests relating to election results")
|
||||||
class ElectionResultController(private val service: ElectionResultService) {
|
class ElectionResultController(private val service: ElectionResultService) {
|
||||||
private val mapper = Mappers.getMapper(ElectionResultMapper::class.java)
|
private val mapper = Mappers.getMapper(ElectionResultMapper::class.java)
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Returns election result for given election name",
|
summary = "Returns election result for given election name",
|
||||||
responses = [ApiResponse(
|
responses = [ApiResponse(
|
||||||
responseCode = "200",
|
responseCode = "200",
|
||||||
description = "Returns stored election result for given election name",
|
description = "Returns stored election result for given election name",
|
||||||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ElectionResult::class))]
|
content = [Content(mediaType = "application/json", schema = Schema(implementation = ElectionResult::class))]
|
||||||
), ApiResponse(
|
), ApiResponse(
|
||||||
responseCode = "404",
|
responseCode = "404",
|
||||||
description = "No election result found",
|
description = "No election result found",
|
||||||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorMessage::class))]
|
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorMessage::class))]
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
@GetMapping(
|
@GetMapping(
|
||||||
value = ["/electionResult/{electionName}"],
|
value = ["/electionResults/{electionName}"],
|
||||||
produces = [MediaType.APPLICATION_JSON_VALUE]
|
produces = [MediaType.APPLICATION_JSON_VALUE]
|
||||||
)
|
)
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun getElectionByName(
|
fun getElectionResultByElectionName(
|
||||||
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String
|
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String
|
||||||
): Mono<ResponseEntity<ElectionResult>> {
|
): ResponseEntity<ElectionResult> {
|
||||||
return service.getElectionResult(electionName)
|
val result = mapper.mapToExternal(service.getElectionResult(electionName))
|
||||||
.map {
|
return ok()
|
||||||
mapper.mapToExternal(it)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
}
|
.body(result)
|
||||||
.map {
|
}
|
||||||
ResponseEntity.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Stores a new election",
|
summary = "Stores a new election",
|
||||||
responses = [ApiResponse(
|
responses = [ApiResponse(
|
||||||
responseCode = "201",
|
responseCode = "201",
|
||||||
description = "Election was created"
|
description = "Election was created"
|
||||||
), ApiResponse(responseCode = "200", description = "Election was modified"), ApiResponse(
|
), ApiResponse(responseCode = "200", description = "Election was modified"), ApiResponse(
|
||||||
responseCode = "401",
|
responseCode = "401",
|
||||||
description = "Unauthorized",
|
description = "Unauthorized",
|
||||||
content = [Content(mediaType = "plain/text")]
|
content = [Content(mediaType = "plain/text")]
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
@PutMapping("/electionResult")
|
@PutMapping("/electionResult")
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun putElection(@RequestBody electionResult: ElectionResult,
|
fun putElection(@RequestBody electionResult: ElectionResult?,
|
||||||
uriComponentsBuilder: UriComponentsBuilder): Mono<ResponseEntity<ElectionResult>> {
|
uriComponentsBuilder: UriComponentsBuilder): ResponseEntity<Void> {
|
||||||
val storedElection = service.storeResult(mapper.mapToDB(electionResult))
|
val createdNew = service.storeResult(mapper.mapToDB(electionResult!!))
|
||||||
return storedElection
|
return if (createdNew) {
|
||||||
.map { tuple ->
|
created(uriComponentsBuilder.path("/electionResult/{electionName}")
|
||||||
Tuples.of(tuple.t1, mapper.mapToExternal(tuple.t2))
|
.buildAndExpand(electionResult.electionName).toUri())
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
.map { tuple ->
|
else ok().build()
|
||||||
if (tuple.t1) {
|
}
|
||||||
ResponseEntity.created(uriComponentsBuilder.path("/electionResult/{electionName}")
|
|
||||||
.buildAndExpand(tuple.t2.electionName).toUri())
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
} else {
|
|
||||||
ResponseEntity.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-33
@@ -20,9 +20,6 @@ import org.springframework.http.ResponseEntity.ok
|
|||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
import org.springframework.web.util.UriComponentsBuilder
|
import org.springframework.web.util.UriComponentsBuilder
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuples
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping(value = ["/wahlrecht/v1"])
|
@RequestMapping(value = ["/wahlrecht/v1"])
|
||||||
@@ -45,23 +42,26 @@ class PartyController(private val service: PartyService) {
|
|||||||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorMessage::class))]
|
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorMessage::class))]
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
@GetMapping(value = ["/parties/by-election-name/{electionName}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
@GetMapping(value = ["/parties/{electionName}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun getPartiesByElectionName(
|
fun getPartiesByElectionName(
|
||||||
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String
|
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String
|
||||||
): ResponseEntity<Flux<PartyInElection>> {
|
): ResponseEntity<Collection<PartyInElection>> {
|
||||||
val parties = service.getPartiesByElectionName(electionName)
|
val parties = service.getPartiesByElectionName(electionName).stream()
|
||||||
.map { election: de.twomartens.wahlrecht.model.db.PartyInElection ->
|
.map { election: de.twomartens.wahlrecht.model.db.PartyInElection? ->
|
||||||
mapper.mapToExternal(election)
|
mapper.mapToExternal(
|
||||||
|
election!!
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
.toList()
|
||||||
return ok()
|
return ok()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(parties)
|
.body(parties)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Returns party stored for given election name and abbreviation",
|
summary = "Returns stored party for given election name and party abbreviation",
|
||||||
responses = [ApiResponse(
|
responses = [ApiResponse(
|
||||||
responseCode = "200",
|
responseCode = "200",
|
||||||
description = "Returns stored party",
|
description = "Returns stored party",
|
||||||
@@ -81,11 +81,10 @@ class PartyController(private val service: PartyService) {
|
|||||||
fun getPartyByElectionNameAndAbbreviation(
|
fun getPartyByElectionNameAndAbbreviation(
|
||||||
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String,
|
@PathVariable @Parameter(description = "the election name", example = "Bezirkswahl 2019") electionName: String,
|
||||||
@PathVariable @Parameter(description = "the party abbreviation", example = "SPD") abbreviation: String
|
@PathVariable @Parameter(description = "the party abbreviation", example = "SPD") abbreviation: String
|
||||||
): ResponseEntity<Mono<PartyInElection>> {
|
): ResponseEntity<PartyInElection> {
|
||||||
val party = service.getPartyByElectionNameAndAbbreviation(electionName, abbreviation)
|
val party = mapper.mapToExternal(
|
||||||
.map { stored: de.twomartens.wahlrecht.model.db.PartyInElection ->
|
service.getPartyByElectionNameAndAbbreviation(electionName, abbreviation)
|
||||||
mapper.mapToExternal(stored)
|
)
|
||||||
}
|
|
||||||
return ok()
|
return ok()
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.body(party)
|
.body(party)
|
||||||
@@ -104,24 +103,13 @@ class PartyController(private val service: PartyService) {
|
|||||||
@PutMapping("/party")
|
@PutMapping("/party")
|
||||||
@SecurityRequirement(name = "bearerAuth")
|
@SecurityRequirement(name = "bearerAuth")
|
||||||
@SecurityRequirement(name = "oauth2")
|
@SecurityRequirement(name = "oauth2")
|
||||||
fun putParty(@RequestBody party: PartyInElection,
|
fun putParty(@RequestBody party: PartyInElection?,
|
||||||
uriComponentsBuilder: UriComponentsBuilder): Mono<ResponseEntity<PartyInElection>> {
|
uriComponentsBuilder: UriComponentsBuilder): ResponseEntity<Void> {
|
||||||
val storedParty = service.storeParty(mapper.mapToDB(party))
|
val createdNew = service.storeParty(mapper.mapToDB(party!!))
|
||||||
return storedParty
|
return if (createdNew) {
|
||||||
.map { tuple ->
|
created(uriComponentsBuilder.path("/parties/{electionName}/{abbreviation}")
|
||||||
Tuples.of(tuple.t1, mapper.mapToExternal(tuple.t2))
|
.buildAndExpand(party.electionName, party.abbreviation).toUri())
|
||||||
}
|
.build()
|
||||||
.map { tuple ->
|
} else ok().build()
|
||||||
if (tuple.t1) {
|
|
||||||
created(uriComponentsBuilder.path("/parties/{electionName}/{abbreviation}")
|
|
||||||
.buildAndExpand(tuple.t2.electionName, tuple.t2.abbreviation).toUri())
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
} else {
|
|
||||||
ok()
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body(tuple.t2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,30 +7,27 @@ import org.springframework.data.annotation.Id
|
|||||||
import org.springframework.data.annotation.LastModifiedDate
|
import org.springframework.data.annotation.LastModifiedDate
|
||||||
import org.springframework.data.mongodb.core.index.CompoundIndex
|
import org.springframework.data.mongodb.core.index.CompoundIndex
|
||||||
import org.springframework.data.mongodb.core.mapping.Document
|
import org.springframework.data.mongodb.core.mapping.Document
|
||||||
import org.springframework.data.mongodb.core.mapping.DocumentReference
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@CompoundIndex(def = "{'name': 1, 'partyAbbreviation': 1, 'electionName': 1}")
|
@CompoundIndex(def = "{'name': 1, 'partyAbbreviation': 1, 'electionName': 1}")
|
||||||
class Nomination {
|
class Nomination {
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
@Id
|
@Id
|
||||||
var id: ObjectId? = null
|
var id: ObjectId? = null
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
@CreatedDate
|
@CreatedDate
|
||||||
var created: Instant? = null
|
var created: Instant? = null
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
@LastModifiedDate
|
@LastModifiedDate
|
||||||
var lastModified: Instant? = null
|
var lastModified: Instant? = null
|
||||||
|
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
var partyAbbreviation: String = ""
|
var partyAbbreviation: String = ""
|
||||||
var electionName: String = ""
|
var electionName: String = ""
|
||||||
|
var candidates: Collection<Candidate> = emptyList()
|
||||||
@DocumentReference
|
var supportVotesOnNomination = false
|
||||||
var candidates: Collection<Candidate> = emptyList()
|
|
||||||
var supportVotesOnNomination = false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ package de.twomartens.wahlrecht.property
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope
|
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
@RefreshScope
|
|
||||||
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht")
|
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht")
|
||||||
@Schema(description = "Properties, to configure this Application")
|
@Schema(description = "Properties, to configure this Application")
|
||||||
class ServiceProperties {
|
data class ServiceProperties @ConstructorBinding constructor(
|
||||||
lateinit var defaultTimeZone: ZoneId
|
val defaultTimeZone: ZoneId,
|
||||||
lateinit var greeting: String
|
val greeting: String
|
||||||
}
|
)
|
||||||
-2
@@ -4,11 +4,9 @@ import io.swagger.v3.oas.annotations.media.Schema
|
|||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
import org.springframework.boot.context.properties.bind.ConstructorBinding
|
||||||
import org.springframework.boot.convert.DurationUnit
|
import org.springframework.boot.convert.DurationUnit
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope
|
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.temporal.ChronoUnit
|
import java.time.temporal.ChronoUnit
|
||||||
|
|
||||||
@RefreshScope
|
|
||||||
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht.statusprobe")
|
@ConfigurationProperties(prefix = "de.twomartens.wahlrecht.statusprobe")
|
||||||
@Schema(description = "Properties, to configure this Application")
|
@Schema(description = "Properties, to configure this Application")
|
||||||
data class StatusProbeProperties @ConstructorBinding constructor(
|
data class StatusProbeProperties @ConstructorBinding constructor(
|
||||||
|
|||||||
+2
-27
@@ -1,31 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.Candidate
|
import de.twomartens.wahlrecht.model.db.Candidate
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
interface CandidateRepository : ReactiveMongoRepository<Candidate, String> {
|
interface CandidateRepository : MongoRepository<Candidate, String>
|
||||||
fun findByName(name: String): Mono<Candidate>
|
|
||||||
|
|
||||||
fun findAndModify(new: Candidate): Mono<Candidate> {
|
|
||||||
val existing = findByName(new.name)
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.flatMap { old ->
|
|
||||||
old.profession = new.profession
|
|
||||||
save(old)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
save(new)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findAllAndModify(new: Collection<Candidate>): Flux<Candidate> {
|
|
||||||
val existing = new.map {
|
|
||||||
findAndModify(it)
|
|
||||||
}
|
|
||||||
return Flux.merge(existing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-23
@@ -1,27 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.Constituency
|
import de.twomartens.wahlrecht.model.db.Constituency
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
interface ConstituencyRepository : ReactiveMongoRepository<Constituency, String> {
|
interface ConstituencyRepository : MongoRepository<Constituency, String>
|
||||||
fun findByElectionNameAndNumber(electionName: String, number: Int): Mono<Constituency>
|
|
||||||
|
|
||||||
fun findAndModify(new: Constituency): Mono<Constituency> {
|
|
||||||
val existing = findByElectionNameAndNumber(
|
|
||||||
new.electionName,
|
|
||||||
new.number)
|
|
||||||
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.flatMap { old ->
|
|
||||||
old.name = new.name
|
|
||||||
old.numberOfSeats = new.numberOfSeats
|
|
||||||
save(old)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
save(new)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-23
@@ -1,27 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.Election
|
import de.twomartens.wahlrecht.model.db.Election
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
interface ElectionRepository : ReactiveMongoRepository<Election, String> {
|
interface ElectionRepository : MongoRepository<Election, String>
|
||||||
fun findByName(name: String): Mono<Election>
|
|
||||||
|
|
||||||
fun findAndModify(new: Election): Mono<Tuple2<Boolean, Election>> {
|
|
||||||
val electionName = new.name
|
|
||||||
val existing = findByName(electionName)
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.flatMap { old ->
|
|
||||||
old.constituencies = new.constituencies
|
|
||||||
old.totalNumberOfSeats = new.totalNumberOfSeats
|
|
||||||
old.votingThreshold = new.votingThreshold
|
|
||||||
Mono.just(false).zipWith(save(old))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Mono.just(true).zipWith(save(new))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-21
@@ -1,25 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.ElectionResult
|
import de.twomartens.wahlrecht.model.db.ElectionResult
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
interface ElectionResultRepository : ReactiveMongoRepository<ElectionResult, String> {
|
interface ElectionResultRepository : MongoRepository<ElectionResult, String>
|
||||||
fun findByElectionName(electionName: String): Mono<ElectionResult>
|
|
||||||
|
|
||||||
fun findAndModify(new: ElectionResult): Mono<Tuple2<Boolean, ElectionResult>> {
|
|
||||||
val existing = findByElectionName(new.electionName)
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.flatMap { old ->
|
|
||||||
old.overallResults = new.overallResults
|
|
||||||
old.constituencyResults = new.constituencyResults
|
|
||||||
Mono.just(false).zipWith(save(old))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Mono.just(true).zipWith(save(new))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-27
@@ -1,31 +1,6 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.Nomination
|
import de.twomartens.wahlrecht.model.db.Nomination
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.core.scheduler.Schedulers
|
|
||||||
|
|
||||||
interface NominationRepository : ReactiveMongoRepository<Nomination, String> {
|
interface NominationRepository : MongoRepository<Nomination, String>
|
||||||
fun findByElectionNameAndPartyAbbreviationAndName(electionName: String,
|
|
||||||
abbreviation: String,
|
|
||||||
name: String): Mono<Nomination>
|
|
||||||
|
|
||||||
fun findAndModify(new: Nomination): Mono<Nomination> {
|
|
||||||
val existing = findByElectionNameAndPartyAbbreviationAndName(
|
|
||||||
new.electionName,
|
|
||||||
new.partyAbbreviation,
|
|
||||||
new.name
|
|
||||||
)
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.publishOn(Schedulers.boundedElastic()).publishOn(Schedulers.boundedElastic()).flatMap { old ->
|
|
||||||
old.supportVotesOnNomination = new.supportVotesOnNomination
|
|
||||||
old.candidates = new.candidates
|
|
||||||
save(old)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
save(new)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+4
-24
@@ -1,30 +1,10 @@
|
|||||||
package de.twomartens.wahlrecht.repository
|
package de.twomartens.wahlrecht.repository
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.PartyInElection
|
import de.twomartens.wahlrecht.model.db.PartyInElection
|
||||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
interface PartyRepository : ReactiveMongoRepository<PartyInElection, String> {
|
interface PartyRepository : MongoRepository<PartyInElection, String> {
|
||||||
|
fun findByElectionName(name: String): Collection<PartyInElection>
|
||||||
|
|
||||||
fun findByElectionName(name: String): Flux<PartyInElection>
|
fun findByElectionNameAndAbbreviation(electionName: String, abbreviation: String): PartyInElection?
|
||||||
|
|
||||||
fun findByElectionNameAndAbbreviation(electionName: String, abbreviation: String): Mono<PartyInElection>
|
|
||||||
|
|
||||||
fun findAndModify(party: PartyInElection): Mono<Tuple2<Boolean, PartyInElection>> {
|
|
||||||
val existing = findByElectionNameAndAbbreviation(party.electionName, party.abbreviation)
|
|
||||||
return existing.hasElement().flatMap { hasElement ->
|
|
||||||
if (hasElement) {
|
|
||||||
existing.flatMap { old ->
|
|
||||||
old.name = party.name
|
|
||||||
old.overallNomination = party.overallNomination
|
|
||||||
old.constituencyNominations = party.constituencyNominations
|
|
||||||
Mono.just(false).zipWith(save(old))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Mono.just(true).zipWith(save(party))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-40
@@ -13,53 +13,54 @@ import org.keycloak.representations.idm.authorization.Permission
|
|||||||
class SpringPolicyEnforcer(private val policyEnforcer: PolicyEnforcer,
|
class SpringPolicyEnforcer(private val policyEnforcer: PolicyEnforcer,
|
||||||
private val policyEnforcerConfig: PolicyEnforcerConfig) {
|
private val policyEnforcerConfig: PolicyEnforcerConfig) {
|
||||||
|
|
||||||
fun enforce(request: HttpRequest, response: HttpResponse): AuthorizationContext {
|
fun enforce(request: HttpRequest, response: HttpResponse): AuthorizationContext {
|
||||||
if (log.isDebugEnabled) {
|
if (log.isDebugEnabled) {
|
||||||
log.debug("Policy enforcement is enabled. Enforcing policy decisions for path [{}].", request.uri)
|
log.debug("Policy enforcement is enabled. Enforcing policy decisions for path [{}].", request.uri)
|
||||||
}
|
|
||||||
val context = authorize(request, response)
|
|
||||||
if (log.isDebugEnabled) {
|
|
||||||
log.debug("Policy enforcement result for path [{}] is : {}", request.uri, if (context.isGranted) "GRANTED" else "DENIED")
|
|
||||||
log.debug("Returning authorization context with permissions:")
|
|
||||||
for (permission in context.permissions) {
|
|
||||||
log.debug(permission.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return context
|
|
||||||
}
|
}
|
||||||
|
val context = authorize(request, response)
|
||||||
private fun authorize(request: HttpRequest, response: HttpResponse): AuthorizationContext {
|
if (log.isDebugEnabled) {
|
||||||
val enforcementMode = policyEnforcerConfig.enforcementMode
|
log.debug("Policy enforcement result for path [{}] is : {}", request.uri, if (context.isGranted) "GRANTED" else "DENIED")
|
||||||
return if (EnforcementMode.DISABLED == enforcementMode) {
|
log.debug("Returning authorization context with permissions:")
|
||||||
createAuthorizedContext()
|
for (permission in context.permissions) {
|
||||||
} else policyEnforcer.enforce(request, response)
|
log.debug(permission.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
private fun createAuthorizedContext(): AuthorizationContext {
|
private fun authorize(request: HttpRequest, response: HttpResponse): AuthorizationContext {
|
||||||
return object : ClientAuthorizationContext(policyEnforcer.authzClient) {
|
val enforcementMode = policyEnforcerConfig.enforcementMode
|
||||||
override fun hasPermission(resourceName: String, scopeName: String): Boolean {
|
log.debug("Authorize with enforcement mode: [{}]", enforcementMode)
|
||||||
return true
|
return if (EnforcementMode.DISABLED == enforcementMode) {
|
||||||
}
|
createAuthorizedContext()
|
||||||
|
} else policyEnforcer.enforce(request, response)
|
||||||
|
}
|
||||||
|
|
||||||
override fun hasResourcePermission(resourceName: String): Boolean {
|
private fun createAuthorizedContext(): AuthorizationContext {
|
||||||
return true
|
return object : ClientAuthorizationContext(policyEnforcer.authzClient) {
|
||||||
}
|
override fun hasPermission(resourceName: String, scopeName: String): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
override fun hasScopePermission(scopeName: String): Boolean {
|
override fun hasResourcePermission(resourceName: String): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPermissions(): List<Permission> {
|
override fun hasScopePermission(scopeName: String): Boolean {
|
||||||
return emptyList()
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isGranted(): Boolean {
|
override fun getPermissions(): List<Permission> {
|
||||||
return true
|
return emptyList()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
override fun isGranted(): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = KotlinLogging.logger {}
|
private val log = KotlinLogging.logger {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-6
@@ -12,18 +12,15 @@ import org.keycloak.adapters.authorization.spi.ConfigurationResolver
|
|||||||
import org.keycloak.adapters.authorization.spi.HttpRequest
|
import org.keycloak.adapters.authorization.spi.HttpRequest
|
||||||
import org.keycloak.representations.adapters.config.PolicyEnforcerConfig
|
import org.keycloak.representations.adapters.config.PolicyEnforcerConfig
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
|
|
||||||
|
|
||||||
class SpringPolicyEnforcerFilter(private val configResolver: ConfigurationResolver) : Filter {
|
class SpringPolicyEnforcerFilter(private val configResolver: ConfigurationResolver) : Filter {
|
||||||
private val policyEnforcer: MutableMap<PolicyEnforcerConfig, SpringPolicyEnforcer> = ConcurrentHashMap()
|
|
||||||
|
|
||||||
@Throws(IOException::class, ServletException::class)
|
@Throws(IOException::class, ServletException::class)
|
||||||
override fun doFilter(servletRequest: ServletRequest, servletResponse: ServletResponse?, filterChain: FilterChain) {
|
override fun doFilter(servletRequest: ServletRequest, servletResponse: ServletResponse?, filterChain: FilterChain) {
|
||||||
val request = servletRequest as HttpServletRequest
|
val request = servletRequest as HttpServletRequest
|
||||||
val response = servletResponse as HttpServletResponse?
|
val response = servletResponse as HttpServletResponse?
|
||||||
val httpRequest = ServletHttpRequest(request) { extractBearerToken(request) }
|
val httpRequest = ServletHttpRequest(request) { extractBearerToken(request) }
|
||||||
val policyEnforcer = getOrCreatePolicyEnforcer(httpRequest)
|
val policyEnforcer = createPolicyEnforcer(httpRequest)
|
||||||
val authzContext = policyEnforcer.enforce(httpRequest, ServletHttpResponse(response))
|
val authzContext = policyEnforcer.enforce(httpRequest, ServletHttpResponse(response))
|
||||||
request.setAttribute(AuthorizationContext::class.java.name, authzContext)
|
request.setAttribute(AuthorizationContext::class.java.name, authzContext)
|
||||||
if (authzContext.isGranted) {
|
if (authzContext.isGranted) {
|
||||||
@@ -53,8 +50,8 @@ class SpringPolicyEnforcerFilter(private val configResolver: ConfigurationResolv
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOrCreatePolicyEnforcer(request: HttpRequest): SpringPolicyEnforcer {
|
private fun createPolicyEnforcer(request: HttpRequest): SpringPolicyEnforcer {
|
||||||
return policyEnforcer.computeIfAbsent(configResolver.resolve(request)) { createPolicyEnforcer(it) }
|
return createPolicyEnforcer(configResolver.resolve(request))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createPolicyEnforcer(enforcerConfig: PolicyEnforcerConfig): SpringPolicyEnforcer {
|
private fun createPolicyEnforcer(enforcerConfig: PolicyEnforcerConfig): SpringPolicyEnforcer {
|
||||||
|
|||||||
+10
-5
@@ -17,9 +17,9 @@ class CalculationService(
|
|||||||
log.info("Calculate election result for election {}", electionResult.electionName)
|
log.info("Calculate election result for election {}", electionResult.electionName)
|
||||||
val stopWatch = StopWatch()
|
val stopWatch = StopWatch()
|
||||||
stopWatch.start("determineElectedCandidates")
|
stopWatch.start("determineElectedCandidates")
|
||||||
val election = electionService.getElectionInternal(electionResult.electionName).block()
|
val election = electionService.getElectionInternal(electionResult.electionName)
|
||||||
val seatResult = calculateOverallSeatDistribution(
|
val seatResult = calculateOverallSeatDistribution(
|
||||||
election!!,
|
election,
|
||||||
electionResult.overallResults
|
electionResult.overallResults
|
||||||
)
|
)
|
||||||
val constituencyResults: MutableMap<Int, ElectedResult> = HashMap()
|
val constituencyResults: MutableMap<Int, ElectedResult> = HashMap()
|
||||||
@@ -192,8 +192,8 @@ class CalculationService(
|
|||||||
.toMap()
|
.toMap()
|
||||||
.toMutableMap()
|
.toMutableMap()
|
||||||
val nominationId = votingResult.nominationId
|
val nominationId = votingResult.nominationId
|
||||||
val nomination = nominationService.getNominationInternal(nominationId).block()
|
val nomination = nominationService.getNominationInternal(nominationId)
|
||||||
if (nomination!!.supportsVotesOnNomination()) {
|
if (nomination.supportsVotesOnNomination()) {
|
||||||
val seatsByNomination = calculateSeatsByNominationOrder(votingResult, numberOfSeats)
|
val seatsByNomination = calculateSeatsByNominationOrder(votingResult, numberOfSeats)
|
||||||
seatsByVoteOrder = numberOfSeats - seatsByNomination
|
seatsByVoteOrder = numberOfSeats - seatsByNomination
|
||||||
val candidates = nomination.getCandidates()
|
val candidates = nomination.getCandidates()
|
||||||
@@ -247,6 +247,7 @@ class CalculationService(
|
|||||||
var assignedSeats: Long
|
var assignedSeats: Long
|
||||||
var assignedSeatsPerVotingResult: Map<VotingResult, Int>
|
var assignedSeatsPerVotingResult: Map<VotingResult, Int>
|
||||||
log.debug("Calculate assigned seats with initial election number {}", electionNumber)
|
log.debug("Calculate assigned seats with initial election number {}", electionNumber)
|
||||||
|
var numberOfAttempts = 5
|
||||||
do {
|
do {
|
||||||
electionNumberHistory.add(electionNumber)
|
electionNumberHistory.add(electionNumber)
|
||||||
val seatsPerVotingResult: MutableMap<VotingResult, Double> = mutableMapOf()
|
val seatsPerVotingResult: MutableMap<VotingResult, Double> = mutableMapOf()
|
||||||
@@ -277,7 +278,11 @@ class CalculationService(
|
|||||||
)
|
)
|
||||||
log.debug("Calculated higher election number {}", electionNumber)
|
log.debug("Calculated higher election number {}", electionNumber)
|
||||||
}
|
}
|
||||||
} while (assignedSeats != numberOfSeats.toLong())
|
numberOfAttempts--
|
||||||
|
} while (assignedSeats != numberOfSeats.toLong() && numberOfAttempts > 0)
|
||||||
|
if (numberOfAttempts == 0 && assignedSeats != numberOfSeats.toLong()) {
|
||||||
|
log.error("With the given result, the solution can never be calculated")
|
||||||
|
}
|
||||||
return assignedSeatsPerVotingResult
|
return assignedSeatsPerVotingResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,33 @@ package de.twomartens.wahlrecht.service
|
|||||||
import de.twomartens.wahlrecht.model.db.Candidate
|
import de.twomartens.wahlrecht.model.db.Candidate
|
||||||
import de.twomartens.wahlrecht.repository.CandidateRepository
|
import de.twomartens.wahlrecht.repository.CandidateRepository
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class CandidateService(private val repository: CandidateRepository) {
|
class CandidateService(private val repository: CandidateRepository) {
|
||||||
|
private val candidates: MutableMap<String, Candidate> by lazy {
|
||||||
|
fetchCandidates()
|
||||||
|
}
|
||||||
|
|
||||||
fun storeCandidate(candidate: Candidate): Mono<Candidate> {
|
fun storeCandidate(candidate: Candidate): Candidate {
|
||||||
return repository.findAndModify(candidate)
|
var result = candidate
|
||||||
}
|
val existing = candidates[candidate.name]
|
||||||
|
val needsUpdate = candidate != existing
|
||||||
|
if (!needsUpdate && existing != null) {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
if (existing != null) {
|
||||||
|
existing.profession = candidate.profession
|
||||||
|
result = existing
|
||||||
|
}
|
||||||
|
result = repository.save(result)
|
||||||
|
candidates[candidate.name] = candidate
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun storeCandidates(candidates: Collection<Candidate>): Flux<Candidate> {
|
private fun fetchCandidates(): MutableMap<String, Candidate> {
|
||||||
return Flux.merge(candidates.map { storeCandidate(it) })
|
return repository.findAll().asSequence()
|
||||||
}
|
.map { Pair(it.name, it) }
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-4
@@ -1,14 +1,40 @@
|
|||||||
package de.twomartens.wahlrecht.service
|
package de.twomartens.wahlrecht.service
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.model.db.Constituency
|
import de.twomartens.wahlrecht.model.db.Constituency
|
||||||
|
import de.twomartens.wahlrecht.model.internal.ConstituencyId
|
||||||
import de.twomartens.wahlrecht.repository.ConstituencyRepository
|
import de.twomartens.wahlrecht.repository.ConstituencyRepository
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ConstituencyService(private val repository: ConstituencyRepository) {
|
class ConstituencyService(private val repository: ConstituencyRepository) {
|
||||||
|
private val constituencies: MutableMap<ConstituencyId, Constituency> by lazy {
|
||||||
|
fetchConstituencies()
|
||||||
|
}
|
||||||
|
|
||||||
fun storeConstituencies(constituencies: Collection<Constituency>): Flux<Constituency> {
|
fun storeConstituency(constituency: Constituency): Constituency {
|
||||||
return Flux.merge(constituencies.map { repository.findAndModify(it) })
|
var result = constituency
|
||||||
}
|
val constituencyId = ConstituencyId(
|
||||||
|
constituency.electionName,
|
||||||
|
constituency.number
|
||||||
|
)
|
||||||
|
val existing = constituencies[constituencyId]
|
||||||
|
if (constituency == existing) {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
if (existing != null) {
|
||||||
|
existing.numberOfSeats = constituency.numberOfSeats
|
||||||
|
existing.name = constituency.name
|
||||||
|
result = existing
|
||||||
|
}
|
||||||
|
val stored = repository.save(result)
|
||||||
|
constituencies[constituencyId] = stored
|
||||||
|
return stored
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchConstituencies(): MutableMap<ConstituencyId, Constituency> {
|
||||||
|
return repository.findAll().asSequence()
|
||||||
|
.map { Pair(ConstituencyId(electionName = it.electionName, number = it.number), it) }
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-11
@@ -5,20 +5,45 @@ import de.twomartens.wahlrecht.repository.ElectionResultRepository
|
|||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ElectionResultService(private val repository: ElectionResultRepository) {
|
class ElectionResultService(private val repository: ElectionResultRepository) {
|
||||||
|
private val electionResults: MutableMap<String, ElectionResult> by lazy {
|
||||||
|
fetchResults()
|
||||||
|
}
|
||||||
|
fun getElectionResult(electionName: String): ElectionResult {
|
||||||
|
return electionResults[electionName]
|
||||||
|
?: throw ResponseStatusException(
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
"no election result found for $electionName"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun getElectionResult(electionName: String): Mono<ElectionResult> {
|
fun storeResult(electionResult: ElectionResult): Boolean {
|
||||||
return repository.findByElectionName(electionName)
|
var result = electionResult
|
||||||
.switchIfEmpty(Mono.error(
|
|
||||||
ResponseStatusException(HttpStatus.NOT_FOUND, "no election result found for $electionName")
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun storeResult(new: ElectionResult): Mono<Tuple2<Boolean, ElectionResult>> {
|
val id = result.electionName
|
||||||
return repository.findAndModify(new)
|
val existing = electionResults[id]
|
||||||
}
|
val needsUpdate = result != existing
|
||||||
|
if (!needsUpdate) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var createdNew = true
|
||||||
|
if (existing != null) {
|
||||||
|
existing.overallResults = result.overallResults
|
||||||
|
existing.constituencyResults = result.constituencyResults
|
||||||
|
result = existing
|
||||||
|
createdNew = false
|
||||||
|
}
|
||||||
|
val stored = repository.save(result)
|
||||||
|
electionResults[id] = stored
|
||||||
|
return createdNew
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchResults(): MutableMap<String, ElectionResult> {
|
||||||
|
return repository.findAll().asSequence()
|
||||||
|
.map { Pair(it.electionName, it) }
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,60 @@
|
|||||||
package de.twomartens.wahlrecht.service
|
package de.twomartens.wahlrecht.service
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.mapper.v1.ElectionMapper
|
import de.twomartens.wahlrecht.mapper.v1.ElectionMapper
|
||||||
|
import de.twomartens.wahlrecht.model.db.Constituency
|
||||||
import de.twomartens.wahlrecht.model.db.Election
|
import de.twomartens.wahlrecht.model.db.Election
|
||||||
import de.twomartens.wahlrecht.repository.ElectionRepository
|
import de.twomartens.wahlrecht.repository.ElectionRepository
|
||||||
import org.mapstruct.factory.Mappers
|
import org.mapstruct.factory.Mappers
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ElectionService(
|
class ElectionService(
|
||||||
private val electionRepository: ElectionRepository
|
private val electionRepository: ElectionRepository,
|
||||||
|
private val constituencyService: ConstituencyService
|
||||||
) {
|
) {
|
||||||
private val electionMapper = Mappers.getMapper(ElectionMapper::class.java)
|
private val electionMapper = Mappers.getMapper(ElectionMapper::class.java)
|
||||||
|
private val _elections: MutableMap<String, Election> by lazy {
|
||||||
fun getElections(): Flux<Election> {
|
fetchElections()
|
||||||
return electionRepository.findAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findElectionByName(electionName: String): Mono<Election> {
|
|
||||||
return electionRepository.findByName(electionName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getElectionInternal(electionName: String): Mono<de.twomartens.wahlrecht.model.internal.Election> {
|
|
||||||
return findElectionByName(electionName).map {
|
|
||||||
electionMapper.mapToInternal(it)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun storeElection(new: Election): Mono<Tuple2<Boolean, Election>> {
|
val elections: Map<String, Election> = _elections
|
||||||
return electionRepository.findAndModify(new)
|
|
||||||
}
|
private fun getElection(electionName: String): Election? {
|
||||||
|
return elections[electionName]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getElectionInternal(electionName: String): de.twomartens.wahlrecht.model.internal.Election {
|
||||||
|
return electionMapper.mapToInternal(getElection(electionName)!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun storeElection(election: Election): Boolean {
|
||||||
|
var result = election
|
||||||
|
var createdNew = true
|
||||||
|
val electionName = election.name
|
||||||
|
val existing = elections[electionName]
|
||||||
|
if (election == existing) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val constituencies: MutableCollection<Constituency> = mutableListOf()
|
||||||
|
result.constituencies
|
||||||
|
.forEach { constituencies.add(constituencyService.storeConstituency(it)) }
|
||||||
|
if (existing != null) {
|
||||||
|
existing.day = election.day
|
||||||
|
existing.totalNumberOfSeats = election.totalNumberOfSeats
|
||||||
|
existing.votingThreshold = election.votingThreshold
|
||||||
|
result = existing
|
||||||
|
createdNew = false
|
||||||
|
}
|
||||||
|
result.constituencies = constituencies
|
||||||
|
val stored = electionRepository.save(result)
|
||||||
|
_elections[electionName] = stored
|
||||||
|
return createdNew
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchElections(): MutableMap<String, Election> {
|
||||||
|
return electionRepository.findAll().asSequence()
|
||||||
|
.map { Pair(it.name, it) }
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-23
@@ -1,41 +1,69 @@
|
|||||||
package de.twomartens.wahlrecht.service
|
package de.twomartens.wahlrecht.service
|
||||||
|
|
||||||
import de.twomartens.wahlrecht.mapper.v1.NominationMapper
|
import de.twomartens.wahlrecht.mapper.v1.NominationMapper
|
||||||
|
import de.twomartens.wahlrecht.model.db.Candidate
|
||||||
import de.twomartens.wahlrecht.model.db.Nomination
|
import de.twomartens.wahlrecht.model.db.Nomination
|
||||||
import de.twomartens.wahlrecht.model.internal.NominationId
|
import de.twomartens.wahlrecht.model.internal.NominationId
|
||||||
import de.twomartens.wahlrecht.repository.NominationRepository
|
import de.twomartens.wahlrecht.repository.NominationRepository
|
||||||
import org.mapstruct.factory.Mappers
|
import org.mapstruct.factory.Mappers
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class NominationService(
|
class NominationService(
|
||||||
private val repository: NominationRepository
|
private val repository: NominationRepository,
|
||||||
|
private val candidateService: CandidateService
|
||||||
) {
|
) {
|
||||||
private val mapper = Mappers.getMapper(NominationMapper::class.java)
|
private val mapper = Mappers.getMapper(NominationMapper::class.java)
|
||||||
|
private val nominations: MutableMap<NominationId, Nomination> by lazy {
|
||||||
fun getNominationInternal(id: NominationId): Mono<de.twomartens.wahlrecht.model.internal.Nomination> {
|
fetchNominations()
|
||||||
return getNomination(id).map {
|
|
||||||
mapper.mapToInternal(it)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun storeNomination(new: Nomination?): Mono<Nomination> {
|
fun getNominationInternal(id: NominationId): de.twomartens.wahlrecht.model.internal.Nomination {
|
||||||
if (new == null) return Mono.empty()
|
return mapper.mapToInternal(getNomination(id)!!)
|
||||||
|
}
|
||||||
|
|
||||||
return repository.findAndModify(new)
|
fun storeNomination(nomination: Nomination?): Nomination? {
|
||||||
}
|
if (nomination == null) return null
|
||||||
|
val nominationId = NominationId(
|
||||||
|
nomination.electionName,
|
||||||
|
nomination.partyAbbreviation,
|
||||||
|
nomination.name
|
||||||
|
)
|
||||||
|
val existing = nominations[nominationId]
|
||||||
|
val needsUpdate = nomination != existing
|
||||||
|
if (!needsUpdate) {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
var result: Nomination = nomination
|
||||||
|
val candidates: MutableCollection<Candidate> = ArrayList()
|
||||||
|
result.candidates
|
||||||
|
.forEach { candidates.add(candidateService.storeCandidate(it)) }
|
||||||
|
if (existing != null) {
|
||||||
|
result = existing
|
||||||
|
}
|
||||||
|
result.candidates = candidates
|
||||||
|
result = repository.save(nomination)
|
||||||
|
nominations[nominationId] = result
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun storeNominations(new: Collection<Nomination>): Flux<Nomination> {
|
private fun getNomination(id: NominationId): Nomination? {
|
||||||
return Flux.merge(new.map { storeNomination(it) })
|
return nominations[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNomination(id: NominationId): Mono<Nomination> {
|
private fun fetchNominations(): MutableMap<NominationId, Nomination> {
|
||||||
return repository.findByElectionNameAndPartyAbbreviationAndName(
|
return repository.findAll().asSequence()
|
||||||
id.electionName,
|
.map {
|
||||||
id.partyAbbreviation,
|
Pair(
|
||||||
id.name
|
NominationId(
|
||||||
)
|
electionName = it.electionName,
|
||||||
}
|
partyAbbreviation = it.partyAbbreviation,
|
||||||
|
name = it.name
|
||||||
|
),
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,73 @@
|
|||||||
package de.twomartens.wahlrecht.service
|
package de.twomartens.wahlrecht.service
|
||||||
|
|
||||||
|
import de.twomartens.wahlrecht.model.db.Nomination
|
||||||
import de.twomartens.wahlrecht.model.db.PartyInElection
|
import de.twomartens.wahlrecht.model.db.PartyInElection
|
||||||
|
import de.twomartens.wahlrecht.model.internal.PartyId
|
||||||
import de.twomartens.wahlrecht.repository.PartyRepository
|
import de.twomartens.wahlrecht.repository.PartyRepository
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
import reactor.core.publisher.Flux
|
|
||||||
import reactor.core.publisher.Mono
|
|
||||||
import reactor.util.function.Tuple2
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class PartyService(
|
class PartyService(
|
||||||
private val partyRepository: PartyRepository
|
private val partyRepository: PartyRepository,
|
||||||
|
private val nominationService: NominationService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun getPartiesByElectionName(electionName: String): Flux<PartyInElection> {
|
private val parties: MutableMap<PartyId, PartyInElection> by lazy {
|
||||||
return partyRepository.findByElectionName(electionName)
|
fetchParties()
|
||||||
.switchIfEmpty(Flux.error(
|
}
|
||||||
ResponseStatusException(HttpStatus.NOT_FOUND, "no party found for $electionName")
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPartyByElectionNameAndAbbreviation(electionName: String,
|
fun getPartyByElectionNameAndAbbreviation(electionName: String,
|
||||||
abbreviation: String): Mono<PartyInElection> {
|
abbreviation: String): PartyInElection {
|
||||||
return partyRepository.findByElectionNameAndAbbreviation(electionName, abbreviation)
|
return partyRepository.findByElectionNameAndAbbreviation(electionName, abbreviation)
|
||||||
|
?: throw ResponseStatusException(HttpStatus.NOT_FOUND,
|
||||||
|
"no party found for $electionName and $abbreviation")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun storeParty(new: PartyInElection): Mono<Tuple2<Boolean, PartyInElection>> {
|
fun getPartiesByElectionName(electionName: String): Collection<PartyInElection> {
|
||||||
return partyRepository.findAndModify(new)
|
val parties = partyRepository.findByElectionName(electionName)
|
||||||
}
|
if (parties.isEmpty()) {
|
||||||
|
throw ResponseStatusException(HttpStatus.NOT_FOUND, "no party found for $electionName")
|
||||||
|
}
|
||||||
|
return parties
|
||||||
|
}
|
||||||
|
|
||||||
|
fun storeParty(partyInElection: PartyInElection): Boolean {
|
||||||
|
var result = partyInElection
|
||||||
|
var createdNew = true
|
||||||
|
val partyId = PartyId(
|
||||||
|
partyInElection.electionName,
|
||||||
|
partyInElection.abbreviation
|
||||||
|
)
|
||||||
|
val existing = parties[partyId]
|
||||||
|
val needsUpdate = partyInElection != existing
|
||||||
|
if (!needsUpdate) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val constituencyNominations: MutableMap<Int, Nomination> = mutableMapOf()
|
||||||
|
result.constituencyNominations
|
||||||
|
.forEach { constituencyNominations[it.key] = nominationService.storeNomination(it.value)!! }
|
||||||
|
if (existing != null) {
|
||||||
|
existing.name = partyInElection.name
|
||||||
|
if (constituencyNominations.isEmpty()) {
|
||||||
|
constituencyNominations.putAll(existing.constituencyNominations)
|
||||||
|
}
|
||||||
|
result = existing
|
||||||
|
createdNew = false
|
||||||
|
}
|
||||||
|
partyInElection.constituencyNominations = constituencyNominations
|
||||||
|
partyInElection.overallNomination = nominationService.storeNomination(partyInElection.overallNomination)!!
|
||||||
|
result = partyRepository.save(result)
|
||||||
|
parties[partyId] = result
|
||||||
|
return createdNew
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchParties(): MutableMap<PartyId, PartyInElection> {
|
||||||
|
val allParties = partyRepository.findAll()
|
||||||
|
return allParties.asSequence()
|
||||||
|
.map { Pair(PartyId(electionName = it.electionName, abbreviation = it.abbreviation), it) }
|
||||||
|
.toMap()
|
||||||
|
.toMutableMap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
server.port: 12000
|
|
||||||
management.server.port: 12001
|
|
||||||
|
|
||||||
|
|
||||||
spring:
|
|
||||||
config:
|
|
||||||
import:
|
|
||||||
- "classpath:config/wahlrecht.yaml"
|
|
||||||
- "optional:configserver:http://localhost:8888/config"
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
spring:
|
|
||||||
config:
|
|
||||||
import:
|
|
||||||
- "configserver:http://configserver:8888/config"
|
|
||||||
kafka:
|
|
||||||
bootstrap-servers:
|
|
||||||
- kafka:9092
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
server:
|
server:
|
||||||
port: 12000
|
port: ${PORT:12000}
|
||||||
shutdown: graceful
|
shutdown: graceful
|
||||||
|
forward-headers-strategy: framework
|
||||||
|
|
||||||
### technical configurations ###
|
### technical configurations ###
|
||||||
management:
|
management:
|
||||||
# for security, don't use same port as application
|
# for security, don't use same port as application
|
||||||
server.port: 12001
|
server.port: ${ACTUATOR_PORT:12001}
|
||||||
health:
|
health:
|
||||||
livenessState.enabled: true
|
livenessState.enabled: true
|
||||||
readinessState.enabled: true
|
readinessState.enabled: true
|
||||||
@@ -23,9 +24,6 @@ management:
|
|||||||
http.server.requests: true
|
http.server.requests: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
|
||||||
config:
|
|
||||||
name: wahlrecht
|
|
||||||
main:
|
main:
|
||||||
banner-mode: off
|
banner-mode: off
|
||||||
profiles:
|
profiles:
|
||||||
@@ -37,7 +35,7 @@ spring:
|
|||||||
oauth2:
|
oauth2:
|
||||||
resourceserver:
|
resourceserver:
|
||||||
jwt:
|
jwt:
|
||||||
jwk-set-uri: https://id.2martens.de/realms/2martens/protocol/openid-connect/certs
|
jwk-set-uri: ${KEYCLOAK_URL:https://id.2martens.de}/realms/${KEYCLOAK_REALM:twomartens}/protocol/openid-connect/certs
|
||||||
application:
|
application:
|
||||||
name: wahlrecht
|
name: wahlrecht
|
||||||
|
|
||||||
@@ -86,3 +84,12 @@ resttemplate:
|
|||||||
connectionRestHealthIndicatorTimeoutInMillis: 5000
|
connectionRestHealthIndicatorTimeoutInMillis: 5000
|
||||||
readTimeoutRestTemplateInMillis: 5000
|
readTimeoutRestTemplateInMillis: 5000
|
||||||
connectionRestTemplateTimeoutInMillis: 5000
|
connectionRestTemplateTimeoutInMillis: 5000
|
||||||
|
|
||||||
|
de.twomartens.wahlrecht:
|
||||||
|
defaultTimeZone: Europe/Berlin
|
||||||
|
greeting: "Hello %s, on millenium"
|
||||||
|
statusprobe:
|
||||||
|
scheduleDuration: 60
|
||||||
|
maxKafkaFailureDuration: 5
|
||||||
|
maxBlobFailureCount: 5
|
||||||
|
maxFailurePercent: 50
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
de.twomartens.wahlrecht:
|
|
||||||
greeting: "Moin %s, you are test"
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
de.twomartens.wahlrecht:
|
|
||||||
defaultTimeZone: Europe/Berlin
|
|
||||||
greeting: "Hello %s, on millenium"
|
|
||||||
statusprobe:
|
|
||||||
scheduleDuration: 60
|
|
||||||
maxKafkaFailureDuration: 5
|
|
||||||
maxBlobFailureCount: 5
|
|
||||||
maxFailurePercent: 50
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"realm": "2martens",
|
"realm": "twomartens",
|
||||||
"auth-server-url": "https://id.2martens.de",
|
"auth-server-url": "https://id.2martens.de",
|
||||||
"resource": "wahlrecht",
|
"resource": "wahlrecht",
|
||||||
"http-method-as-scope": true
|
"http-method-as-scope": true
|
||||||
|
|||||||
Reference in New Issue
Block a user