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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

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

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

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

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

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

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

76
            };
77
            c.setWaitMessage(waitMessage);
×
78
            return c;
×
79
        }
80
    }
81

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

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

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

131
    }
132

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