From ee322ca36103ae6b6b1e99e4cb785bf6e0303ce8 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:58:27 +0200 Subject: [PATCH 01/11] create demo for use of generated openapi client --- wls-basisdaten-service/pom.xml | 53 +++++++++++++++++++ .../configuration/ClientConfiguration.java | 36 +++++++++++++ .../rest/ClientDemoRestController.java | 19 +++++++ .../basisdatenservice/rest/DemoClient.java | 20 +++++++ .../basisdatenservice/rest/DemoDTO.java | 4 ++ .../src/main/resources/application.yml | 5 ++ .../main/resources/openapis/openapi.eai.json | 1 + .../src/test/resources/demo.http | 22 ++++++++ 8 files changed, 160 insertions(+) create mode 100644 wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java create mode 100644 wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/ClientDemoRestController.java create mode 100644 wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java create mode 100644 wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoDTO.java create mode 100644 wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json create mode 100644 wls-basisdaten-service/src/test/resources/demo.http diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 137f3a7ac..3662b7375 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -76,6 +76,10 @@ org.springframework.boot spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-webflux + @@ -165,6 +169,11 @@ springdoc-openapi-starter-webmvc-ui ${org.springdoc.version} + + org.openapitools + jackson-databind-nullable + 0.2.6 + @@ -324,6 +333,50 @@ + + + org.openapitools + openapi-generator-maven-plugin + 7.5.0 + + + generateEAI + + generate + + + ${project.basedir}/src/main/resources/openapis/openapi.eai.json + + java + webclient + + de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api + de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model + + false + false + false + false + false + + + false + false + false + true + true + + + + + BaseApi.java,ApiClient.java,JavaTimeFormatter.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,HttpBearerAuth.java,RFC3339DateFormat.java + + + + + + + maven-scm-plugin ${maven-scm-plugin.version} diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java new file mode 100644 index 000000000..e52f25a77 --- /dev/null +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java @@ -0,0 +1,36 @@ +package de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration; + +import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.ApiClient; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api.WahlvorschlagControllerApi; +import lombok.val; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.oauth2.server.resource.web.reactive.function.client.ServletBearerExchangeFilterFunction; +import org.springframework.web.reactive.function.client.WebClient; + +@Configuration +public class ClientConfiguration { + + @Value("${app.clients.eai.basePath}") + String eaiBasePath; + + @Bean + public WahlvorschlagControllerApi wahlvorschlagControllerApi(final ApiClient apiClient) { + return new WahlvorschlagControllerApi(apiClient); + } + + @Bean + public ApiClient eaiApiClient(final WebClient webClient) { + val eaiApiClient = new ApiClient(webClient); + eaiApiClient.setBasePath(eaiBasePath); + return eaiApiClient; + } + + @Bean + public WebClient webClient() { + return WebClient.builder().baseUrl(eaiBasePath) + .filter(new ServletBearerExchangeFilterFunction()) + .build(); + } +} diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/ClientDemoRestController.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/ClientDemoRestController.java new file mode 100644 index 000000000..fd6f784e8 --- /dev/null +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/ClientDemoRestController.java @@ -0,0 +1,19 @@ +package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest; + +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/demo") +@RequiredArgsConstructor +public class ClientDemoRestController { + + private final DemoClient demoClient; + + @GetMapping + public DemoDTO getDemo() { + return demoClient.getDemo(); + } +} diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java new file mode 100644 index 000000000..5a8af09ca --- /dev/null +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java @@ -0,0 +1,20 @@ +package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest; + +import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api.WahlvorschlagControllerApi; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class DemoClient { + + private final WahlvorschlagControllerApi wahlvorschlagControllerApi; + + public DemoDTO getDemo() { + val wahlvorschlaege = wahlvorschlagControllerApi.loadWahlvorschlaege("wahlID", "wahlbezirkID").block(); + + return new DemoDTO(wahlvorschlaege.getStimmzettelgebietID(), "" + wahlvorschlaege.getWahlvorschlaege().size()); + } + +} diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoDTO.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoDTO.java new file mode 100644 index 000000000..8504b0a8d --- /dev/null +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoDTO.java @@ -0,0 +1,4 @@ +package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest; + +public record DemoDTO(String demoString1, String demoString) { +} diff --git a/wls-basisdaten-service/src/main/resources/application.yml b/wls-basisdaten-service/src/main/resources/application.yml index 7b717c450..e8b86d097 100644 --- a/wls-basisdaten-service/src/main/resources/application.yml +++ b/wls-basisdaten-service/src/main/resources/application.yml @@ -56,3 +56,8 @@ management: enabled: true info.application.name: @project.artifactId@ info.application.version: @project.version@ + +app: + clients: + eai: + basePath: http://localhost:39146 \ No newline at end of file diff --git a/wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json b/wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json new file mode 100644 index 000000000..e254cb9c9 --- /dev/null +++ b/wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json @@ -0,0 +1 @@ +{"openapi":"3.0.1","info":{"title":"EAI Service","contact":{"name":"Your Name","email":"Your E-Mail-Address"},"version":"0.0.1-RC1"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"security":[{"bearerAuth":[]}],"paths":{"/wahlvorstaende":{"get":{"tags":["wahlvorstand-controller"],"operationId":"loadWahlvorstand","parameters":[{"name":"wahlbezirkID","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahlvorstandDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}},"post":{"tags":["wahlvorstand-controller"],"operationId":"saveAnwesenheit","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WahlvorstandsaktualisierungDTO"}}},"required":true},"responses":{"200":{"description":"OK"},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahllokalzustand":{"post":{"tags":["wahllokalzustand-controller"],"operationId":"saveWahllokalZustand","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WahllokalZustandDTO"}}},"required":true},"responses":{"200":{"description":"OK"},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahlergebnis":{"post":{"tags":["wahlergebnis-controller"],"operationId":"saveWahlergebnismeldung","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErgebnismeldungDTO"}}},"required":true},"responses":{"200":{"description":"OK"},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahlbeteiligung":{"post":{"tags":["wahlbeteiligung-controller"],"operationId":"saveWahlbeteiligung","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WahlbeteiligungsMeldungDTO"}}},"required":true},"responses":{"200":{"description":"OK"},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahldaten/wahltage":{"get":{"tags":["wahldaten-controller"],"operationId":"loadWahltageSinceIncluding","parameters":[{"name":"includingAfter","in":"query","required":true,"schema":{"type":"string","format":"date"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahltageDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahldaten/wahlen":{"get":{"tags":["wahldaten-controller"],"operationId":"loadWahlen","parameters":[{"name":"forDate","in":"query","required":true,"schema":{"type":"string","format":"date"}},{"name":"withNummer","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahlenDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahldaten/wahlbezirke/{wahlbezirkID}/wahlberechtigte":{"get":{"tags":["wahldaten-controller"],"operationId":"loadWahlberechtigte","parameters":[{"name":"wahlbezirkID","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WahlberechtigteDTO"}}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahldaten/wahlbezirk":{"get":{"tags":["wahldaten-controller"],"operationId":"loadWahlbezirke","parameters":[{"name":"forDate","in":"query","required":true,"schema":{"type":"string","format":"date"}},{"name":"withNummer","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahlbezirkeDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/wahldaten/basisdaten":{"get":{"tags":["wahldaten-controller"],"operationId":"getBasisdaten","parameters":[{"name":"forDate","in":"query","required":true,"schema":{"type":"string","format":"date"}},{"name":"withNummer","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/BasisdatenDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/vorschlaege/wahl/{wahlID}/{wahlbezirkID}":{"get":{"tags":["wahlvorschlag-controller"],"operationId":"loadWahlvorschlaege","parameters":[{"name":"wahlID","in":"path","required":true,"schema":{"type":"string"}},{"name":"wahlbezirkID","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahlvorschlaegeDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/vorschlaege/wahl/{wahlID}/liste":{"get":{"tags":["wahlvorschlag-controller"],"operationId":"loadWahlvorschlaegeListe","parameters":[{"name":"forDate","in":"query","required":true,"schema":{"type":"string","format":"date"}},{"name":"wahlID","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/WahlvorschlaegeListeDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}},"/vorschlaege/referendum/{wahlID}/{wahlbezirkID}":{"get":{"tags":["wahlvorschlag-controller"],"operationId":"loadReferendumvorlagen","parameters":[{"name":"wahlID","in":"path","required":true,"schema":{"type":"string"}},{"name":"wahlbezirkID","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ReferendumvorlagenDTO"}}}},"400":{"description":"request body validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"404":{"description":"no resource found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}},"500":{"description":"unhandled error during communication with other system","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WlsExceptionDTO"}}}}}}}},"components":{"schemas":{"WahlvorstandsaktualisierungDTO":{"required":["anwesenheitBeginn","mitglieder","wahlbezirkID"],"type":"object","properties":{"wahlbezirkID":{"type":"string"},"mitglieder":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlvorstandsmitgliedAktualisierungDTO"}},"anwesenheitBeginn":{"type":"string","format":"date-time"}}},"WahlvorstandsmitgliedAktualisierungDTO":{"required":["anwesend","identifikator"],"type":"object","properties":{"identifikator":{"type":"string"},"anwesend":{"type":"boolean"}}},"DruckzustandDTO":{"required":["niederschriftDruckUhrzeit","niederschriftSendenUhrzeit","schnellmeldungDruckUhrzeit","schnellmeldungSendenUhrzeit","wahlID"],"type":"object","properties":{"wahlID":{"type":"string"},"schnellmeldungSendenUhrzeit":{"type":"string","format":"date-time"},"niederschriftSendenUhrzeit":{"type":"string","format":"date-time"},"schnellmeldungDruckUhrzeit":{"type":"string","format":"date-time"},"niederschriftDruckUhrzeit":{"type":"string","format":"date-time"}}},"WahllokalZustandDTO":{"required":["druckzustaende","letzteAbmeldung","wahlbezirkID","zuletztGesehen"],"type":"object","properties":{"wahlbezirkID":{"type":"string"},"zuletztGesehen":{"type":"string","format":"date-time"},"letzteAbmeldung":{"type":"string","format":"date-time"},"druckzustaende":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/DruckzustandDTO"}}}},"AWerteDTO":{"type":"object","properties":{"a1":{"type":"integer","format":"int64"},"a2":{"type":"integer","format":"int64"}}},"BWerteDTO":{"type":"object","properties":{"b":{"type":"integer","format":"int64"},"b1":{"type":"integer","format":"int64"},"b2":{"type":"integer","format":"int64"}}},"ErgebnisDTO":{"required":["ergebnis","kandidatID","stimmenart","wahlvorschlagID","wahlvorschlagsordnungszahl"],"type":"object","properties":{"stimmenart":{"type":"string"},"wahlvorschlagsordnungszahl":{"type":"integer","format":"int64"},"ergebnis":{"type":"integer","format":"int64"},"wahlvorschlagID":{"type":"string"},"kandidatID":{"type":"string"}}},"ErgebnismeldungDTO":{"required":["wahlID","wahlbezirkID"],"type":"object","properties":{"wahlbezirkID":{"type":"string"},"wahlID":{"type":"string"},"meldungsart":{"type":"string","enum":["NIEDERSCHRIFT","SCHNELLMELDUNG"]},"aWerte":{"$ref":"#/components/schemas/AWerteDTO"},"bWerte":{"$ref":"#/components/schemas/BWerteDTO"},"wahlbriefeWerte":{"$ref":"#/components/schemas/WahlbriefeWerteDTO"},"ungueltigeStimmzettels":{"type":"array","items":{"$ref":"#/components/schemas/UngueltigeStimmzettelDTO"}},"ungueltigeStimmzettelAnzahl":{"type":"integer","format":"int64"},"ergebnisse":{"type":"array","items":{"$ref":"#/components/schemas/ErgebnisDTO"}},"wahlart":{"type":"string","enum":["BAW","BEB","BTW","BZW","EUW","LTW","MBW","OBW","SRW","SVW","VE"]}}},"UngueltigeStimmzettelDTO":{"type":"object","properties":{"stimmenart":{"type":"string"},"anzahl":{"type":"integer","format":"int64"},"wahlvorschlagID":{"type":"string"}}},"WahlbriefeWerteDTO":{"type":"object","properties":{"zurueckgewiesenGesamt":{"type":"integer","format":"int64"}}},"WahlbeteiligungsMeldungDTO":{"required":["anzahlWaehler","meldeZeitpunkt","wahlID","wahlbezirkID"],"type":"object","properties":{"wahlID":{"type":"string"},"wahlbezirkID":{"type":"string"},"anzahlWaehler":{"type":"integer","format":"int64"},"meldeZeitpunkt":{"type":"string","format":"date-time"}}},"WahlvorstandDTO":{"required":["anwesenheitBeginn","mitglieder","wahlbezirkID"],"type":"object","properties":{"anwesenheitBeginn":{"type":"string","format":"date-time"},"wahlbezirkID":{"type":"string"},"mitglieder":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlvorstandsmitgliedDTO"}}}},"WahlvorstandsmitgliedDTO":{"required":["anwesend","funktion","identifikator","nachname","vorname"],"type":"object","properties":{"identifikator":{"type":"string"},"vorname":{"type":"string"},"nachname":{"type":"string"},"funktion":{"type":"string"},"anwesend":{"type":"boolean"}}},"WahltagDTO":{"required":["beschreibung","identifikator","nummer","tag"],"type":"object","properties":{"identifikator":{"type":"string"},"tag":{"type":"string","format":"date"},"beschreibung":{"type":"string"},"nummer":{"type":"string"}}},"WahltageDTO":{"required":["wahltage"],"type":"object","properties":{"wahltage":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahltagDTO"}}}},"WahlDTO":{"required":["identifikator","name","nummer","wahlart","wahltag"],"type":"object","properties":{"identifikator":{"type":"string"},"name":{"type":"string"},"wahlart":{"type":"string","enum":["BAW","BEB","BTW","BZW","EUW","LTW","MBW","OBW","SRW","SVW","VE"]},"wahltag":{"type":"string","format":"date"},"nummer":{"type":"string"}}},"WahlenDTO":{"required":["wahlen"],"type":"object","properties":{"wahlen":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlDTO"}}}},"WahlberechtigteDTO":{"required":["a1","a2","a3","wahlID","wahlbezirkID"],"type":"object","properties":{"wahlID":{"type":"string"},"wahlbezirkID":{"type":"string"},"a1":{"type":"integer","format":"int64"},"a2":{"type":"integer","format":"int64"},"a3":{"type":"integer","format":"int64"}}},"WahlbezirkDTO":{"required":["identifikator","nummer","wahlID","wahlbezirkArt","wahlnummer","wahltag"],"type":"object","properties":{"identifikator":{"type":"string"},"wahlbezirkArt":{"type":"string","enum":["UWB","BWB"]},"nummer":{"type":"string"},"wahltag":{"type":"string","format":"date"},"wahlnummer":{"type":"string"},"wahlID":{"type":"string"}}},"WahlbezirkeDTO":{"required":["wahlbezirke"],"type":"object","properties":{"wahlbezirke":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlbezirkDTO"}}}},"BasisdatenDTO":{"required":["basisstrukturdaten","stimmzettelgebiete","wahlbezirke","wahlen"],"type":"object","properties":{"basisstrukturdaten":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/BasisstrukturdatenDTO"}},"wahlen":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlDTO"}},"wahlbezirke":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlbezirkDTO"}},"stimmzettelgebiete":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/StimmzettelgebietDTO"}}}},"BasisstrukturdatenDTO":{"required":["stimmzettelgebietID","wahlID","wahlbezirkID","wahltag"],"type":"object","properties":{"wahlID":{"type":"string"},"stimmzettelgebietID":{"type":"string"},"wahlbezirkID":{"type":"string"},"wahltag":{"type":"string","format":"date"}}},"StimmzettelgebietDTO":{"required":["stimmzettelgebietart"],"type":"object","properties":{"identifikator":{"type":"string"},"nummer":{"type":"string"},"name":{"type":"string"},"wahltag":{"type":"string","format":"date"},"stimmzettelgebietart":{"type":"string","enum":["SB","SG","SK","WK"]}}},"KandidatDTO":{"required":["identifikator","listenposition","name","tabellenSpalteInNiederschrift"],"type":"object","properties":{"identifikator":{"type":"string"},"name":{"type":"string"},"listenposition":{"type":"integer","format":"int64"},"direktkandidat":{"type":"boolean"},"tabellenSpalteInNiederschrift":{"type":"integer","format":"int64"},"einzelbewerber":{"type":"boolean"}}},"WahlvorschlaegeDTO":{"required":["stimmzettelgebietID","wahlID","wahlbezirkID","wahlvorschlaege"],"type":"object","properties":{"wahlbezirkID":{"type":"string"},"wahlID":{"type":"string"},"stimmzettelgebietID":{"type":"string"},"wahlvorschlaege":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlvorschlagDTO"}}}},"WahlvorschlagDTO":{"required":["erhaeltStimmen","identifikator","kurzname","ordnungszahl"],"type":"object","properties":{"identifikator":{"type":"string"},"ordnungszahl":{"type":"integer","format":"int64"},"kurzname":{"type":"string"},"erhaeltStimmen":{"type":"boolean"},"kandidaten":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/KandidatDTO"}}}},"WahlvorschlaegeListeDTO":{"required":["wahlvorschlaege"],"type":"object","properties":{"wahlvorschlaege":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/WahlvorschlaegeDTO"}}}},"ReferendumoptionDTO":{"required":["id","name"],"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"position":{"type":"integer","format":"int64"}}},"ReferendumvorlageDTO":{"required":["frage","kurzname","ordnungszahl","referendumoption","wahlvorschlagID"],"type":"object","properties":{"wahlvorschlagID":{"type":"string"},"ordnungszahl":{"type":"integer","format":"int64"},"kurzname":{"type":"string"},"frage":{"type":"string"},"referendumoption":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/ReferendumoptionDTO"}}}},"ReferendumvorlagenDTO":{"required":["referendumvorlage","stimmzettelgebietID"],"type":"object","properties":{"stimmzettelgebietID":{"type":"string"},"referendumvorlage":{"maxItems":2147483647,"minItems":1,"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/ReferendumvorlageDTO"}}}},"WlsExceptionDTO":{"required":["category","code","message","service"],"type":"object","properties":{"category":{"type":"string","enum":["F","T","S","I"]},"code":{"type":"string"},"service":{"type":"string"},"message":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}}} \ No newline at end of file diff --git a/wls-basisdaten-service/src/test/resources/demo.http b/wls-basisdaten-service/src/test/resources/demo.http new file mode 100644 index 000000000..0c014406f --- /dev/null +++ b/wls-basisdaten-service/src/test/resources/demo.http @@ -0,0 +1,22 @@ +### get token for wls_all +POST http://kubernetes.docker.internal:8100/auth/realms/wls_realm/protocol/openid-connect/token +Content-Type: application/x-www-form-urlencoded + +password = test & +grant_type = password & +client_secret = top-secret & +client_id = wls & +username = wls_all + +> {% + client.global.set("auth_token", response.body.access_token); + client.global.set("token_type", response.body.token_type); +%} + +### get userinfo with auth_token +GET http://kubernetes.docker.internal:8100/auth/realms/wls_realm/protocol/openid-connect/userinfo +Authorization: {{ token_type }} {{ auth_token }} + +### Demo für client zu EAI +GET http://localhost:39151/demo +Authorization: {{ token_type }} {{ auth_token }} \ No newline at end of file From 765e7e2bff59de2a4c72cbc1478de2d375834fd2 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:42:21 +0200 Subject: [PATCH 02/11] switch openapi client to resttemplate and use response error handler --- wls-basisdaten-service/pom.xml | 9 ++++- .../configuration/ClientConfiguration.java | 39 +++++++++++++++---- .../basisdatenservice/rest/DemoClient.java | 2 +- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 3662b7375..2995e53eb 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -81,6 +81,13 @@ spring-boot-starter-webflux + + + de.muenchen.oss.wahllokalsystem.wls-common + exception + 1.1.0 + + org.springframework.boot @@ -348,7 +355,7 @@ ${project.basedir}/src/main/resources/openapis/openapi.eai.json java - webclient + resttemplate de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java index e52f25a77..ee7831c25 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java @@ -1,13 +1,17 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration; +import com.fasterxml.jackson.databind.ObjectMapper; import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.ApiClient; import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api.WahlvorschlagControllerApi; +import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.WlsResponseErrorHandler; import lombok.val; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.oauth2.server.resource.web.reactive.function.client.ServletBearerExchangeFilterFunction; -import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.oauth2.core.AbstractOAuth2Token; +import org.springframework.web.client.RestTemplate; @Configuration public class ClientConfiguration { @@ -15,22 +19,43 @@ public class ClientConfiguration { @Value("${app.clients.eai.basePath}") String eaiBasePath; + @Bean + public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { + return new WlsResponseErrorHandler(objectMapper); + } + @Bean public WahlvorschlagControllerApi wahlvorschlagControllerApi(final ApiClient apiClient) { return new WahlvorschlagControllerApi(apiClient); } @Bean - public ApiClient eaiApiClient(final WebClient webClient) { + public ApiClient eaiApiClient(final RestTemplate webClient) { val eaiApiClient = new ApiClient(webClient); eaiApiClient.setBasePath(eaiBasePath); return eaiApiClient; } @Bean - public WebClient webClient() { - return WebClient.builder().baseUrl(eaiBasePath) - .filter(new ServletBearerExchangeFilterFunction()) - .build(); + public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { + val restTemplate = new RestTemplate(); + + restTemplate.setErrorHandler(wlsResponseErrorHandler); + restTemplate.getInterceptors().add((request, body, execution) -> { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) { + return execution.execute(request, body); + } + + if (!(authentication.getCredentials() instanceof AbstractOAuth2Token)) { + return execution.execute(request, body); + } + + val token = (AbstractOAuth2Token) authentication.getCredentials(); + request.getHeaders().setBearerAuth(token.getTokenValue()); + return execution.execute(request, body); + }); + + return restTemplate; } } diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java index 5a8af09ca..da508a950 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java @@ -12,7 +12,7 @@ public class DemoClient { private final WahlvorschlagControllerApi wahlvorschlagControllerApi; public DemoDTO getDemo() { - val wahlvorschlaege = wahlvorschlagControllerApi.loadWahlvorschlaege("wahlID", "wahlbezirkID").block(); + val wahlvorschlaege = wahlvorschlagControllerApi.loadWahlvorschlaege("wahlID", "wahlbezirkID"); return new DemoDTO(wahlvorschlaege.getStimmzettelgebietID(), "" + wahlvorschlaege.getWahlvorschlaege().size()); } From 5e15e23e24a3c7a1dc58921f35df6b2217e82a5b Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:53:36 +0200 Subject: [PATCH 03/11] remove unused dependency --- wls-basisdaten-service/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 2995e53eb..b887c9182 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -76,10 +76,6 @@ org.springframework.boot spring-boot-starter-actuator - - org.springframework.boot - spring-boot-starter-webflux - From e112d0d59597956e62c12c153ddb01c2f5faff91 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:46:57 +0200 Subject: [PATCH 04/11] add version to openapi file --- wls-basisdaten-service/pom.xml | 2 +- wls-basisdaten-service/src/main/resources/application.yml | 1 + .../openapis/{openapi.eai.json => openapi.eai.0.0.1-RC1.json} | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename wls-basisdaten-service/src/main/resources/openapis/{openapi.eai.json => openapi.eai.0.0.1-RC1.json} (100%) diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index b887c9182..61b064a5c 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -348,7 +348,7 @@ generate - ${project.basedir}/src/main/resources/openapis/openapi.eai.json + ${project.basedir}/src/main/resources/openapis/openapi.eai.0.0.1-RC1.json java resttemplate diff --git a/wls-basisdaten-service/src/main/resources/application.yml b/wls-basisdaten-service/src/main/resources/application.yml index e8b86d097..82eae7f41 100644 --- a/wls-basisdaten-service/src/main/resources/application.yml +++ b/wls-basisdaten-service/src/main/resources/application.yml @@ -36,6 +36,7 @@ server: include-stacktrace: never whitelabel: enabled: false + max-http-request-header-size: 32KB # Config for spring actuator endpoints management: diff --git a/wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json b/wls-basisdaten-service/src/main/resources/openapis/openapi.eai.0.0.1-RC1.json similarity index 100% rename from wls-basisdaten-service/src/main/resources/openapis/openapi.eai.json rename to wls-basisdaten-service/src/main/resources/openapis/openapi.eai.0.0.1-RC1.json From 5d4f8864161d80fac80fe023bb31fa07b6e91830 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:47:48 +0200 Subject: [PATCH 05/11] generate client as beans --- wls-basisdaten-service/pom.xml | 6 ++--- .../configuration/BasePathConfiguration.java | 22 +++++++++++++++++++ .../configuration/ClientConfiguration.java | 18 --------------- 3 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 61b064a5c..7cb0910dd 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -357,16 +357,14 @@ de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model false - false false + false false - false false - false false - true + true true diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java new file mode 100644 index 000000000..a833679d6 --- /dev/null +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java @@ -0,0 +1,22 @@ +package de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration; + +import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.ApiClient; +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@RequiredArgsConstructor +public class BasePathConfiguration { + + @Value("${app.clients.eai.basePath}") + String eaiBasePath; + + private final ApiClient eaiApiClient; + + @PostConstruct + public void updateBasePaths() { + eaiApiClient.setBasePath(eaiBasePath); + } +} diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java index ee7831c25..e6cc9c434 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java @@ -1,11 +1,8 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration; import com.fasterxml.jackson.databind.ObjectMapper; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.ApiClient; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api.WahlvorschlagControllerApi; import de.muenchen.oss.wahllokalsystem.wls.common.exception.errorhandler.WlsResponseErrorHandler; import lombok.val; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.core.Authentication; @@ -16,26 +13,11 @@ @Configuration public class ClientConfiguration { - @Value("${app.clients.eai.basePath}") - String eaiBasePath; - @Bean public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { return new WlsResponseErrorHandler(objectMapper); } - @Bean - public WahlvorschlagControllerApi wahlvorschlagControllerApi(final ApiClient apiClient) { - return new WahlvorschlagControllerApi(apiClient); - } - - @Bean - public ApiClient eaiApiClient(final RestTemplate webClient) { - val eaiApiClient = new ApiClient(webClient); - eaiApiClient.setBasePath(eaiBasePath); - return eaiApiClient; - } - @Bean public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { val restTemplate = new RestTemplate(); From 403ecc9d1fa74915c03ef3bd5385fdb1c4d526e1 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Thu, 20 Jun 2024 09:48:15 +0200 Subject: [PATCH 06/11] add a guide how to generate a client --- docs/.vitepress/config.mts | 5 + ...how-to-create-client-from-open-api-json.md | 214 ++++++++++++++++++ docs/src/guides/index.md | 0 ...shot-wls-eai-service-release-0.0.1-RC1.png | Bin 0 -> 23940 bytes 4 files changed, 219 insertions(+) create mode 100644 docs/src/guides/how-to-create-client-from-open-api-json.md create mode 100644 docs/src/guides/index.md create mode 100644 docs/src/public/screenshot-wls-eai-service-release-0.0.1-RC1.png diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index cfa953c3e..7e0625032 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -2,6 +2,7 @@ import {withMermaid} from "vitepress-plugin-mermaid" const PATH_TECHNIK = '/technik/'; const PATH_FEATURES = '/features/'; +const PATH_GUIDES = '/guides/'; // https://vitepress.dev/reference/site-config export default withMermaid({ @@ -16,6 +17,7 @@ export default withMermaid({ {text: 'Home', link: '/'}, {text: 'About', link: '/about/'}, {text: 'Features', link: '/features/'}, + {text: 'Guides', link: PATH_GUIDES}, {text: 'Technik', link: PATH_TECHNIK} ], @@ -53,6 +55,9 @@ export default withMermaid({ {text: 'Wahlvorstand-Service', link: `${PATH_FEATURES}wahlvorstand-service/`}, {text: 'Ergebnismeldung-Service', link: `${PATH_FEATURES}ergebnismeldung-service/`}, {text: 'Auth-Service', link: `${PATH_FEATURES}auth-service/`}, + ], + [PATH_GUIDES]: [ + {text: 'API-Client generieren', link: `${PATH_GUIDES}how-to-create-client-from-open-api-json.md`} ] }, diff --git a/docs/src/guides/how-to-create-client-from-open-api-json.md b/docs/src/guides/how-to-create-client-from-open-api-json.md new file mode 100644 index 000000000..c931efb71 --- /dev/null +++ b/docs/src/guides/how-to-create-client-from-open-api-json.md @@ -0,0 +1,214 @@ +# API-Client aus OpenAPI-Spec erstellen + +## Einleitung + +Alle Services stellen ihre API in Form einer OpenAPI Spezifikation zur Verfügung. Diese Dateien liegen den Assets +der jeweiligen Releases bei. + +![Übersicht über Release von wls-eai-service Version 0.0.1-RC1](/screenshot-wls-eai-service-release-0.0.1-RC1.png) +*Übersicht über [Release](https://github.com/it-at-m/Wahllokalsystem/releases/tag/wls-eai-service%2F0.0.1-RC1) von +wls-eai-service Version 0.0.1-RC1* + +Durch ein Maven-Plugin lassen sich aus der Datei `openapi.json` der Client generieren. + +## Einfügen des Plugins + +Um aus der Spezifikation die Java-Klassen zu erstellen, muss das Generator-Plugin eingebunden werden. + +```xml + + + org.openapitools + openapi-generator-maven-plugin + 7.5.0 + + + +``` + +Für jeden zu erzeugenden Client mus ein `execution`-Element definiert werden. + +## Konfigurieren der Ausführung + +```xml + + + + generateEAI + + generate + + + + ${project.basedir}/src/main/resources/openapis/openapi.eai.0.0.1-RC1.json + + + java + + resttemplate + + + + de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api + + de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model + + + false + false + + false + false + + + + false + + false + + true + + true + + + + + + BaseApi.java,ApiClient.java,JavaTimeFormatter.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,HttpBearerAuth.java,RFC3339DateFormat.java + + + + +``` + +Eine ausführliche Beschreibung alle Konfigurationsoptionen gibt es in der +[offiziellen Dokumentation](https://openapi-generator.tech/docs/generators/java/). + +Bei der Konfiguration für die Packages soll folgendes Schema beachtet werden: +`.clients..(api|model)` + +## Ergänzen von Dependencies + +Damit die generierten Klassen compiliert werden können, muss folgende Dependency ergänzt werden: + +```xml + + + org.openapitools + jackson-databind-nullable + 0.2.6 + +``` + +Des Weiteren wird für die abschließende Konfiguration der Beans `wls-common:exception` benötigt: + +```xml + + + de.muenchen.oss.wahllokalsystem.wls-common + exception + 1.1.0 + +``` + +## Context um Beans erweitern + +Damit der generierte Client verwendet werden kann, muss dem Spring-Context noch ein `RestTemplate` hinzugefügt werden: + +```java + +@Bean +public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { + val restTemplate = new RestTemplate(); + + /* definieren des Errorhandlers für Antworten vom externen Service */ + restTemplate.setErrorHandler(wlsResponseErrorHandler); + /* Ergänzen eines Interceptors um den Bearer-Token an den nächsten Service weiter zu geben */ + restTemplate.getInterceptors().add((request, body, execution) -> { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) { + return execution.execute(request, body); + } + + if (!(authentication.getCredentials() instanceof AbstractOAuth2Token)) { + return execution.execute(request, body); + } + + val token = (AbstractOAuth2Token) authentication.getCredentials(); + request.getHeaders().setBearerAuth(token.getTokenValue()); + return execution.execute(request, body); + }); + + return restTemplate; +} +``` + +Wie zu erkennen ist, wird für das RestTemplate ein ErrorHandler benötigt, wobei wir hier den `WlsResponseErrorHandler` +aus `wls-common:exception` verwenden. Eine entsprechende Bean muss ebenfalls noch dem Spring-Context hinzugefügt werden: + +```java + +@Bean +public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { + return new WlsResponseErrorHandler(objectMapper); +} +``` + +## Target des Clients definieren + +Nachdem jetzt alle Beans im Kontext sind, fehlt nur noch die Konfiguration unter welche Adresse der Service, für den wir +den Client generiert haben, erreichbar ist. + +❗Diese Konfiguration darf nicht in derselben Konfigurationsklasse enthalten sein, in der das `RestTemplate` erstellt +wird, das sonst eine zirkulare Abhängigkeit vorliegt und die Anwendung nicht startet. + +```java + +@Configuration +@RequiredArgsConstructor +public class BasePathConfiguration { + + /* Umgebungsvariable welche die Ziel-URL enthält, z.b. http//localhost:39146 */ + @Value("${app.clients.eai.basePath}") + String eaiBasePath; + + private final ApiClient eaiApiClient; + + @PostConstruct + public void updateBasePaths() { + eaiApiClient.setBasePath(eaiBasePath); + } +} +``` + +In der `application.yml` wird der Defaultwert für die Ziel-URL hinterlegt: + +```yml +app: + clients: + eai: + basePath: http://localhost:39146 +``` + +## EAI-Client definieren und verwenden + +Abschließend wird der EAI-Client, welche das Datenmodell des aufgerufenen externen Services auf das Datenmodell unseres +Services mappt, erstellt: + +```java + +@Component +@RequiredArgsConstructor +public class DemoClient { + + private final WahlvorschlagControllerApi wahlvorschlagControllerApi; + + public DemoDTO getDemo() { + val wahlvorschlaege = wahlvorschlagControllerApi.loadWahlvorschlaege("wahlID", "wahlbezirkID"); + + return new DemoDTO(wahlvorschlaege.getStimmzettelgebietID(), "" + wahlvorschlaege.getWahlvorschlaege().size()); + } + +} +``` \ No newline at end of file diff --git a/docs/src/guides/index.md b/docs/src/guides/index.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/src/public/screenshot-wls-eai-service-release-0.0.1-RC1.png b/docs/src/public/screenshot-wls-eai-service-release-0.0.1-RC1.png new file mode 100644 index 0000000000000000000000000000000000000000..3f7ed6167edb58e773dc34fd4330f9a71bb12b35 GIT binary patch literal 23940 zcmeFZcT^Nz*DqLzfC`9@2q++!03|C)f*=njvgDj3No<1T&q8RgrpcLZ zkR&0Q8E_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}Y>dLMmNNwklV6q;tJa>@N`6pC!|wofp=8B&Q}*ov1EQ)a zXHSTWqS5;bVg>plaRDubO4|bpkVN+SXRjbTdhLsczgxK;nCeO#sjlxpv1%XW>nE zao~fk><080wdIjH<-lfx+f&QJaD&ypuc|3vf`LY@PhS5=ZI&vff`zF96>Y%V>ASyA z?*;lP&|nc&=-)J0+Zw3kUfO2KJ>$&Z5{TYV-?pvBrRuDCiA;%x5H!6k-$<-$3@Z^#3sTrtl1-p1SbN&A#~bM9^#KlRp#B(#Kd*X{D}u|s5c0`0LGtsU3UsC%vd(5TP=8QdA#(aE88HHwbYOi z9vg+bCi7ht#?7INw$dL3c1W|(!jQiLAKzfV6uci(?uY5reyTlyadM1{E3xh8<6I># zE!{C4r+^V^T9DDHW`f*HgEM(4VRIL+2Q%4^oFecl)^ZeGvcQ*`YLS$s2xl-}>%9GO zZC+Pkz6X23e0>y8Ddc|}@=};osXH1rIKjN>65pl35C;v%o^Li}uPnQjT<7>cDio?#q`Gh(7PZO0TR@HjoH5x6CNj#$yVHC`E5WyOrrQdDv)KbS1(AzPg zD}VpknKnA7!=F#M9ov@AzHI--g&GpKUf7f#$Ll zGoSU>b+UgLTpi5d`>@@*s>bwW@Uj>BdCfWdbPN*N;qjF}G>oQ409ME&8Z)btaGPgl z8vQbbFKCfJ|Ga%aZ|w3SNp3$`-Ty+7G&_9w@8-w5dQYB#qMpoOChCVTii%P%CkbCV zNpPE5V)0U2sz(`vb49+P1)OPiMjKDCL;5se8x1Y#&>HfAWuzMHBv)5FuA6dqcdZ)# z03ro!;0tIiW^pf}zl(aH6tq$LQ?TeuuV$BeYaihNN{ zO8pZf^?C7p`pY1UZ8qN62&X{j6hVAv6N!8|A`CgdX0G0&oTbe_>HlV+yf7WnHrh@t?0CK Date: Thu, 20 Jun 2024 09:49:03 +0200 Subject: [PATCH 07/11] improve code: use replace variable --- .../basisdatenservice/configuration/ClientConfiguration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java index e6cc9c434..6cb9b0548 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/ClientConfiguration.java @@ -29,11 +29,10 @@ public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorH return execution.execute(request, body); } - if (!(authentication.getCredentials() instanceof AbstractOAuth2Token)) { + if (!(authentication.getCredentials() instanceof AbstractOAuth2Token token)) { return execution.execute(request, body); } - val token = (AbstractOAuth2Token) authentication.getCredentials(); request.getHeaders().setBearerAuth(token.getTokenValue()); return execution.execute(request, body); }); From 51e8aef63b2652036e4110a42520d9f481e4c887 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:21:24 +0200 Subject: [PATCH 08/11] change client and model package --- docs/src/guides/how-to-create-client-from-open-api-json.md | 4 ++-- wls-basisdaten-service/pom.xml | 4 ++-- .../configuration/BasePathConfiguration.java | 2 +- .../wahllokalsystem/basisdatenservice/rest/DemoClient.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/src/guides/how-to-create-client-from-open-api-json.md b/docs/src/guides/how-to-create-client-from-open-api-json.md index c931efb71..e9ccb177d 100644 --- a/docs/src/guides/how-to-create-client-from-open-api-json.md +++ b/docs/src/guides/how-to-create-client-from-open-api-json.md @@ -49,9 +49,9 @@ Für jeden zu erzeugenden Client mus ein `execution`-Element definiert werden. - de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api + ${groupId}.basisdatenservice.eai.aou.client - de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model + ${groupId}.basisdatenservice.eai.aou.model false diff --git a/wls-basisdaten-service/pom.xml b/wls-basisdaten-service/pom.xml index 7cb0910dd..c679cb63a 100644 --- a/wls-basisdaten-service/pom.xml +++ b/wls-basisdaten-service/pom.xml @@ -353,8 +353,8 @@ java resttemplate - de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api - de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.model + ${groupId}.basisdatenservice.eai.aou.client + ${groupId}.basisdatenservice.eai.aou.model false false diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java index a833679d6..b158469b9 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/configuration/BasePathConfiguration.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.configuration; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.ApiClient; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.ApiClient; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; diff --git a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java index da508a950..2a10352b4 100644 --- a/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java +++ b/wls-basisdaten-service/src/main/java/de/muenchen/oss/wahllokalsystem/basisdatenservice/rest/DemoClient.java @@ -1,6 +1,6 @@ package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest; -import de.muenchen.oss.wahllokalsystem.basisdatenservice.clients.eai.api.WahlvorschlagControllerApi; +import de.muenchen.oss.wahllokalsystem.basisdatenservice.eai.aou.client.WahlvorschlagControllerApi; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Component; From f7ccbbb5e64ef469db9d91e4e9792d206a8f1b60 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:24:17 +0200 Subject: [PATCH 09/11] wrap rest template code in configuration class --- ...how-to-create-client-from-open-api-json.md | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/src/guides/how-to-create-client-from-open-api-json.md b/docs/src/guides/how-to-create-client-from-open-api-json.md index e9ccb177d..17ccf9fc2 100644 --- a/docs/src/guides/how-to-create-client-from-open-api-json.md +++ b/docs/src/guides/how-to-create-client-from-open-api-json.md @@ -118,29 +118,34 @@ Damit der generierte Client verwendet werden kann, muss dem Spring-Context noch ```java -@Bean -public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { - val restTemplate = new RestTemplate(); - - /* definieren des Errorhandlers für Antworten vom externen Service */ - restTemplate.setErrorHandler(wlsResponseErrorHandler); - /* Ergänzen eines Interceptors um den Bearer-Token an den nächsten Service weiter zu geben */ - restTemplate.getInterceptors().add((request, body, execution) -> { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (authentication == null) { - return execution.execute(request, body); - } - - if (!(authentication.getCredentials() instanceof AbstractOAuth2Token)) { +@Configuration +public class ClientConfiguration { + + @Bean + public RestTemplate restTemplate(final WlsResponseErrorHandler wlsResponseErrorHandler) { + val restTemplate = new RestTemplate(); + + /* definieren des Errorhandlers für Antworten vom externen Service */ + restTemplate.setErrorHandler(wlsResponseErrorHandler); + /* Ergänzen eines Interceptors um den Bearer-Token an den nächsten Service weiter zu geben */ + restTemplate.getInterceptors().add((request, body, execution) -> { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null) { + return execution.execute(request, body); + } + + if (!(authentication.getCredentials() instanceof AbstractOAuth2Token)) { + return execution.execute(request, body); + } + + val token = (AbstractOAuth2Token) authentication.getCredentials(); + request.getHeaders().setBearerAuth(token.getTokenValue()); return execution.execute(request, body); - } + }); - val token = (AbstractOAuth2Token) authentication.getCredentials(); - request.getHeaders().setBearerAuth(token.getTokenValue()); - return execution.execute(request, body); - }); + return restTemplate; + } - return restTemplate; } ``` From 6c9f541e92acc987931eb7adcc61877e4b18767d Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:24:50 +0200 Subject: [PATCH 10/11] wrap wslResponseErrorHandler code in configuration class --- .../how-to-create-client-from-open-api-json.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/src/guides/how-to-create-client-from-open-api-json.md b/docs/src/guides/how-to-create-client-from-open-api-json.md index 17ccf9fc2..67a245b46 100644 --- a/docs/src/guides/how-to-create-client-from-open-api-json.md +++ b/docs/src/guides/how-to-create-client-from-open-api-json.md @@ -153,10 +153,16 @@ Wie zu erkennen ist, wird für das RestTemplate ein ErrorHandler benötigt, wobe aus `wls-common:exception` verwenden. Eine entsprechende Bean muss ebenfalls noch dem Spring-Context hinzugefügt werden: ```java +@Configuration +public class ClientConfiguration { + + //other configurations like the restTemplate bean factory method -@Bean -public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { - return new WlsResponseErrorHandler(objectMapper); + @Bean + public WlsResponseErrorHandler wlsResponseErrorHandler(final ObjectMapper objectMapper) { + return new WlsResponseErrorHandler(objectMapper); + } + } ``` From 0fb04b642cee5a2b9467b67ed0fddb74d25f59b4 Mon Sep 17 00:00:00 2001 From: MrSebastian <13592751+MrSebastian@users.noreply.github.com> Date: Mon, 1 Jul 2024 12:26:28 +0200 Subject: [PATCH 11/11] add hint that error will occur --- wls-basisdaten-service/src/test/resources/demo.http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wls-basisdaten-service/src/test/resources/demo.http b/wls-basisdaten-service/src/test/resources/demo.http index 0c014406f..ebca281b3 100644 --- a/wls-basisdaten-service/src/test/resources/demo.http +++ b/wls-basisdaten-service/src/test/resources/demo.http @@ -17,6 +17,6 @@ username = wls_all GET http://kubernetes.docker.internal:8100/auth/realms/wls_realm/protocol/openid-connect/userinfo Authorization: {{ token_type }} {{ auth_token }} -### Demo für client zu EAI +### Demo für client zu EAI - will result in 500 als long as eai is not implemented (not implemented yet) GET http://localhost:39151/demo Authorization: {{ token_type }} {{ auth_token }} \ No newline at end of file