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

knowledgepixels / nanodash / 17319343703

29 Aug 2025 08:53AM UTC coverage: 12.007% (-0.3%) from 12.355%
17319343703

push

github

tkuhn
Fix forcedGet(...) also catching RuntimeExceptions

330 of 3844 branches covered (8.58%)

Branch coverage included in aggregate %.

949 of 6808 relevant lines covered (13.94%)

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
/**
31
 * A panel that displays activity data in a table format.
32
 * It shows the number of nanopublications per type and month.
33
 */
34
public class ActivityPanel extends Panel {
35

36
    private static final long serialVersionUID = 1L;
37

38
    private Map<String, Map<String, String>> typeMonthValueMap = new HashMap<>();
×
39

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

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

63
        final Calendar calendar = Calendar.getInstance();
×
64
        int year = Year.now().getValue() - 1;
×
65
        int month = calendar.get(Calendar.MONTH) + 1;
×
66

67
        List<IColumn<Entity, String>> columns = new ArrayList<>();
×
68
        columns.add(new Column("type"));
×
69

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

81
        DataTable<Entity, String> table = new DataTable<Entity, String>("table", columns, new EntityProvider(list), 10);
×
82
        table.addBottomToolbar(new NavigationToolbar(table));
×
83
        table.addTopToolbar(new HeadersToolbar<String>(table, null));
×
84
        add(table);
×
85
    }
×
86

87
    private static String formatYearMonth(int year, int month) {
88
        return year + "-" + (month > 9 ? "" + month : "0" + month);
×
89
    }
90

91
    private class Entity implements Serializable {
92

93
        private static final long serialVersionUID = 1L;
94

95
        public String type;
96

97
        public Entity(String type) {
×
98
            this.type = type;
×
99
        }
×
100

101
        public String getValue(String month) {
102
            if (!typeMonthValueMap.containsKey(type)) return "";
×
103
            if (!typeMonthValueMap.get(type).containsKey(month)) return "";
×
104
            return typeMonthValueMap.get(type).get(month);
×
105
        }
106

107
    }
108

109
    private class Column extends AbstractColumn<Entity, String> {
110

111
        private static final long serialVersionUID = 1L;
112

113
        private String title;
114

115
        public Column(String title) {
116
            this(new Model<String>(title));
×
117
        }
×
118

119
        public Column(Model<String> titleModel) {
×
120
            super(titleModel);
×
121
            this.title = titleModel.getObject();
×
122
            titleModel.setObject(titleModel.getObject().replaceFirst("^20", ""));
×
123
        }
×
124

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

147
    }
148

149
    private class EntityProvider implements IDataProvider<Entity> {
150

151
        private static final long serialVersionUID = 1L;
152

153
        private List<Entity> list;
154

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

164
        @Override
165
        public Iterator<? extends Entity> iterator(long first, long count) {
166
            return list.iterator();
×
167
        }
168

169
        @Override
170
        public long size() {
171
            return list.size();
×
172
        }
173

174
        @Override
175
        public IModel<Entity> model(Entity object) {
176
            return new Model<Entity>(object);
×
177
        }
178

179
    }
180

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