Skip to content

Commit cf70002

Browse files
committed
Add api module
1 parent f1716c9 commit cf70002

File tree

9 files changed

+890
-2
lines changed

9 files changed

+890
-2
lines changed

gbfs-validator-java-api/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/

gbfs-validator-java-api/pom.xml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.4.3</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>org.entur.gbfs</groupId>
12+
<artifactId>gbfs-validator-java-api</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>gbfs-validator-java-api</name>
15+
<description>gbfs-validator-java-api</description>
16+
<url/>
17+
<licenses>
18+
<license/>
19+
</licenses>
20+
<developers>
21+
<developer/>
22+
</developers>
23+
<scm>
24+
<connection/>
25+
<developerConnection/>
26+
<tag/>
27+
<url/>
28+
</scm>
29+
<properties>
30+
<java.version>17</java.version>
31+
<openapi-generator-maven-plugin>6.0.0</openapi-generator-maven-plugin>
32+
</properties>
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-validation</artifactId>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>io.swagger.core.v3</groupId>
46+
<artifactId>swagger-annotations</artifactId>
47+
<version>2.2.28</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>javax.validation</groupId>
52+
<artifactId>validation-api</artifactId>
53+
<version>2.0.1.Final</version>
54+
</dependency>
55+
56+
<!-- https://mvnrepository.com/artifact/jakarta.annotation/jakarta.annotation-api -->
57+
<dependency>
58+
<groupId>jakarta.annotation</groupId>
59+
<artifactId>jakarta.annotation-api</artifactId>
60+
<version>3.0.0</version>
61+
</dependency>
62+
<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
63+
<dependency>
64+
<groupId>javax.annotation</groupId>
65+
<artifactId>javax.annotation-api</artifactId>
66+
<version>1.3.2</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>javax.servlet</groupId>
71+
<artifactId>servlet-api</artifactId>
72+
<version>2.5</version>
73+
<scope>provided</scope>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>org.springdoc</groupId>
78+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
79+
<version>2.6.0</version>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.openapitools</groupId>
84+
<artifactId>jackson-databind-nullable</artifactId>
85+
<version>0.2.6</version>
86+
</dependency>
87+
88+
<dependency>
89+
<groupId>org.entur.gbfs</groupId>
90+
<artifactId>gbfs-validator-java-loader</artifactId>
91+
<version>0-SNAPSHOT</version>
92+
</dependency>
93+
94+
<dependency>
95+
<groupId>org.entur.gbfs</groupId>
96+
<artifactId>gbfs-validator-java</artifactId>
97+
<version>2.0.30-SNAPSHOT</version>
98+
</dependency>
99+
100+
<dependency>
101+
<groupId>org.springframework.boot</groupId>
102+
<artifactId>spring-boot-starter-test</artifactId>
103+
<scope>test</scope>
104+
</dependency>
105+
106+
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
107+
<dependency>
108+
<groupId>org.junit.jupiter</groupId>
109+
<artifactId>junit-jupiter-api</artifactId>
110+
<version>5.9.2</version>
111+
<scope>test</scope>
112+
</dependency>
113+
</dependencies>
114+
115+
<build>
116+
<plugins>
117+
<plugin>
118+
<groupId>org.springframework.boot</groupId>
119+
<artifactId>spring-boot-maven-plugin</artifactId>
120+
</plugin>
121+
<plugin>
122+
<groupId>org.openapitools</groupId>
123+
<artifactId>openapi-generator-maven-plugin</artifactId>
124+
<version>${openapi-generator-maven-plugin}</version>
125+
<executions>
126+
<execution>
127+
<goals>
128+
<goal>generate</goal>
129+
</goals>
130+
<configuration>
131+
<inputSpec>${project.basedir}/src/main/resources/public/openapi.yaml</inputSpec>
132+
<generatorName>spring</generatorName>
133+
<output>${project.build.directory}/generated-sources/openapi</output>
134+
<apiPackage>org.entur.gbfs.validator.api.gen</apiPackage>
135+
<modelPackage>org.entur.gbfs.validator.api.model</modelPackage>
136+
<invokerPackage>org.entur.gbfs.validator.api.handler</invokerPackage>
137+
<configOptions>
138+
<delegatePattern>true</delegatePattern>
139+
<interfaceOnly>false</interfaceOnly>
140+
<skipDefaultInterface>false</skipDefaultInterface>
141+
<dateLibrary>java8</dateLibrary>
142+
<useOneOfInterfaces>false</useOneOfInterfaces>
143+
<useOneOfDiscriminatorLookup>true</useOneOfDiscriminatorLookup>
144+
<!-- <useEnumForDiscriminator>true</useEnumForDiscriminator>-->
145+
<!-- <useOneOfInterfaces>true</useOneOfInterfaces>-->
146+
</configOptions>
147+
<typeMappings>
148+
<typeMapping>Double=java.math.BigDecimal</typeMapping>
149+
</typeMappings>
150+
<!-- <library>spring-boot</library>-->
151+
</configuration>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
</plugins>
156+
</build>
157+
158+
</project>
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
*
3+
* *
4+
* *
5+
* * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
6+
* * * the European Commission - subsequent versions of the EUPL (the "Licence");
7+
* * * You may not use this work except in compliance with the Licence.
8+
* * * You may obtain a copy of the Licence at:
9+
* * *
10+
* * * https://joinup.ec.europa.eu/software/page/eupl
11+
* * *
12+
* * * Unless required by applicable law or agreed to in writing, software
13+
* * * distributed under the Licence is distributed on an "AS IS" basis,
14+
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * * See the Licence for the specific language governing permissions and
16+
* * * limitations under the Licence.
17+
* *
18+
*
19+
*/
20+
21+
package org.entur.gbfs.validator.api.handler;
22+
23+
import org.entur.gbfs.validation.GbfsValidator;
24+
import org.entur.gbfs.validation.GbfsValidatorFactory;
25+
import org.entur.gbfs.validation.model.FileValidationError;
26+
import org.entur.gbfs.validation.model.FileValidationResult;
27+
import org.entur.gbfs.validation.model.ValidationResult;
28+
import org.entur.gbfs.validator.api.gen.ValidateOption1ApiDelegate;
29+
import org.entur.gbfs.validator.api.model.FileError;
30+
import org.entur.gbfs.validator.api.model.FileLangOption1;
31+
import org.entur.gbfs.validator.api.model.FileOption1;
32+
import org.entur.gbfs.validator.api.model.ValidateOption1PostRequest;
33+
import org.entur.gbfs.validator.api.model.ValidationResultOption1;
34+
import org.entur.gbfs.validator.api.model.ValidationResultOption1Summary;
35+
import org.entur.gbfs.validator.api.model.ValidationResultOption1SummaryFilesInner;
36+
import org.entur.gbfs.validator.loader.Loader;
37+
import org.springframework.http.ResponseEntity;
38+
import org.springframework.stereotype.Service;
39+
40+
import java.io.IOException;
41+
import java.io.InputStream;
42+
import java.util.ArrayList;
43+
import java.util.List;
44+
import java.util.Map;
45+
46+
@Service
47+
public class ValidateApiDelegateHandler implements ValidateOption1ApiDelegate {
48+
49+
@Override
50+
public ResponseEntity<ValidationResultOption1> validateOption1Post(ValidateOption1PostRequest validateOption1PostRequest) {
51+
Loader loader = new Loader();
52+
Map<String, InputStream> fileMap = null;
53+
try {
54+
fileMap = loader.load(validateOption1PostRequest.getFeedUrl());
55+
} catch (IOException e) {
56+
throw new RuntimeException(e);
57+
}
58+
GbfsValidator validator = GbfsValidatorFactory.getGbfsJsonValidator();
59+
return ResponseEntity.ok(
60+
mapValidationResult(validator.validate(fileMap))
61+
);
62+
}
63+
64+
private ValidationResultOption1 mapValidationResult(ValidationResult validationResult) {
65+
ValidationResultOption1Summary validationResultOption1Summary = new ValidationResultOption1Summary();
66+
validationResultOption1Summary.setValidatorVersion("2.0.30-SNAPSHOT"); // TODO inject this value
67+
validationResultOption1Summary.setGbfsVersion(validationResult.summary().version());
68+
validationResultOption1Summary.setFiles(mapFiles(validationResult.files()));
69+
ValidationResultOption1 validationResultOption1 = new ValidationResultOption1();
70+
validationResultOption1.setSummary(validationResultOption1Summary);
71+
return validationResultOption1;
72+
}
73+
74+
private List<ValidationResultOption1SummaryFilesInner> mapFiles(Map<String, FileValidationResult> files) {
75+
List<ValidationResultOption1SummaryFilesInner> summaryFiles = new ArrayList<>();
76+
files.entrySet().stream().forEach(entry -> {
77+
String fileName = entry.getKey();
78+
FileValidationResult fileValidationResult = entry.getValue();
79+
80+
FileLangOption1 filesInner = new FileLangOption1();
81+
filesInner.setName(fileName);
82+
filesInner.setExists(fileValidationResult.exists());
83+
filesInner.setRequired(fileValidationResult.required());
84+
//filesInner.setRecommended(); // TODO not available
85+
filesInner.setSchema(fileValidationResult.schema());
86+
filesInner.setVersion(fileValidationResult.version());
87+
88+
FileOption1 file = new FileOption1();
89+
file.exists(fileValidationResult.exists());
90+
file.errors(
91+
mapFileErrors(fileValidationResult.errors())
92+
);
93+
file.fileContent(fileValidationResult.fileContents());
94+
95+
96+
filesInner.setFiles(
97+
List.of(file)
98+
);
99+
summaryFiles.add(filesInner);
100+
});
101+
return summaryFiles;
102+
}
103+
104+
private List<FileError> mapFileErrors(List<FileValidationError> errors) {
105+
return errors.stream().map(error -> {
106+
var mapped = new FileError();
107+
mapped.setMessage(error.message());
108+
mapped.setInstancePath(error.violationPath());
109+
mapped.setSchemaPath(error.schemaPath());
110+
//mapped.setParams(error.); // TODO no source?
111+
//mapped.setKeyword(error.); // TODO no source?
112+
return mapped;
113+
}).toList();
114+
}
115+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.application.name=gbfs-validator-java-api

0 commit comments

Comments
 (0)