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

knowledgepixels / nanodash / 17406147119

02 Sep 2025 02:07PM UTC coverage: 12.066% (-0.005%) from 12.071%
17406147119

push

github

tkuhn
Make our own AjaxLazyLoadPanel that doesn't introduce a <div>

331 of 3866 branches covered (8.56%)

Branch coverage included in aggregate %.

969 of 6908 relevant lines covered (14.03%)

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/TemplateList.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.template.TemplateData;
5
import jakarta.xml.bind.DatatypeConverter;
6
import org.apache.wicket.Component;
7
import org.apache.wicket.markup.html.basic.Label;
8
import org.apache.wicket.markup.html.panel.Panel;
9
import org.apache.wicket.markup.repeater.Item;
10
import org.apache.wicket.markup.repeater.data.DataView;
11
import org.apache.wicket.markup.repeater.data.ListDataProvider;
12
import org.nanopub.extra.services.ApiResponse;
13
import org.nanopub.extra.services.ApiResponseEntry;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

17
import java.io.Serializable;
18
import java.util.ArrayList;
19
import java.util.Calendar;
20
import java.util.HashMap;
21
import java.util.Map;
22

23
/**
24
 * A list of templates, grouped by topic.
25
 */
26
public class TemplateList extends Panel {
27

28
    private static final long serialVersionUID = 1L;
29
    private static final Logger logger = LoggerFactory.getLogger(TemplateList.class);
×
30

31
    /**
32
     * A list of templates, grouped by topic.
33
     *
34
     * @param id the wicket id of this component
35
     */
36
    public TemplateList(String id) {
37
        super(id);
×
38

39
        final Map<String, String> ptParams = new HashMap<>();
×
40
        final String ptQueryName = "get-most-used-templates-last30d";
×
41
        ApiResponse ptResponse = ApiCache.retrieveResponse(ptQueryName, ptParams);
×
42
        if (ptResponse != null) {
×
43
            add(TemplateResults.fromApiResponse("populartemplates", ptResponse));
×
44
        } else {
45
            add(new AjaxLazyLoadPanel<Component>("populartemplates") {
×
46

47
                private static final long serialVersionUID = 1L;
48

49
                @Override
50
                public Component getLazyLoadComponent(String markupId) {
51
                    ApiResponse r = null;
×
52
                    while (true) {
53
                        try {
54
                            Thread.sleep(500);
×
55
                        } catch (InterruptedException ex) {
×
56
                            logger.error("Thread interrupted", ex);
×
57
                        }
×
58
                        if (!ApiCache.isRunning(ptQueryName, ptParams)) {
×
59
                            r = ApiCache.retrieveResponse(ptQueryName, ptParams);
×
60
                            if (r != null) break;
×
61
                        }
62
                    }
63
                    return TemplateResults.fromApiResponse(markupId, r);
×
64
                }
65

66
            });
67
        }
68

69
        final Map<String, String> stParams = new HashMap<>();
×
70
        final String stQueryName = "get-suggested-templates-to-get-started";
×
71
        ApiResponse stResponse = ApiCache.retrieveResponse(stQueryName, stParams);
×
72
        if (stResponse != null) {
×
73
            add(TemplateResults.fromApiResponse("getstartedtemplates", stResponse));
×
74
        } else {
75
            add(new AjaxLazyLoadPanel<Component>("getstartedtemplates") {
×
76

77
                private static final long serialVersionUID = 1L;
78

79
                @Override
80
                public Component getLazyLoadComponent(String markupId) {
81
                    ApiResponse r = null;
×
82
                    while (true) {
83
                        try {
84
                            Thread.sleep(500);
×
85
                        } catch (InterruptedException ex) {
×
86
                            logger.error("Thread interrupted", ex);
×
87
                        }
×
88
                        if (!ApiCache.isRunning(stQueryName, stParams)) {
×
89
                            r = ApiCache.retrieveResponse(stQueryName, stParams);
×
90
                            if (r != null) break;
×
91
                        }
92
                    }
93
                    return TemplateResults.fromApiResponse(markupId, r);
×
94
                }
95

96
            });
97
        }
98

99
        ArrayList<ApiResponseEntry> templateList = new ArrayList<>(TemplateData.get().getAssertionTemplates());
×
100
        templateList.sort((t1, t2) -> {
×
101
            Calendar c1 = getTime(t1);
×
102
            Calendar c2 = getTime(t2);
×
103
            if (c1 == null && c2 == null) return 0;
×
104
            if (c1 == null) return 1;
×
105
            if (c2 == null) return -1;
×
106
            return c2.compareTo(c1);
×
107
        });
108

109
        Map<String, Topic> topics = new HashMap<>();
×
110
        for (ApiResponseEntry entry : templateList) {
×
111
            String tag = entry.get("tag");
×
112
            if ("".equals(tag)) tag = null;
×
113
            if (!topics.containsKey(tag)) {
×
114
                topics.put(tag, new Topic(tag));
×
115
            }
116
            topics.get(tag).templates.add(entry);
×
117

118
        }
×
119
        ArrayList<Topic> topicList = new ArrayList<Topic>(topics.values());
×
120
        topicList.sort((t0, t1) -> {
×
121
            if (t0.tag == null) return 1;
×
122
            if (t1.tag == null) return -1;
×
123
            return t1.templates.size() - t0.templates.size();
×
124
        });
125
        add(new DataView<Topic>("topics", new ListDataProvider<Topic>(topicList)) {
×
126

127
            private static final long serialVersionUID = 1L;
128

129
            @Override
130
            protected void populateItem(Item<Topic> item) {
131
                String tag = item.getModelObject().tag;
×
132
                if (tag == null) tag = "Other";
×
133
                item.add(new Label("title", tag));
×
134
                item.add(new DataView<ApiResponseEntry>("template-list", new ListDataProvider<ApiResponseEntry>(item.getModelObject().templates)) {
×
135

136
                    private static final long serialVersionUID = 1L;
137

138
                    @Override
139
                    protected void populateItem(Item<ApiResponseEntry> item) {
140
                        item.add(new TemplateItem("template", item.getModelObject()));
×
141
                    }
×
142

143
                });
144
            }
×
145
        });
146

147
    }
×
148

149
    private static Calendar getTime(ApiResponseEntry entry) {
150
        return DatatypeConverter.parseDateTime(entry.get("date"));
×
151
    }
152

153

154
    private static class Topic implements Serializable {
155

156
        private static final long serialVersionUID = 5919614141679468774L;
157

158
        String tag;
159
        ArrayList<ApiResponseEntry> templates = new ArrayList<>();
×
160

161
        Topic(String tag) {
×
162
            this.tag = tag;
×
163
        }
×
164

165
    }
166

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