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

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

21 Jan 2025 11:55PM UTC coverage: 75.383% (+3.0%) from 72.4%
#444

Pull #218

github

web-flow
Merge 0aada098b 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

78.13
/src/main/java/edu/kit/datamanager/pit/typeregistry/schema/DtrTestSchemaGenerator.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.http.client.JdkClientHttpRequestFactory;
15
import org.springframework.web.client.RestClient;
16

17
import java.io.InputStream;
18
import java.net.URI;
19
import java.net.URISyntaxException;
20
import java.net.http.HttpClient;
21

22
public class DtrTestSchemaGenerator implements SchemaGenerator {
23

24
    protected static final String ORIGIN = "dtr-test";
25
    protected final URI baseUrl;
26
    protected final RestClient http;
27

28
    public DtrTestSchemaGenerator(@NotNull ApplicationProperties props) {
1✔
29
        try {
30
            this.baseUrl = props.getHandleBaseUri().toURI();
1✔
NEW
31
        } catch (URISyntaxException e) {
×
NEW
32
            throw new InvalidConfigException("BaseUrl not configured properly.");
×
33
        }
1✔
34
        HttpClient httpClient = java.net.http.HttpClient.newBuilder()
1✔
35
                .followRedirects(java.net.http.HttpClient.Redirect.NORMAL)
1✔
36
                .build();
1✔
37
        this.http = RestClient.builder()
1✔
38
                .baseUrl(this.baseUrl.toString())
1✔
39
                .requestFactory(new JdkClientHttpRequestFactory(httpClient))
1✔
40
                .build();
1✔
41
    }
1✔
42

43
    @Override
44
    public SchemaInfo generateSchema(@NotNull String maybeTypePid) {
45
        return this.http.get().uri(uriBuilder -> uriBuilder.pathSegment(maybeTypePid).build())
1✔
46
                .exchange((request, response) -> {
1✔
47
                    HttpStatusCode status = response.getStatusCode();
1✔
48
                    if (status.is2xxSuccessful()) {
1✔
49
                        Schema schema = null;
1✔
50
                        try (InputStream inputStream = response.getBody()) {
1✔
51
                            JSONObject jsonBody = new JSONObject(new JSONTokener(inputStream));
1✔
52
                            JSONObject rawSchema = new JSONObject(new JSONTokener(jsonBody.getString("validationSchema")));
1✔
53
                            schema = SchemaLoader.load(rawSchema);
1✔
54
                        } catch (JSONException e) {
1✔
55
                            return new SchemaInfo(
1✔
56
                                    ORIGIN,
57
                                    schema,
58
                                    new ExternalServiceException(baseUrl.toString(), "No valid schema found resolving PID " + maybeTypePid)
1✔
59
                            );
60
                        }
1✔
61
                        return new SchemaInfo(ORIGIN, schema, null);
1✔
NEW
62
                    } else if (status.value() == 404) {
×
NEW
63
                        return new SchemaInfo(
×
64
                                ORIGIN,
65
                                null,
66
                                new TypeNotFoundException(maybeTypePid)
67
                        );
68
                    } else {
NEW
69
                        return new SchemaInfo(
×
70
                                ORIGIN,
71
                                null,
72
                                new ExternalServiceException(
NEW
73
                                        this.baseUrl.toString(),
×
NEW
74
                                        "Error generating schema: %s - %s".formatted(status.value(), status.toString()))
×
75
                        );
76
                    }
77
                });
78
    }
79
}
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