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

knowledgepixels / nanodash / 17606718291

10 Sep 2025 07:37AM UTC coverage: 13.824% (+0.1%) from 13.688%
17606718291

push

github

tkuhn
Replace usage of TemplateResults with generic ItemListPanel

414 of 3878 branches covered (10.68%)

Branch coverage included in aggregate %.

1090 of 7002 relevant lines covered (15.57%)

0.69 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
    private static final long serialVersionUID = 1L;
19

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

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

73
                private static final long serialVersionUID = 1L;
74

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

80
            };
81
            c.setWaitMessage(waitMessage);
×
82
            return c;
×
83
        }
84
    }
85

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

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

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

135
    }
136

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