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

knowledgepixels / nanodash / 17437818570

03 Sep 2025 03:09PM UTC coverage: 12.108% (-0.03%) from 12.137%
17437818570

push

github

tkuhn
Improve async loading of projects; provide new MethodResultComponent

337 of 3874 branches covered (8.7%)

Branch coverage included in aggregate %.

972 of 6937 relevant lines covered (14.01%)

0.62 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 java.util.HashMap;
4

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 com.knowledgepixels.nanodash.ApiCache;
12

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

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

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

37
    /**
38
     * Constructor for ApiResultComponent with a single parameter.
39
     *
40
     * @param id         the component id
41
     * @param queryName  the name of the API query to be executed
42
     * @param paramKey   the key of the parameter to be passed to the API query
43
     * @param paramValue the value of the parameter to be passed to the API query
44
     */
45
    public ApiResultComponent(String id, String queryName, String paramKey, String paramValue) {
46
        this(id, queryName, getParams(paramKey, paramValue));
×
47
    }
×
48

49
    private static HashMap<String, String> getParams(String paramKey, String paramValue) {
50
        final HashMap<String, String> params = new HashMap<>();
×
51
        params.put(paramKey, paramValue);
×
52
        return params;
×
53
    }
54

55
    /**
56
     * {@inheritDoc}
57
     */
58
    @Override
59
    public Component getLazyLoadComponent(String markupId) {
60
        while (true) {
61
            if (!ApiCache.isRunning(queryName, params)) {
×
62
                try {
63
                    response = ApiCache.retrieveResponse(queryName, params);
×
64
                    if (response != null) break;
×
65
                } catch (Exception ex) {
×
66
                    return new Label(markupId, "<span class=\"negative\">API call failed.</span>").setEscapeModelStrings(false);
×
67
                }
×
68
            }
69
            try {
70
                Thread.sleep(100);
×
71
            } catch (InterruptedException ex) {
×
72
                logger.error("Interrupted while waiting for API response", ex);
×
73
            }
×
74
        }
75
        return getApiResultComponent(markupId, response);
×
76
    }
77

78
    /**
79
     * {@inheritDoc}
80
     */
81
    @Override
82
    protected boolean isContentReady() {
83
        return response != null || !ApiCache.isRunning(queryName, params);
×
84
    }
85

86
    /**
87
     * Abstract method to be implemented by subclasses to provide the component that displays the API result.
88
     *
89
     * @param markupId the markup ID for the component
90
     * @param response the API response to display
91
     * @return a Component that displays the API result
92
     */
93
    // TODO Use lambda instead of abstract method?
94
    public abstract Component getApiResultComponent(String markupId, ApiResponse response);
95

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