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

knowledgepixels / nanodash / 18679270445

21 Oct 2025 09:24AM UTC coverage: 14.048% (+1.0%) from 13.053%
18679270445

push

github

tkuhn
feat(ExplorePage): Show nanopubs where term was described/introduced

480 of 4316 branches covered (11.12%)

Branch coverage included in aggregate %.

1250 of 7999 relevant lines covered (15.63%)

0.7 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
        DESCRIPTIONS("get-term-definitions", "term", "np", "nanopublication", "nanopublications", "Described in");
×
94

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

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

134
    }
135

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