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

knowledgepixels / nanodash / 17550569588

08 Sep 2025 12:20PM UTC coverage: 11.945% (-0.02%) from 11.96%
17550569588

push

github

tkuhn
Improve ActivityPanel (currently only on Test page)

334 of 3850 branches covered (8.68%)

Branch coverage included in aggregate %.

958 of 6966 relevant lines covered (13.75%)

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

3
import java.io.Serializable;
4
import java.time.Year;
5
import java.util.ArrayList;
6
import java.util.Calendar;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.Iterator;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Set;
13

14
import org.apache.wicket.behavior.AttributeAppender;
15
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
16
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
17
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
18
import org.apache.wicket.extensions.markup.html.repeater.data.table.HeadersToolbar;
19
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
20
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigationToolbar;
21
import org.apache.wicket.markup.html.basic.Label;
22
import org.apache.wicket.markup.html.panel.Panel;
23
import org.apache.wicket.markup.repeater.Item;
24
import org.apache.wicket.markup.repeater.data.IDataProvider;
25
import org.apache.wicket.model.IModel;
26
import org.apache.wicket.model.Model;
27
import org.nanopub.extra.services.ApiResponse;
28
import org.nanopub.extra.services.ApiResponseEntry;
29

30
import com.knowledgepixels.nanodash.Utils;
31

32
/**
33
 * A panel that displays activity data in a table format.
34
 * It shows the number of nanopublications per type and month.
35
 */
36
public class ActivityPanel extends Panel {
37

38
    private static final long serialVersionUID = 1L;
39

40
    private Map<String, Map<String, String>> typeMonthValueMap = new HashMap<>();
×
41

42
    /**
43
     * Constructor for ActivityPanel.
44
     *
45
     * @param markupId the Wicket markup ID for this panel
46
     * @param response the ApiResponse containing activity data
47
     */
48
    public ActivityPanel(String markupId, ApiResponse response) {
49
        super(markupId);
×
50
        setOutputMarkupId(true);
×
51

52
        List<Entity> list = new ArrayList<>();
×
53
        Set<String> types = new HashSet<>();
×
54
        for (ApiResponseEntry e : response.getData()) {
×
55
            String type = e.get("type");
×
56
            if (!types.contains(type)) {
×
57
                list.add(new Entity(type));
×
58
                types.add(type);
×
59
            }
60
            if (!typeMonthValueMap.containsKey(type)) {
×
61
                typeMonthValueMap.put(type, new HashMap<>());
×
62
            }
63
            typeMonthValueMap.get(type).put(e.get("month"), e.get("npCount"));
×
64
        }
×
65

66
        final Calendar calendar = Calendar.getInstance();
×
67
        int year = Year.now().getValue() - 1;
×
68
        int month = calendar.get(Calendar.MONTH) + 1;
×
69

70
        List<IColumn<Entity, String>> columns = new ArrayList<>();
×
71
        columns.add(new Column("type"));
×
72

73
        int count = 0;
×
74
        while (count < 12) {
×
75
            month++;
×
76
            if (month == 13) {
×
77
                year++;
×
78
                month = 1;
×
79
            }
80
            columns.add(new Column(formatYearMonth(year, month)));
×
81
            count++;
×
82
        }
83

84
        DataTable<Entity, String> table = new DataTable<Entity, String>("table", columns, new EntityProvider(list), 10);
×
85
        table.addBottomToolbar(new NavigationToolbar(table));
×
86
        table.addTopToolbar(new HeadersToolbar<String>(table, null));
×
87
        table.setOutputMarkupId(true);
×
88
        add(table);
×
89
    }
×
90

91
    private static String formatYearMonth(int year, int month) {
92
        return year + "-" + (month > 9 ? "" + month : "0" + month);
×
93
    }
94

95
    private class Entity implements Serializable {
96

97
        private static final long serialVersionUID = 1L;
98

99
        public String type;
100

101
        public Entity(String type) {
×
102
            this.type = type;
×
103
        }
×
104

105
        public String getValue(String month) {
106
            if (!typeMonthValueMap.containsKey(type)) return "";
×
107
            if (!typeMonthValueMap.get(type).containsKey(month)) return "";
×
108
            return typeMonthValueMap.get(type).get(month);
×
109
        }
110

111
    }
112

113
    private class Column extends AbstractColumn<Entity, String> {
114

115
        private static final long serialVersionUID = 1L;
116

117
        private String title;
118

119
        public Column(String title) {
120
            this(new Model<String>(title));
×
121
        }
×
122

123
        public Column(Model<String> titleModel) {
×
124
            super(titleModel);
×
125
            this.title = titleModel.getObject();
×
126
            titleModel.setObject(titleModel.getObject().replaceFirst("^20", ""));
×
127
        }
×
128

129
        @Override
130
        public void populateItem(Item<ICellPopulator<Entity>> cellItem, String componentId, IModel<Entity> rowModel) {
131
            Entity e = rowModel.getObject();
×
132
            if (title.equals("type")) {
×
133
                cellItem.add(new NanodashLink(componentId, e.type));
×
134
            } else {
135
                String v = e.getValue(title);
×
136
                cellItem.add(new Label(componentId, v));
×
137
                try {
138
                    int i = Integer.parseInt(v);
×
139
                    if (i >= 100) {
×
140
                        cellItem.add(new AttributeAppender("class", " high"));
×
141
                    } else if (i >= 10) {
×
142
                        cellItem.add(new AttributeAppender("class", " med"));
×
143
                    } else if (i >= 1) {
×
144
                        cellItem.add(new AttributeAppender("class", " low"));
×
145
                    }
146
                } catch (NumberFormatException ex) {
×
147
                }
×
148
            }
149
        }
×
150

151
    }
152

153
    private class EntityProvider implements IDataProvider<Entity> {
154

155
        private static final long serialVersionUID = 1L;
156

157
        private List<Entity> list;
158

159
        /**
160
         * Constructor for EntityProvider.
161
         *
162
         * @param list the list of Entity objects to provide
163
         */
164
        public EntityProvider(List<Entity> list) {
×
165
            this.list = list;
×
166
        }
×
167

168
        @Override
169
        public Iterator<? extends Entity> iterator(long first, long count) {
170
            return Utils.subList(list, first, first + count).iterator();
×
171
        }
172

173
        @Override
174
        public long size() {
175
            return list.size();
×
176
        }
177

178
        @Override
179
        public IModel<Entity> model(Entity object) {
180
            return new Model<Entity>(object);
×
181
        }
182

183
    }
184

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