• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kit-data-manager / pit-service / #450

22 Jan 2025 05:09PM UTC coverage: 75.383% (+3.0%) from 72.4%
#450

Pull #218

github

web-flow
Merge 85e1ddf30 into 459f0c036
Pull Request #218: Type-Api support and validation speedup

257 of 322 new or added lines in 18 files covered. (79.81%)

3 existing lines in 2 files now uncovered.

885 of 1174 relevant lines covered (75.38%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.61
/src/main/java/edu/kit/datamanager/pit/typeregistry/schema/TypeApiSchemaGenerator.java
1
package edu.kit.datamanager.pit.typeregistry.schema;
2

3
import edu.kit.datamanager.pit.common.ExternalServiceException;
4
import edu.kit.datamanager.pit.common.InvalidConfigException;
5
import edu.kit.datamanager.pit.common.TypeNotFoundException;
6
import edu.kit.datamanager.pit.configuration.ApplicationProperties;
7
import jakarta.validation.constraints.NotNull;
8
import org.everit.json.schema.Schema;
9
import org.everit.json.schema.loader.SchemaLoader;
10
import org.json.JSONException;
11
import org.json.JSONObject;
12
import org.json.JSONTokener;
13
import org.springframework.http.HttpStatusCode;
14
import org.springframework.web.client.RestClient;
15

16
import java.io.InputStream;
17
import java.net.URISyntaxException;
18
import java.net.URL;
19

20
public class TypeApiSchemaGenerator implements SchemaGenerator {
21

22
    protected final URL baseUrl;
23
    protected final RestClient http;
24

25
    public TypeApiSchemaGenerator(@NotNull ApplicationProperties props) {
1✔
26
        this.baseUrl = props.getTypeRegistryUri();
1✔
27
        String baseUri;
28
        try {
29
            baseUri = baseUrl.toURI().resolve("v1/types").toString();
1✔
NEW
30
        } catch (URISyntaxException e) {
×
NEW
31
            throw new InvalidConfigException("Type-Api base url not valid: " + baseUrl, e);
×
32
        }
1✔
33
        this.http = RestClient.builder().baseUrl(baseUri).build();
1✔
34
    }
1✔
35

36
    @Override
37
    public SchemaInfo generateSchema(@NotNull String maybeTypePid) {
38
        return http.get()
1✔
39
                .uri(uriBuilder -> uriBuilder
1✔
40
                        .pathSegment("schema")
1✔
41
                        .path(maybeTypePid)
1✔
42
                        .build())
1✔
43
                .exchange((request, response) -> {
1✔
44
                    HttpStatusCode statusCode = response.getStatusCode();
1✔
45
                    if (statusCode.is2xxSuccessful()) {
1✔
46
                        Schema schema = null;
1✔
47
                        try (InputStream inputStream = response.getBody()) {
1✔
48
                            JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
1✔
49
                            schema = SchemaLoader.load(rawSchema);
1✔
NEW
50
                        } catch (JSONException e) {
×
NEW
51
                            return new SchemaInfo(
×
NEW
52
                                    this.baseUrl.toString(),
×
53
                                    schema,
NEW
54
                                    new ExternalServiceException(baseUrl.toString(), "Response (" + maybeTypePid + ") is not a valid schema.")
×
55
                            );
56
                        }
1✔
57
                        return new SchemaInfo(this.baseUrl.toString(), schema, null);
1✔
NEW
58
                    } else if (statusCode.value() == 404) {
×
NEW
59
                        return new SchemaInfo(
×
NEW
60
                                this.baseUrl.toString(),
×
61
                                null,
62
                                new TypeNotFoundException(maybeTypePid));
63
                    } else {
NEW
64
                        return new SchemaInfo(
×
NEW
65
                                this.baseUrl.toString(),
×
66
                                null,
67
                                new ExternalServiceException(
NEW
68
                                        this.baseUrl.toString(),
×
NEW
69
                                        "Error generating schema: %s - %s".formatted(statusCode.value(), response.getStatusText())));
×
70
                    }
71
                });
72
    }
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc