Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • fit-connect/sdk-java
1 result
Show changes
Commits on Source (10)
Showing
with 79 additions and 417 deletions
......@@ -47,7 +47,6 @@ See the projects' module documentation for more specific information:
* [API Module ](api/README.md)
* [Core Module ](core/README.md)
* [Client Module ](client/README.md)
* [Open-API Module ](open-api/README.md)
### Setup
......@@ -61,7 +60,7 @@ _The following steps show how to get the SDK running_
```
4. Build the project
```sh
mvn clean install
mvn clean install -DskipTests
```
5. Enter your API keys and references to your private decryption key in `config.yml`
......
......@@ -3,6 +3,8 @@ package de.fitko.fitconnect.api.domain.model.jwk;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
public enum AlgEnum {
PS512("PS512"),
......@@ -27,11 +29,9 @@ public enum AlgEnum {
@JsonCreator
public static AlgEnum fromValue(final String value) {
for (final AlgEnum algEnum : AlgEnum.values()) {
if (algEnum.value.equals(value)) {
return algEnum;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
return Arrays.stream(AlgEnum.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,6 +3,8 @@ package de.fitko.fitconnect.api.domain.model.jwk;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
public enum EEnum {
AQAB("AQAB");
......@@ -25,11 +27,9 @@ public enum EEnum {
@JsonCreator
public static EEnum fromValue(final String value) {
for (final EEnum eEnum : EEnum.values()) {
if (eEnum.value.equals(value)) {
return eEnum;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
return Arrays.stream(EEnum.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,6 +3,8 @@ package de.fitko.fitconnect.api.domain.model.jwk;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
public enum KeyOpsEnum {
VERIFY("verify"),
......@@ -27,11 +29,9 @@ public enum KeyOpsEnum {
@JsonCreator
public static KeyOpsEnum fromValue(final String value) {
for (final KeyOpsEnum keyOpsEnum : KeyOpsEnum.values()) {
if (keyOpsEnum.value.equals(value)) {
return keyOpsEnum;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
return Arrays.stream(KeyOpsEnum.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,6 +3,8 @@ package de.fitko.fitconnect.api.domain.model.jwk;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.Arrays;
public enum KtyEnum {
RSA("RSA");
......@@ -25,11 +27,9 @@ public enum KtyEnum {
@JsonCreator
public static KtyEnum fromValue(final String value) {
for (final KtyEnum ktyEnum : KtyEnum.values()) {
if (ktyEnum.value.equals(value)) {
return ktyEnum;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
return Arrays.stream(KtyEnum.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,8 +3,7 @@ package de.fitko.fitconnect.api.domain.model.metadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum EidasAdesProfile {
......@@ -14,13 +13,6 @@ public enum EidasAdesProfile {
HTTP_URI_ETSI_ORG_ADES_191_X_2_LEVEL_BASELINE_B_LTA("http://uri.etsi.org/ades/191x2/level/baseline/B-LTA#");
private final String value;
private final static Map<String, EidasAdesProfile> CONSTANTS = new HashMap<>();
static {
for (final EidasAdesProfile c : values()) {
CONSTANTS.put(c.value, c);
}
}
EidasAdesProfile(final String value) {
this.value = value;
......@@ -38,12 +30,10 @@ public enum EidasAdesProfile {
@JsonCreator
public static EidasAdesProfile fromValue(final String value) {
final EidasAdesProfile constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
return Arrays.stream(EidasAdesProfile.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,8 +3,7 @@ package de.fitko.fitconnect.api.domain.model.metadata;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum SignatureFormat {
......@@ -13,14 +12,8 @@ public enum SignatureFormat {
PDF("pdf"),
ASIC("asic"),
JSON("json");
private final String value;
private final static Map<String, SignatureFormat> CONSTANTS = new HashMap<>();
static {
for (final SignatureFormat c : values()) {
CONSTANTS.put(c.value, c);
}
}
private final String value;
SignatureFormat(final String value) {
this.value = value;
......@@ -38,12 +31,10 @@ public enum SignatureFormat {
@JsonCreator
public static SignatureFormat fromValue(final String value) {
final SignatureFormat constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
return Arrays.stream(SignatureFormat.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
\ No newline at end of file
......@@ -3,8 +3,7 @@ package de.fitko.fitconnect.api.domain.model.metadata.attachment;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum Purpose {
......@@ -12,15 +11,8 @@ public enum Purpose {
ATTACHMENT("attachment"),
REPORT("report");
private final String value;
private final static Map<String, Purpose> CONSTANTS = new HashMap<>();
static {
for (Purpose c : values()) {
CONSTANTS.put(c.value, c);
}
}
Purpose(String value) {
Purpose(final String value) {
this.value = value;
}
......@@ -35,12 +27,10 @@ public enum Purpose {
}
@JsonCreator
public static Purpose fromValue(String value) {
Purpose constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
public static Purpose fromValue(final String value) {
return Arrays.stream(Purpose.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,20 +3,12 @@ package de.fitko.fitconnect.api.domain.model.metadata.attachment.signature;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum AttachmentSignatureType {
SHA_512("sha512");
private final String value;
private final static Map<String, AttachmentSignatureType> CONSTANTS = new HashMap<>();
static {
for (final AttachmentSignatureType c : values()) {
CONSTANTS.put(c.value, c);
}
}
AttachmentSignatureType(final String value) {
this.value = value;
......@@ -34,12 +26,10 @@ public enum AttachmentSignatureType {
@JsonCreator
public static AttachmentSignatureType fromValue(final String value) {
final AttachmentSignatureType constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
return Arrays.stream(AttachmentSignatureType.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,20 +3,12 @@ package de.fitko.fitconnect.api.domain.model.metadata.data;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum DataSignatureType {
SHA_512("sha512");
private final String value;
private final static Map<String, DataSignatureType> CONSTANTS = new HashMap<>();
static {
for (final DataSignatureType c : values()) {
CONSTANTS.put(c.value, c);
}
}
DataSignatureType(final String value) {
this.value = value;
......@@ -34,12 +26,10 @@ public enum DataSignatureType {
@JsonCreator
public static DataSignatureType fromValue(final String value) {
final DataSignatureType constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
return Arrays.stream(DataSignatureType.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
......@@ -3,21 +3,14 @@ package de.fitko.fitconnect.api.domain.model.metadata.data;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
public enum MimeType {
APPLICATION_JSON("application/json"),
APPLICATION_XML("application/xml");
private final String value;
private final static Map<String, MimeType> CONSTANTS = new HashMap<>();
static {
for (final MimeType c : values()) {
CONSTANTS.put(c.value, c);
}
}
private final String value;
MimeType(final String value) {
this.value = value;
......@@ -35,11 +28,9 @@ public enum MimeType {
@JsonCreator
public static MimeType fromValue(final String value) {
final MimeType constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
return Arrays.stream(MimeType.values())
.filter(enumValue -> enumValue.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'"));
}
}
### OpenAPI Model Generation
This module generates model classes from the open-api specification of the submission api.
Usage: ``mvn compile exec:java`` generates all models into the package ``de.fitko.fitconnect.api.domain.model.submission`` under
**target/generated-sources/openapi/gen**.
### Config
The relevant config parameters are listed below.
````xml
<configuration>
<!-- open api spec url -->
<inputSpec>${submission-api.baseurl}/${submission-api.version}/${submission-api.spec}</inputSpec>
<!-- language generator -->
<generatorName>java</generatorName>
<!-- validation is currently disabled, otherwise the generation fails due to duplicate entries -->
<skipValidateSpec>true</skipValidateSpec>
<!-- use jackson annotations -->
<library>resttemplate</library>
<!-- target package name -->
<modelPackage>de.fitko.fitconnect.api.domain.model.submission</modelPackage>
<!-- target folder to write files into -->
<configOptions>
<sourceFolder>../../../src/main/java</sourceFolder>
</configOptions>
</configuration>
````
### Draft/Todo PostProcessing
The ``de.fitko.fitconnect.api.postprocessing.ModelClassPostProcessor`` is running in a maven execute step and
replaces all comments and unwanted annotations.
Currently, there are some @Nullable and @NonNull annotations from ```javax.annotations``` that need to be replaced.
In a further step the cleaned and post-processed model classes can be updated in the original ``api/domain/model``
package of the ``api`` module via the maven resource plugin.
<?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">
<parent>
<artifactId>sdk-java</artifactId>
<groupId>de.fitko.fitconnect.sdk</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>open-api</artifactId>
<packaging>jar</packaging>
<properties>
<submission-api.baseurl>https://schema.fitko.de/fit-connect/submission-api</submission-api.baseurl>
<submission-api.version>1.0.7</submission-api.version>
<submission-api.spec>submission-api.yaml</submission-api.spec>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${submission-api.baseurl}/${submission-api.version}/${submission-api.spec}
</inputSpec>
<generatorName>java</generatorName>
<generateApis>false</generateApis>
<skipValidateSpec>true</skipValidateSpec>
<generateApis>false</generateApis>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<library>resttemplate</library>
<modelPackage>de.fitko.fitconnect.api.domain.model.submission</modelPackage>
<configOptions>
<sourceFolder>gen</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>de.fitko.fitconnect.api.postprocessing.ModelClassPostProcessor</mainClass>
<workingDirectory>postprocessing</workingDirectory>
<arguments>
<argument>target/generated-sources/openapi/gen/de/fitko/fitconnect/api/domain/model/submission
</argument>
</arguments>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resource-one</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/../api/src/main/java/de/fitko/fitconnect/api/domain/generated
</outputDirectory>
<resources>
<resource>
<directory>
target/generated-sources/openapi/gen/de/fitko/fitconnect/api/domain/model/submission
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
\ No newline at end of file
package de.fitko.fitconnect.api.postprocessing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ModelClassPostProcessor {
private static final Logger logger = LoggerFactory.getLogger(ModelClassPostProcessor.class);
public static void main(final String[] args) {
final ModelClassPostProcessor postProcessor = new ModelClassPostProcessor();
final var dir = args[0]; // -modelPath
postProcessor.readModelsToStrings(dir)
.stream()
.map(ModelClassPostProcessor::replaceContent)
//.peek(pair -> logger.info(pair.content))
.forEach(ModelClassPostProcessor::writeFiles);
}
private static ModelPair replaceContent(final ModelPair pair) {
String content = pair.content;
// Remove all Comments
content = content.replaceAll("\\/\\*([\\S\\s]+?)\\*\\/", "");
content = content.replaceAll("(?s)/\\*.*?\\*/", "");
// Remove unwanted annos
content = content.replaceAll("@ApiModel([\\w]+)((.*))", "");
content = content.replaceAll("@ApiModelProperty([\\w]+)((.*))", "");
content = content.replaceAll("Generated([\\w]+)((.*))", "");
// Replace javax
//content = content.replaceAll("Nonnull([\\w]+)((.*))", "");
//content = content.replaceAll("(@\([\\w]+)\\((.*?)\\)(?:\s|$))", "");
return new ModelPair(pair.originalPath, content);
}
public Set<ModelPair> readModelsToStrings(final String dir) {
return Stream.of(new File(dir).listFiles())
.filter(file -> !file.isDirectory())
.peek(file -> logger.info("Postprocessing model {}", file.getName()))
.map(file -> new ModelPair(file.toPath(), getFileAsString(file)))
.collect(Collectors.toSet());
}
private String getFileAsString(final File file) {
try {
return Files.readString(file.toPath(), StandardCharsets.UTF_8);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
private static void writeFiles(final ModelPair modelPair) {
try {
final File f = new File(modelPair.originalPath.toFile().getAbsolutePath());
final FileWriter fw = new FileWriter( f, false);
fw.write(modelPair.content);
fw.flush();
fw.close();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
private static class ModelPair {
final Path originalPath;
final String content;
ModelPair(final Path originalPath, final String content) {
this.originalPath = originalPath;
this.content = content;
}
@Override
public String toString() {
return content;
}
}
}
......@@ -11,8 +11,7 @@
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>${java.version}</maven.compiler.release>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
......@@ -47,7 +46,6 @@
<module>api</module>
<module>core</module>
<module>client</module>
<module>open-api</module>
</modules>
<dependencyManagement>
......@@ -137,13 +135,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
......@@ -173,28 +164,25 @@
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file