• 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/ThingListPanel.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.apache.wicket.markup.html.panel.Panel;
6
import org.nanopub.extra.services.ApiResponse;
7
import org.nanopub.extra.services.QueryRef;
8

9
import com.knowledgepixels.nanodash.ApiCache;
10
import com.knowledgepixels.nanodash.Utils;
11
import com.knowledgepixels.nanodash.template.Template;
12
import com.knowledgepixels.nanodash.template.TemplateData;
13

14
/**
15
 * Panel to show a list of things.
16
 */
17
public class ThingListPanel extends Panel {
18

19
    /**
20
     * Constructor for the ThingListPanel.
21
     *
22
     * @param markupId the Wicket markup ID for this panel
23
     * @param mode     the mode of the panel, determining what kind of things to show
24
     * @param thingRef the reference of the thing to show the list for
25
     * @param response the API response containing the data to display
26
     */
27
    private ThingListPanel(String markupId, final Mode mode, final String thingRef, ApiResponse response) {
28
        super(markupId);
×
29
        // TODO Not copying the table here, which can lead to problems if at some point the same result list is sorted differently at different places:
30
        response.getData().sort(new Utils.ApiResponseEntrySorter("date", true));
×
31
        if (response.getData().isEmpty()) {
×
32
            setVisible(false);
×
33
        } else if (mode == Mode.TEMPLATES) {
×
34
            add(new Label("message").setVisible(false));
×
35
        } else if (response.getData().size() == 1) {
×
36
            add(new Label("message", mode.messageStart + " 1 " + mode.wordSg + ":"));
×
37
        } else if (response.getData().size() == 1000) {
×
38
            add(new Label("message", mode.messageStart + " more " + mode.wordPl + " (>999) than what can be shown here:"));
×
39
        } else {
40
            add(new Label("message", mode.messageStart + " " + response.getData().size() + " " + mode.wordPl + ":"));
×
41
        }
42
        if (mode == Mode.TEMPLATES) {
×
43
            add(new ItemListPanel<Template>(
×
44
                    "templates",
45
                    "Related Templates",
46
                    TemplateData.getTemplateList(response),
×
47
                    (template) -> new TemplateItem("item", template)
×
48
                ));
49
            add(new Label("things").setVisible(false));
×
50
        } else {
51
            add(ThingResults.fromApiResponse("things", mode.returnField, response));
×
52
            add(new Label("templates").setVisible(false));
×
53
        }
54
    }
×
55

56
    /**
57
     * Factory method to create a ThingListPanel component.
58
     *
59
     * @param markupId    the Wicket markup ID for the panel
60
     * @param mode        the mode of the panel, determining what kind of things to show
61
     * @param thingRef    the reference of the thing to show the list for
62
     * @param waitMessage the message to display while waiting for the API response
63
     * @return a new ThingListPanel component
64
     */
65
    public static Component createComponent(final String markupId, final Mode mode, final String thingRef, final String waitMessage) {
66
        QueryRef queryRef = new QueryRef(mode.queryName, mode.queryParamKey, thingRef);
×
67
        ApiResponse response = ApiCache.retrieveResponse(queryRef);
×
68
        if (response != null) {
×
69
            return new ThingListPanel(markupId, mode, thingRef, response);
×
70
        } else {
71
            ApiResultComponent c = new ApiResultComponent(markupId, queryRef) {
×
72

73
                @Override
74
                public Component getApiResultComponent(String markupId, ApiResponse response) {
75
                    return new ThingListPanel(markupId, mode, thingRef, response);
×
76
                }
77

78
            };
79
            c.setWaitMessage(waitMessage);
×
80
            return c;
×
81
        }
82
    }
83

84
    /**
85
     * Enum representing the different modes of the ThingListPanel.
86
     * Each mode corresponds to a specific type of thing and defines how to query and display them.
87
     */
88
    public enum Mode {
×
89
        CLASSES("get-classes-for-thing", "thing", "class", "class", "classes", "Assigned to"),
×
90
        INSTANCES("get-instances", "class", "instance", "instance", "instances", "Has"),
×
91
        PARTS("get-parts", "thing", "part", "part", "parts", "Has"),
×
92
        TEMPLATES("get-templates-with-uri", "thing", "np", "template", "templates", "Used in");
×
93

94
        /**
95
         * The name of the query to be used for this mode.
96
         */
97
        public final String queryName;
98
        /**
99
         * The parameter to be used in the query for this mode.
100
         */
101
        public final String queryParamKey;
102
        /**
103
         * The field in the API response that contains the relevant data for this mode.
104
         */
105
        public final String returnField;
106
        /**
107
         * The singular word used in messages for this mode.
108
         */
109
        public final String wordSg;
110
        /**
111
         * The plural word used in messages for this mode.
112
         */
113
        public final String wordPl;
114
        /**
115
         * The start of the message displayed in the panel for this mode.
116
         */
117
        public final String messageStart;
118
        /**
119
         * The identifier for this mode, used in URLs and other references.
120
         */
121
        public final String modeId;
122

123
        private Mode(String queryName, String queryParamKey, String returnField, String wordSg, String wordPl, String messageStart) {
×
124
            this.queryName = queryName;
×
125
            this.queryParamKey = queryParamKey;
×
126
            this.returnField = returnField;
×
127
            this.wordSg = wordSg;
×
128
            this.wordPl = wordPl;
×
129
            this.messageStart = messageStart;
×
130
            this.modeId = name().toLowerCase();
×
131
        }
×
132

133
    }
134

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