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

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

30 Sep 2025 10:09AM UTC coverage: 78.134% (+5.4%) from 72.712%
#576

Pull #264

github

web-flow
Merge 269776c6c into ef6582172
Pull Request #264: Development branch for v3.0.0

661 of 796 new or added lines in 25 files covered. (83.04%)

3 existing lines in 2 files now uncovered.

1072 of 1372 relevant lines covered (78.13%)

0.78 hits per line

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

89.8
/src/main/java/edu/kit/datamanager/pit/typeregistry/schema/DtrTestSchemaGenerator.java
1
package edu.kit.datamanager.pit.typeregistry.schema;
2

3
import com.fasterxml.jackson.databind.JsonNode;
4
import com.networknt.schema.JsonSchema;
5
import com.networknt.schema.JsonSchemaFactory;
6
import com.networknt.schema.SpecVersion;
7
import edu.kit.datamanager.pit.Application;
8
import edu.kit.datamanager.pit.common.ExternalServiceException;
9
import edu.kit.datamanager.pit.common.InvalidConfigException;
10
import edu.kit.datamanager.pit.common.TypeNotFoundException;
11
import edu.kit.datamanager.pit.configuration.ApplicationProperties;
12
import jakarta.validation.constraints.NotNull;
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15
import org.springframework.http.HttpStatusCode;
16
import org.springframework.http.client.ClientHttpResponse;
17
import org.springframework.http.client.JdkClientHttpRequestFactory;
18
import org.springframework.web.client.RestClient;
19

20
import java.io.IOException;
21
import java.io.InputStream;
22
import java.net.URI;
23
import java.net.URISyntaxException;
24
import java.net.http.HttpClient;
25

26
public class DtrTestSchemaGenerator implements SchemaGenerator {
27
    private static final Logger LOG = LoggerFactory.getLogger(DtrTestSchemaGenerator.class);
1✔
28

29
    protected static final String ORIGIN = "dtr-test";
30
    protected final URI baseUrl;
31
    protected final RestClient http;
32
    JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4);
1✔
33

34
    public DtrTestSchemaGenerator(@NotNull ApplicationProperties props) {
1✔
35
        try {
36
            this.baseUrl = props.getHandleBaseUri().toURI();
1✔
NEW
37
        } catch (URISyntaxException e) {
×
NEW
38
            throw new InvalidConfigException("BaseUrl not configured properly.");
×
39
        }
1✔
40
        HttpClient httpClient = java.net.http.HttpClient.newBuilder()
1✔
41
                .followRedirects(java.net.http.HttpClient.Redirect.NORMAL)
1✔
42
                .build();
1✔
43
        this.http = RestClient.builder()
1✔
44
                .baseUrl(this.baseUrl.toString())
1✔
45
                .requestFactory(new JdkClientHttpRequestFactory(httpClient))
1✔
46
                .requestInterceptor((request, body, execution) -> {
1✔
47
                    long start = System.currentTimeMillis();
1✔
48
                    ClientHttpResponse response = execution.execute(request,  body);
1✔
49
                    long timeSpan = System.currentTimeMillis() - start;
1✔
50
                    boolean isLongRequest = timeSpan > Application.LONG_HTTP_REQUEST_THRESHOLD;
1✔
51
                    if (isLongRequest) {
1✔
52
                        LOG.warn("Long http request to {} ({}ms)", request.getURI(), timeSpan);
1✔
53
                    }
54
                    return response;
1✔
55
                })
56
                .build();
1✔
57
    }
1✔
58

59
    @Override
60
    public SchemaInfo generateSchema(@NotNull String maybeTypePid) {
61
        return this.http.get().uri(uriBuilder -> uriBuilder.pathSegment(maybeTypePid).build())
1✔
62
                .exchange((request, response) -> {
1✔
63
                    HttpStatusCode status = response.getStatusCode();
1✔
64
                    if (status.is2xxSuccessful()) {
1✔
65
                        JsonSchema schema = null;
1✔
66
                        try (InputStream inputStream = response.getBody()) {
1✔
67
                            JsonNode schemaNode = Application.jsonObjectMapper().readTree(
1✔
68
                                    Application.jsonObjectMapper()
1✔
69
                                            .readTree(inputStream)
1✔
70
                                            .path("validationSchema")
1✔
71
                                            .asText());
1✔
72
                            schema = this.schemaFactory.getSchema(schemaNode);
1✔
73
                            if (schema == null || schema.getSchemaNode().isMissingNode() || schema.getSchemaNode().isTextual()) {
1✔
NEW
74
                                throw new IOException(ORIGIN + "could not create valid schema for %s from %s "
×
NEW
75
                                        .formatted(maybeTypePid, schemaNode));
×
76
                            }
77
                            schema.initializeValidators();
1✔
78
                        } catch (IOException e) {
1✔
79
                            return new SchemaInfo(
1✔
80
                                    ORIGIN,
81
                                    schema,
82
                                    new ExternalServiceException(baseUrl.toString(), "No valid schema found resolving PID " + maybeTypePid, e)
1✔
83
                            );
84
                        }
1✔
85
                        return new SchemaInfo(ORIGIN, schema, null);
1✔
86
                    } else if (status.value() == 404) {
1✔
NEW
87
                        return new SchemaInfo(
×
88
                                ORIGIN,
89
                                null,
90
                                new TypeNotFoundException(maybeTypePid)
91
                        );
92
                    } else {
93
                        return new SchemaInfo(
1✔
94
                                ORIGIN,
95
                                null,
96
                                new ExternalServiceException(
97
                                        this.baseUrl.toString(),
1✔
98
                                        "Error generating schema: %s - %s".formatted(status.value(), status.toString()))
1✔
99
                        );
100
                    }
101
                });
102
    }
103
}
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