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

Nanopublication / nanopub-java / 19897067550

03 Dec 2025 02:19PM UTC coverage: 51.868% (+0.1%) from 51.73%
19897067550

push

github

ashleycaselli
refactor: remove unused code and update wrong javadoc annotations

1013 of 2922 branches covered (34.67%)

Branch coverage included in aggregate %.

5221 of 9097 relevant lines covered (57.39%)

2.69 hits per line

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

57.14
src/main/java/org/nanopub/extra/services/QueryAccess.java
1
package org.nanopub.extra.services;
2

3
import com.opencsv.CSVReader;
4
import com.opencsv.CSVWriterBuilder;
5
import com.opencsv.ICSVWriter;
6
import com.opencsv.exceptions.CsvValidationException;
7
import org.apache.http.HttpResponse;
8

9
import java.io.BufferedReader;
10
import java.io.IOException;
11
import java.io.InputStreamReader;
12
import java.io.Writer;
13

14
/**
15
 * Second-generation query API access
16
 */
17
public abstract class QueryAccess {
3✔
18

19
    /**
20
     * Process the header.
21
     *
22
     * @param line the header line from the CSV response
23
     */
24
    protected abstract void processHeader(String[] line);
25

26
    /**
27
     * Process a line of data from the CSV response.
28
     *
29
     * @param line the line of data from the CSV response
30
     */
31
    protected abstract void processLine(String[] line);
32

33
    /**
34
     * Call a query with the given queryId and parameters.
35
     *
36
     * @param queryRef the query reference
37
     * @throws FailedApiCallException         if the API call fails
38
     * @throws APINotReachableException       if the API is not reachable
39
     * @throws NotEnoughAPIInstancesException if there are not enough API instances available
40
     */
41
    public void call(QueryRef queryRef) throws FailedApiCallException, APINotReachableException, NotEnoughAPIInstancesException {
42
        HttpResponse resp = QueryCall.run(queryRef);
3✔
43
        try (CSVReader csvReader = new CSVReader(new BufferedReader(new InputStreamReader(resp.getEntity().getContent())))) {
13✔
44
            String[] line = null;
2✔
45
            int n = 0;
2✔
46
            while ((line = csvReader.readNext()) != null) {
5✔
47
                n++;
1✔
48
                if (n == 1) {
3!
49
                    processHeader(line);
4✔
50
                } else {
51
                    processLine(line);
×
52
                }
53
            }
54
        } catch (IOException | CsvValidationException ex) {
×
55
            throw new FailedApiCallException(ex);
×
56
        }
1✔
57
    }
1✔
58

59
    /**
60
     * Print the response of a query in CSV format to the given writer.
61
     *
62
     * @param queryRef the query reference
63
     * @param writer   the writer to print the CSV response to
64
     * @throws FailedApiCallException         if the API call fails
65
     * @throws APINotReachableException       if the API is not reachable
66
     * @throws NotEnoughAPIInstancesException if there are not enough API instances available
67
     */
68
    public static void printCvsResponse(QueryRef queryRef, Writer writer) throws FailedApiCallException, APINotReachableException, NotEnoughAPIInstancesException {
69
        ICSVWriter icsvWriter = new CSVWriterBuilder(writer).withSeparator(',').build();
×
70
        QueryAccess a = new QueryAccess() {
×
71

72
            @Override
73
            protected void processHeader(String[] line) {
74
                icsvWriter.writeNext(line);
×
75
            }
×
76

77
            @Override
78
            protected void processLine(String[] line) {
79
                icsvWriter.writeNext(line);
×
80
            }
×
81

82
        };
83
        a.call(queryRef);
×
84
        icsvWriter.flushQuietly();
×
85
    }
×
86

87
    /**
88
     * Get the response of a query as an ApiResponse object.
89
     *
90
     * @param queryRef the query reference
91
     * @return an ApiResponse object containing the response data
92
     * @throws FailedApiCallException         if the API call fails
93
     * @throws APINotReachableException       if the API is not reachable
94
     * @throws NotEnoughAPIInstancesException if there are not enough API instances available
95
     */
96
    public static ApiResponse get(QueryRef queryRef) throws FailedApiCallException, APINotReachableException, NotEnoughAPIInstancesException {
97
        final ApiResponse response = new ApiResponse();
4✔
98
        QueryAccess a = new QueryAccess() {
11✔
99

100
            @Override
101
            protected void processHeader(String[] line) {
102
                response.setHeader(line);
4✔
103
            }
1✔
104

105
            @Override
106
            protected void processLine(String[] line) {
107
                response.add(line);
×
108
            }
×
109

110
        };
111
        a.call(queryRef);
3✔
112
        return response;
2✔
113
    }
114

115
}
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