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

knowledgepixels / nanodash / 18188189824

02 Oct 2025 08:50AM UTC coverage: 13.724% (-0.4%) from 14.135%
18188189824

push

github

tkuhn
feat(ActivityPanel): Show activity panel on user pages

446 of 4114 branches covered (10.84%)

Branch coverage included in aggregate %.

1155 of 7552 relevant lines covered (15.29%)

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
                if (!v.isBlank()) {
×
123
                    try {
124
                        int i = Integer.parseInt(v);
×
125
                        if (i >= 100) {
×
126
                            cellItem.add(new AttributeAppender("class", " high"));
×
127
                        } else if (i >= 10) {
×
128
                            cellItem.add(new AttributeAppender("class", " med"));
×
129
                        } else if (i >= 1) {
×
130
                            cellItem.add(new AttributeAppender("class", " low"));
×
131
                        }
132
                    } catch (NumberFormatException ex) {
×
133
                        logger.error("Error in parsing integer from value: {}", v, ex);
×
134
                    }
×
135
                }
136
            }
137
        }
×
138
    }
139

140
    private class EntityProvider implements IDataProvider<Entity> {
141

142
        private List<Entity> list;
143

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

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

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

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

168
    }
169

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