Skip to content

Commit

Permalink
Merge pull request #278 from it-at-m/151-erstellung-api
Browse files Browse the repository at this point in the history
151 erstellung api
  • Loading branch information
MrSebastian committed Jun 13, 2024
2 parents bc07764 + 399a709 commit 74d9b7f
Show file tree
Hide file tree
Showing 54 changed files with 894 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/callable-create-github-release-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
required: true
type: string
description: 'name of service to use'
files:
required: true
type: string
description: 'Newline-delimited globs of paths to assets to upload for release'

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -41,8 +45,7 @@ jobs:
id: create_release
uses: softprops/action-gh-release@v2
with:
files: |
${{ inputs.service }}/target/*.jar
files: ${{ inputs.files }}
tag_name: ${{ inputs.tag }}
draft: false
prerelease: false
Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/dispatch-eai-microservice-mvn-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: dispatch eai microserivce maven release

on:
workflow_dispatch:
inputs:
release-version:
required: true
description: release version to build
development-version:
required: true
description: next development version to set
service:
required: true
description: service/directory to build (wls-broadcast-service, ...)

jobs:
run-mvn-release-prepare:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Setup git user
uses: fregante/setup-git-user@v2
- name: Install Java and Maven
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"
cache: 'maven'
cache-dependency-path: '${{ github.event.inputs.service }}/pom.xml'
- name: Perform maven release
run: >
mvn -B -ntp release:prepare -f ${{ github.event.inputs.service }}/pom.xml
-DreleaseVersion=${{ github.event.inputs.release-version }}
-DdevelopmentVersion=${{ github.event.inputs.development-version }}
-Dtag=${{ github.event.inputs.service }}/${{ github.event.inputs.release-version }}
-Darguments="-DskipTests"
build-github-release:
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- run-mvn-release-prepare
steps:
- name: Check out Git repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.service }}/${{ github.event.inputs.release-version }}

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
cache: 'maven'
cache-dependency-path: '${{ github.event.inputs.service }}/pom.xml'
java-version: '17'
distribution: 'temurin'

- name: build jar without tests
run: mvn -B -ntp -DskipTests verify -f ${{ github.event.inputs.service }}/pom.xml

- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
files: "${{ github.event.inputs.service }}/target/*.jar\n${{ github.event.inputs.service }}/target/openapi.json"
tag_name: ${{ github.event.inputs.service }}/${{ github.event.inputs.release-version }}
draft: false
prerelease: false
generate_release_notes: false

build-github-container-image:
permissions:
packages: write
needs:
- run-mvn-release-prepare
uses:
./.github/workflows/callable-create-github-container-image.yml
with:
tag: ${{ github.event.inputs.service }}/${{ github.event.inputs.release-version }}
service: ${{ github.event.inputs.service }}
1 change: 1 addition & 0 deletions .github/workflows/dispatch-microservice-mvn-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
with:
tag: ${{ github.event.inputs.service }}/${{ github.event.inputs.release-version }}
service: ${{ github.event.inputs.service }}
files: ${{ inputs.service }}/target/*.jar

build-github-container-image:
permissions:
Expand Down
47 changes: 42 additions & 5 deletions wls-eai-service/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.muenchen.oss.wahllokalsystem</groupId>
Expand Down Expand Up @@ -105,6 +103,13 @@
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>

<!-- wls-common -->
<dependency>
<groupId>de.muenchen.oss.wahllokalsystem.wls-common</groupId>
<artifactId>exception</artifactId>
<version>1.0.0</version>
</dependency>

<!-- json etc. -->
<dependency>
<groupId>org.springframework.hateoas</groupId>
Expand Down Expand Up @@ -301,6 +306,18 @@
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -372,6 +389,26 @@
</executions>
</plugin>

<!-- openapi doc -->
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
<outputFileName>openapi.json</outputFileName>
<outputDir>${project.build.directory}</outputDir>
</configuration>
</plugin>

<!-- Codeformatter Spotless -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
Expand All @@ -393,8 +430,8 @@
<eclipse>
<file>itm-java-codeformat/java_codestyle_formatter.xml</file>
</eclipse>
<trimTrailingWhitespace/>
<endWithNewline/>
<trimTrailingWhitespace />
<endWithNewline />
</java>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.configuration;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import de.muenchen.oss.wahllokalsystem.wls.common.exception.rest.model.WlsExceptionDTO;
import io.swagger.v3.core.util.AnnotationsUtils;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -40,4 +49,48 @@ OpenAPI customOpenAPI() {
.scheme("bearer")
.bearerFormat("JWT")));
}

@Bean
public GlobalOpenApiCustomizer errorCustomizer() {
return api -> api.getPaths().values().forEach(path -> path.readOperations()
.forEach(operation -> addErrorToApi(operation, api.getComponents())));
}

// add response based on the behavior of the global exception handler
private void addErrorToApi(Operation operation, Components components) {
if (operation.getResponses() != null) {
addRequestBodyValidationErrorToAPI(operation, components);
}
addNotFoundErrorToAPI(operation, components);
addInternalErrorToAPI(operation, components);
addUnhandledCommunicationErrorToAPI(operation, components);
}

private void addRequestBodyValidationErrorToAPI(Operation operation, Components components) {
operation.getResponses().addApiResponse("400", new ApiResponse()
.description("request body validation failed")
.content(new Content().addMediaType(APPLICATION_JSON_VALUE, createWlsExceptionDTOMediaType(components))));
}

private void addNotFoundErrorToAPI(Operation operation, Components components) {
operation.getResponses().addApiResponse("404", new ApiResponse()
.description("no resource found")
.content(new Content().addMediaType(APPLICATION_JSON_VALUE, createWlsExceptionDTOMediaType(components))));
}

private void addInternalErrorToAPI(Operation operation, Components components) {
operation.getResponses().addApiResponse("500", new ApiResponse()
.description("unhandled internal error")
.content(new Content().addMediaType(APPLICATION_JSON_VALUE, createWlsExceptionDTOMediaType(components))));
}

private void addUnhandledCommunicationErrorToAPI(Operation operation, Components components) {
operation.getResponses().addApiResponse("500", new ApiResponse()
.description("unhandled error during communication with other system")
.content(new Content().addMediaType(APPLICATION_JSON_VALUE, createWlsExceptionDTOMediaType(components))));
}

private MediaType createWlsExceptionDTOMediaType(final Components components) {
return new MediaType().schema(AnnotationsUtils.resolveSchemaFromType(WlsExceptionDTO.class, components, null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.dto;

public enum WahlartDTO {
BAW, BEB, BTW, BZW, EUW, LTW, MBW, OBW, SRW, SVW, VE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception;

public class ExceptionConstants {

public static final String CODE_DATENALLGEMEIN_ID_NICHT_KONVERTIERBAR = "103";

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

public static final String CODE_DATENALLGEMEIN_PARAMETER_FEHLEN = "102";
public static final String MESSAGE_DATENALLGEMEIN_PARAMETER_FEHLEN = "Anfrage ist ungueltig da notwendige Anfragedaten fehlen";

/**
* @throws IllegalAccessException when constructor is used
*/
private ExceptionConstants() throws IllegalAccessException {
throw new IllegalAccessException("dont create instanced - it is just a holder for constants");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception;

import jakarta.validation.constraints.NotNull;

public record ExceptionDataWrapper(@NotNull String code, @NotNull String message) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung;

import de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto.WahlbeteiligungsMeldungDTO;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wahlbeteiligung")
public class WahlbeteiligungController {

@PostMapping
@ResponseStatus(HttpStatus.OK)
public void saveWahlbeteiligung(@Valid @RequestBody WahlbeteiligungsMeldungDTO wahlbeteiligung) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;

public record WahlbeteiligungsMeldungDTO(@NotNull String wahlID,
@NotNull String wahlbezirkID,
@Schema(requiredMode = Schema.RequiredMode.REQUIRED) long anzahlWaehler,
@NotNull LocalDateTime meldeZeitpunkt) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.muenchen.oss.wahllokalsystem.eaiservice.rest.wahlbeteiligung.exception;

import de.muenchen.oss.wahllokalsystem.eaiservice.rest.common.exception.ExceptionDataWrapper;

public class ExceptionConstants {

public static final String CODE_SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT = "001";
public static final String MESSAGE_SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT = "Die WahlbezirkID fehlt";
public static final ExceptionDataWrapper SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT = new ExceptionDataWrapper(CODE_SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT,
MESSAGE_SAVEWAHLBETEILIGUNG_WAHLBEZIRKID_FEHLT);

public static final String CODE_SAVEWAHLBETEILIGUNG_WAHLID_FEHLT = "002";
public static final String MESSAGE_SAVEWAHLBETEILIGUNG_WAHLID_FEHLT = "Die WahlID fehlt";
public static final ExceptionDataWrapper SAVEWAHLBETEILIGUNG_WAHLID_FEHLT = new ExceptionDataWrapper(CODE_SAVEWAHLBETEILIGUNG_WAHLID_FEHLT,
MESSAGE_SAVEWAHLBETEILIGUNG_WAHLID_FEHLT);

public static final String CODE_SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT = "003";
public static final String MESSAGE_SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT = "Der Meldezeitpunkt fehlt";
public static final ExceptionDataWrapper SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT = new ExceptionDataWrapper(CODE_SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT,
MESSAGE_SAVEWAHLBETEILIGUNG_MELDEZEITPUNKT_FEHLT);

/**
* @throws IllegalAccessException when constructor is used
*/
private ExceptionConstants() throws IllegalAccessException {
throw new IllegalAccessException("dont create instanced - it is just a holder for constants");
}
}
Loading

0 comments on commit 74d9b7f

Please sign in to comment.