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

knowledgepixels / nanodash / 17588871319

09 Sep 2025 04:14PM UTC coverage: 13.618% (-0.03%) from 13.651%
17588871319

push

github

ashleycaselli
docs(ApiResultComponent, QueryRef): add missing javadoc annotations

409 of 3892 branches covered (10.51%)

Branch coverage included in aggregate %.

1086 of 7086 relevant lines covered (15.33%)

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 com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.QueryRef;
5
import org.apache.wicket.Component;
6
import org.apache.wicket.markup.html.basic.Label;
7
import org.nanopub.extra.services.ApiResponse;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10

11
import java.util.HashMap;
12
import java.util.Map;
13

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

20
    private final String queryName;
21
    private final Map<String, String> params;
22
    private ApiResponse response = null;
×
23
    private static final Logger logger = LoggerFactory.getLogger(ApiResultComponent.class);
×
24

25
    /**
26
     * Constructor for ApiResultComponent.
27
     *
28
     * @param id        the component id
29
     * @param queryName the name of the API query to be executed
30
     * @param params    a map of parameters to be passed to the API query
31
     */
32
    public ApiResultComponent(String id, String queryName, Map<String, String> params) {
33
        super(id);
×
34
        this.queryName = queryName;
×
35
        this.params = params;
×
36
    }
×
37

38
    /**
39
     * Constructor for ApiResultComponent using a QueryRef object.
40
     *
41
     * @param id       the component id
42
     * @param queryRef the QueryRef object containing the query name and parameters
43
     */
44
    public ApiResultComponent(String id, QueryRef queryRef) {
45
        super(id);
×
46
        this.queryName = queryRef.getName();
×
47
        this.params = queryRef.getParams();
×
48
    }
×
49

50
    /**
51
     * Constructor for ApiResultComponent with a single parameter.
52
     *
53
     * @param id         the component id
54
     * @param queryName  the name of the API query to be executed
55
     * @param paramKey   the key of the parameter to be passed to the API query
56
     * @param paramValue the value of the parameter to be passed to the API query
57
     */
58
    public ApiResultComponent(String id, String queryName, String paramKey, String paramValue) {
59
        this(id, queryName, getParams(paramKey, paramValue));
×
60
    }
×
61

62
    private static HashMap<String, String> getParams(String paramKey, String paramValue) {
63
        final HashMap<String, String> params = new HashMap<>();
×
64
        params.put(paramKey, paramValue);
×
65
        return params;
×
66
    }
67

68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    public Component getLazyLoadComponent(String markupId) {
73
        while (true) {
74
            if (!ApiCache.isRunning(queryName, params)) {
×
75
                try {
76
                    response = ApiCache.retrieveResponse(queryName, params);
×
77
                    if (response != null) break;
×
78
                } catch (Exception ex) {
×
79
                    return new Label(markupId, "<span class=\"negative\">API call failed.</span>").setEscapeModelStrings(false);
×
80
                }
×
81
            }
82
            try {
83
                Thread.sleep(100);
×
84
            } catch (InterruptedException ex) {
×
85
                logger.error("Interrupted while waiting for API response", ex);
×
86
            }
×
87
        }
88
        return getApiResultComponent(markupId, response);
×
89
    }
90

91
    /**
92
     * {@inheritDoc}
93
     */
94
    @Override
95
    protected boolean isContentReady() {
96
        return response != null || !ApiCache.isRunning(queryName, params);
×
97
    }
98

99
    /**
100
     * Abstract method to be implemented by subclasses to provide the component that displays the API result.
101
     *
102
     * @param markupId the markup ID for the component
103
     * @param response the API response to display
104
     * @return a Component that displays the API result
105
     */
106
    // TODO Use lambda instead of abstract method?
107
    public abstract Component getApiResultComponent(String markupId, ApiResponse response);
108

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