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

knowledgepixels / nanodash / 17852532121

19 Sep 2025 08:10AM UTC coverage: 13.568% (-0.3%) from 13.87%
17852532121

push

github

tkuhn
feat: Switch to QueryRef provided by nanopub, using multimap

428 of 4008 branches covered (10.68%)

Branch coverage included in aggregate %.

1104 of 7283 relevant lines covered (15.16%)

0.68 hits per line

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

0.0
src/main/java/com/knowledgepixels/nanodash/component/ApiResultComponent.java
1
package com.knowledgepixels.nanodash.component;
2

3
import org.apache.wicket.Component;
4
import org.apache.wicket.markup.html.basic.Label;
5
import org.nanopub.extra.services.ApiResponse;
6
import org.nanopub.extra.services.QueryRef;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import com.knowledgepixels.nanodash.ApiCache;
11

12
/**
13
 * A component that retrieves and displays the result of an API call.
14
 * It uses AjaxLazyLoadPanel to load the content lazily and shows a loading indicator while waiting for the response.
15
 */
16
public abstract class ApiResultComponent extends ResultComponent {
17

18
    private final QueryRef queryRef;
19
    private ApiResponse response = null;
×
20
    private static final Logger logger = LoggerFactory.getLogger(ApiResultComponent.class);
×
21

22
    /**
23
     * Constructor for ApiResultComponent using a QueryRef object.
24
     *
25
     * @param id       the component id
26
     * @param queryRef the QueryRef object containing the query name and parameters
27
     */
28
    public ApiResultComponent(String id, QueryRef queryRef) {
29
        super(id);
×
30
        this.queryRef = queryRef;
×
31
    }
×
32

33
    /**
34
     * {@inheritDoc}
35
     */
36
    @Override
37
    public Component getLazyLoadComponent(String markupId) {
38
        while (true) {
39
            if (!ApiCache.isRunning(queryRef)) {
×
40
                try {
41
                    response = ApiCache.retrieveResponse(queryRef);
×
42
                    if (response != null) break;
×
43
                } catch (Exception ex) {
×
44
                    return new Label(markupId, "<span class=\"negative\">API call failed.</span>").setEscapeModelStrings(false);
×
45
                }
×
46
            }
47
            try {
48
                Thread.sleep(100);
×
49
            } catch (InterruptedException ex) {
×
50
                logger.error("Interrupted while waiting for API response", ex);
×
51
            }
×
52
        }
53
        return getApiResultComponent(markupId, response);
×
54
    }
55

56
    /**
57
     * {@inheritDoc}
58
     */
59
    @Override
60
    protected boolean isContentReady() {
61
        return response != null || !ApiCache.isRunning(queryRef);
×
62
    }
63

64
    /**
65
     * Abstract method to be implemented by subclasses to provide the component that displays the API result.
66
     *
67
     * @param markupId the markup ID for the component
68
     * @param response the API response to display
69
     * @return a Component that displays the API result
70
     */
71
    // TODO Use lambda instead of abstract method?
72
    public abstract Component getApiResultComponent(String markupId, ApiResponse response);
73

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