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

knowledgepixels / nanodash / 17320701451

29 Aug 2025 09:55AM UTC coverage: 12.02% (+0.01%) from 12.007%
17320701451

push

github

ashleycaselli
refactor: minor code style update

330 of 3842 branches covered (8.59%)

Branch coverage included in aggregate %.

950 of 6807 relevant lines covered (13.96%)

0.61 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.extensions.ajax.markup.html.AjaxLazyLoadPanel;
8
import org.apache.wicket.markup.html.basic.Label;
9
import org.apache.wicket.markup.html.panel.Panel;
10
import org.apache.wicket.markup.repeater.Item;
11
import org.apache.wicket.markup.repeater.data.DataView;
12
import org.apache.wicket.markup.repeater.data.ListDataProvider;
13
import org.nanopub.extra.services.ApiResponse;
14
import org.nanopub.extra.services.ApiResponseEntry;
15

16
import java.io.Serializable;
17
import java.util.*;
18

19
/**
20
 * A list of templates, grouped by topic.
21
 */
22
public class TemplateList extends Panel {
23

24
    private static final long serialVersionUID = 1L;
25

26
    /**
27
     * A list of templates, grouped by topic.
28
     *
29
     * @param id the wicket id of this component
30
     */
31
    public TemplateList(String id) {
32
        super(id);
×
33

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

42
                private static final long serialVersionUID = 1L;
43

44
                @Override
45
                public Component getLazyLoadComponent(String markupId) {
46
                    ApiResponse r = null;
×
47
                    while (true) {
48
                        try {
49
                            Thread.sleep(500);
×
50
                        } catch (InterruptedException ex) {
×
51
                            ex.printStackTrace();
×
52
                        }
×
53
                        if (!ApiCache.isRunning(ptQueryName, ptParams)) {
×
54
                            r = ApiCache.retrieveResponse(ptQueryName, ptParams);
×
55
                            if (r != null) break;
×
56
                        }
57
                    }
58
                    return TemplateResults.fromApiResponse(markupId, r);
×
59
                }
60

61
            });
62
        }
63

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

72
                private static final long serialVersionUID = 1L;
73

74
                @Override
75
                public Component getLazyLoadComponent(String markupId) {
76
                    ApiResponse r = null;
×
77
                    while (true) {
78
                        try {
79
                            Thread.sleep(500);
×
80
                        } catch (InterruptedException ex) {
×
81
                            ex.printStackTrace();
×
82
                        }
×
83
                        if (!ApiCache.isRunning(stQueryName, stParams)) {
×
84
                            r = ApiCache.retrieveResponse(stQueryName, stParams);
×
85
                            if (r != null) break;
×
86
                        }
87
                    }
88
                    return TemplateResults.fromApiResponse(markupId, r);
×
89
                }
90

91
            });
92
        }
93

94
        ArrayList<ApiResponseEntry> templateList = new ArrayList<>(TemplateData.get().getAssertionTemplates());
×
95
        templateList.sort((t1, t2) -> {
×
96
            Calendar c1 = getTime(t1);
×
97
            Calendar c2 = getTime(t2);
×
98
            if (c1 == null && c2 == null) return 0;
×
99
            if (c1 == null) return 1;
×
100
            if (c2 == null) return -1;
×
101
            return c2.compareTo(c1);
×
102
        });
103

104
        Map<String, Topic> topics = new HashMap<>();
×
105
        for (ApiResponseEntry entry : templateList) {
×
106
            String tag = entry.get("tag");
×
107
            if ("".equals(tag)) tag = null;
×
108
            if (!topics.containsKey(tag)) {
×
109
                topics.put(tag, new Topic(tag));
×
110
            }
111
            topics.get(tag).templates.add(entry);
×
112

113
        }
×
114
        ArrayList<Topic> topicList = new ArrayList<Topic>(topics.values());
×
115
        topicList.sort((t0, t1) -> {
×
116
            if (t0.tag == null) return 1;
×
117
            if (t1.tag == null) return -1;
×
118
            return t1.templates.size() - t0.templates.size();
×
119
        });
120
        add(new DataView<Topic>("topics", new ListDataProvider<Topic>(topicList)) {
×
121

122
            private static final long serialVersionUID = 1L;
123

124
            @Override
125
            protected void populateItem(Item<Topic> item) {
126
                String tag = item.getModelObject().tag;
×
127
                if (tag == null) tag = "Other";
×
128
                item.add(new Label("title", tag));
×
129
                item.add(new DataView<ApiResponseEntry>("template-list", new ListDataProvider<ApiResponseEntry>(item.getModelObject().templates)) {
×
130

131
                    private static final long serialVersionUID = 1L;
132

133
                    @Override
134
                    protected void populateItem(Item<ApiResponseEntry> item) {
135
                        item.add(new TemplateItem("template", item.getModelObject()));
×
136
                    }
×
137

138
                });
139
            }
×
140
        });
141

142
    }
×
143

144
    private static Calendar getTime(ApiResponseEntry entry) {
145
        return DatatypeConverter.parseDateTime(entry.get("date"));
×
146
    }
147

148

149
    private static class Topic implements Serializable {
150

151
        private static final long serialVersionUID = 5919614141679468774L;
152

153
        String tag;
154
        ArrayList<ApiResponseEntry> templates = new ArrayList<>();
×
155

156
        Topic(String tag) {
×
157
            this.tag = tag;
×
158
        }
×
159

160
    }
161

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