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

knowledgepixels / nanodash / 17837235071

18 Sep 2025 05:58PM UTC coverage: 13.87%. Remained the same
17837235071

push

github

tkuhn
chore: Remove serialVersionUIDs

443 of 4022 branches covered (11.01%)

Branch coverage included in aggregate %.

1133 of 7341 relevant lines covered (15.43%)

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 Map<String, Map<String, String>> typeMonthValueMap = new HashMap<>();
×
29
    private final Logger logger = LoggerFactory.getLogger(ActivityPanel.class);
×
30

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

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

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

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

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

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

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

84
    private class Entity implements Serializable {
85

86
        public String type;
87

88
        public Entity(String type) {
×
89
            this.type = type;
×
90
        }
×
91

92
        public String getValue(String month) {
93
            if (!typeMonthValueMap.containsKey(type)) return "";
×
94
            if (!typeMonthValueMap.get(type).containsKey(month)) return "";
×
95
            return typeMonthValueMap.get(type).get(month);
×
96
        }
97

98
    }
99

100
    private class Column extends AbstractColumn<Entity, String> {
101

102
        private String title;
103

104
        public Column(String title) {
105
            this(new Model<String>(title));
×
106
        }
×
107

108
        public Column(Model<String> titleModel) {
×
109
            super(titleModel);
×
110
            this.title = titleModel.getObject();
×
111
            titleModel.setObject(titleModel.getObject().replaceFirst("^20", ""));
×
112
        }
×
113

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

138
    private class EntityProvider implements IDataProvider<Entity> {
139

140
        private List<Entity> list;
141

142
        /**
143
         * Constructor for EntityProvider.
144
         *
145
         * @param list the list of Entity objects to provide
146
         */
147
        public EntityProvider(List<Entity> list) {
×
148
            this.list = list;
×
149
        }
×
150

151
        @Override
152
        public Iterator<? extends Entity> iterator(long first, long count) {
153
            return Utils.subList(list, first, first + count).iterator();
×
154
        }
155

156
        @Override
157
        public long size() {
158
            return list.size();
×
159
        }
160

161
        @Override
162
        public IModel<Entity> model(Entity object) {
163
            return new Model<Entity>(object);
×
164
        }
165

166
    }
167

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