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

knowledgepixels / nanodash / 17852532121

19 Sep 2025 08:10AM UTC coverage: 13.568% (-0.3%) from 13.87%
17852532121

push

github

tkuhn
feat: Switch to QueryRef provided by nanopub, using multimap

428 of 4008 branches covered (10.68%)

Branch coverage included in aggregate %.

1104 of 7283 relevant lines covered (15.16%)

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

3
import java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.Calendar;
6
import java.util.HashMap;
7
import java.util.Map;
8

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.ApiResponseEntry;
14
import org.nanopub.extra.services.QueryRef;
15

16
import com.knowledgepixels.nanodash.template.Template;
17
import com.knowledgepixels.nanodash.template.TemplateData;
18

19
import jakarta.xml.bind.DatatypeConverter;
20

21
/**
22
 * A list of templates, grouped by topic.
23
 */
24
public class TemplateList extends Panel {
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
        setOutputMarkupId(true);
×
34

35
        add(new ItemListPanel<Template>(
×
36
                "popular-templates",
37
                "Popular Templates",
38
                new QueryRef("get-most-used-templates-last30d"),
39
                TemplateData::getTemplateList,
40
                (template) -> new TemplateItem("item", template)
×
41
        ));
42

43
        add(new ItemListPanel<Template>(
×
44
                "getstarted-templates",
45
                "Suggested Templates to Get Started",
46
                new QueryRef("get-suggested-templates-to-get-started"),
47
                TemplateData::getTemplateList,
48
                (template) -> new TemplateItem("item", template)
×
49
        ));
50

51
        ArrayList<ApiResponseEntry> templateList = new ArrayList<>(TemplateData.get().getAssertionTemplates());
×
52
        templateList.sort((t1, t2) -> {
×
53
            Calendar c1 = getTime(t1);
×
54
            Calendar c2 = getTime(t2);
×
55
            if (c1 == null && c2 == null) return 0;
×
56
            if (c1 == null) return 1;
×
57
            if (c2 == null) return -1;
×
58
            return c2.compareTo(c1);
×
59
        });
60

61
        Map<String, Topic> topics = new HashMap<>();
×
62
        for (ApiResponseEntry entry : templateList) {
×
63
            String tag = entry.get("tag");
×
64
            if (tag.isEmpty()) tag = null;
×
65
            if (!topics.containsKey(tag)) {
×
66
                topics.put(tag, new Topic(tag));
×
67
            }
68
            topics.get(tag).templates.add(entry);
×
69

70
        }
×
71
        ArrayList<Topic> topicList = new ArrayList<Topic>(topics.values());
×
72
        topicList.sort((t0, t1) -> {
×
73
            if (t0.tag == null) return 1;
×
74
            if (t1.tag == null) return -1;
×
75
            return t1.templates.size() - t0.templates.size();
×
76
        });
77
        DataView<Topic> topicDataView = new DataView<Topic>("topics", new ListDataProvider<Topic>(topicList)) {
×
78

79
            @Override
80
            protected void populateItem(Item<Topic> item) {
81
                String tag = item.getModelObject().tag;
×
82
                if (tag == null) tag = "Other";
×
83
                item.add(new ItemListPanel<ApiResponseEntry>(
×
84
                        "templates",
85
                        tag,
86
                        item.getModelObject().templates,
×
87
                        (respEntry) -> new TemplateItem("item", respEntry)
×
88
                ));
89
            }
×
90
        };
91
        topicDataView.setOutputMarkupId(true);
×
92
        add(topicDataView);
×
93
    }
×
94

95
    private static Calendar getTime(ApiResponseEntry entry) {
96
        return DatatypeConverter.parseDateTime(entry.get("date"));
×
97
    }
98

99

100
    private static class Topic implements Serializable {
101

102
        String tag;
103
        ArrayList<ApiResponseEntry> templates = new ArrayList<>();
×
104

105
        Topic(String tag) {
×
106
            this.tag = tag;
×
107
        }
×
108

109
    }
110

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