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

knowledgepixels / nanodash / 17581065640

09 Sep 2025 11:22AM UTC coverage: 13.608% (-0.1%) from 13.73%
17581065640

push

github

ashleycaselli
chore: add error logging for exception handling in various components

406 of 3854 branches covered (10.53%)

Branch coverage included in aggregate %.

1072 of 7007 relevant lines covered (15.3%)

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

3
import com.knowledgepixels.nanodash.Utils;
4
import org.apache.wicket.behavior.AttributeAppender;
5
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
6
import org.apache.wicket.extensions.markup.html.repeater.data.table.*;
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.IDataProvider;
11
import org.apache.wicket.model.IModel;
12
import org.apache.wicket.model.Model;
13
import org.nanopub.extra.services.ApiResponse;
14
import org.nanopub.extra.services.ApiResponseEntry;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import java.io.Serializable;
19
import java.time.Year;
20
import java.util.*;
21

22
/**
23
 * A panel that displays activity data in a table format.
24
 * It shows the number of nanopublications per type and month.
25
 */
26
public class ActivityPanel extends Panel {
27

28
    private static final long serialVersionUID = 1L;
29

30
    private Map<String, Map<String, String>> typeMonthValueMap = new HashMap<>();
×
31
    private final Logger logger = LoggerFactory.getLogger(ActivityPanel.class);
×
32

33
    /**
34
     * Constructor for ActivityPanel.
35
     *
36
     * @param markupId the Wicket markup ID for this panel
37
     * @param response the ApiResponse containing activity data
38
     */
39
    public ActivityPanel(String markupId, ApiResponse response) {
40
        super(markupId);
×
41
        setOutputMarkupId(true);
×
42

43
        List<Entity> list = new ArrayList<>();
×
44
        Set<String> types = new HashSet<>();
×
45
        for (ApiResponseEntry e : response.getData()) {
×
46
            String type = e.get("type");
×
47
            if (!types.contains(type)) {
×
48
                list.add(new Entity(type));
×
49
                types.add(type);
×
50
            }
51
            if (!typeMonthValueMap.containsKey(type)) {
×
52
                typeMonthValueMap.put(type, new HashMap<>());
×
53
            }
54
            typeMonthValueMap.get(type).put(e.get("month"), e.get("npCount"));
×
55
        }
×
56

57
        final Calendar calendar = Calendar.getInstance();
×
58
        int year = Year.now().getValue() - 1;
×
59
        int month = calendar.get(Calendar.MONTH) + 1;
×
60

61
        List<IColumn<Entity, String>> columns = new ArrayList<>();
×
62
        columns.add(new Column("type"));
×
63

64
        int count = 0;
×
65
        while (count < 12) {
×
66
            month++;
×
67
            if (month == 13) {
×
68
                year++;
×
69
                month = 1;
×
70
            }
71
            columns.add(new Column(formatYearMonth(year, month)));
×
72
            count++;
×
73
        }
74

75
        DataTable<Entity, String> table = new DataTable<Entity, String>("table", columns, new EntityProvider(list), 10);
×
76
        table.addBottomToolbar(new NavigationToolbar(table));
×
77
        table.addTopToolbar(new HeadersToolbar<String>(table, null));
×
78
        table.setOutputMarkupId(true);
×
79
        add(table);
×
80
    }
×
81

82
    private static String formatYearMonth(int year, int month) {
83
        return year + "-" + (month > 9 ? "" + month : "0" + month);
×
84
    }
85

86
    private class Entity implements Serializable {
87

88
        private static final long serialVersionUID = 1L;
89

90
        public String type;
91

92
        public Entity(String type) {
×
93
            this.type = type;
×
94
        }
×
95

96
        public String getValue(String month) {
97
            if (!typeMonthValueMap.containsKey(type)) return "";
×
98
            if (!typeMonthValueMap.get(type).containsKey(month)) return "";
×
99
            return typeMonthValueMap.get(type).get(month);
×
100
        }
101

102
    }
103

104
    private class Column extends AbstractColumn<Entity, String> {
105

106
        private static final long serialVersionUID = 1L;
107

108
        private String title;
109

110
        public Column(String title) {
111
            this(new Model<String>(title));
×
112
        }
×
113

114
        public Column(Model<String> titleModel) {
×
115
            super(titleModel);
×
116
            this.title = titleModel.getObject();
×
117
            titleModel.setObject(titleModel.getObject().replaceFirst("^20", ""));
×
118
        }
×
119

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

144
    private class EntityProvider implements IDataProvider<Entity> {
145

146
        private static final long serialVersionUID = 1L;
147

148
        private List<Entity> list;
149

150
        /**
151
         * Constructor for EntityProvider.
152
         *
153
         * @param list the list of Entity objects to provide
154
         */
155
        public EntityProvider(List<Entity> list) {
×
156
            this.list = list;
×
157
        }
×
158

159
        @Override
160
        public Iterator<? extends Entity> iterator(long first, long count) {
161
            return Utils.subList(list, first, first + count).iterator();
×
162
        }
163

164
        @Override
165
        public long size() {
166
            return list.size();
×
167
        }
168

169
        @Override
170
        public IModel<Entity> model(Entity object) {
171
            return new Model<Entity>(object);
×
172
        }
173

174
    }
175

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