1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.rssaggregator.templates.components;
35
36 import info.magnolia.jcr.util.ContentMap;
37 import info.magnolia.rendering.model.RenderingModel;
38 import info.magnolia.rendering.template.TemplateDefinition;
39 import info.magnolia.templating.functions.TemplatingFunctions;
40
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.List;
44
45 import javax.jcr.Node;
46 import javax.jcr.RepositoryException;
47
48
49
50
51
52
53 public class FeedStatisticsModel<RD extends TemplateDefinition> extends AbstractFeedModel<TemplateDefinition> {
54
55 private static final String DEFAULT_STATISTIC = "authors";
56
57 public FeedStatisticsModel(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
58 super(content, definition, parent, templatingFunctions);
59 }
60
61 @Override
62 public String execute() {
63 return super.execute();
64 }
65
66
67
68
69
70
71 private String getStatistic() {
72 String statistic = DEFAULT_STATISTIC;
73
74 try {
75 if (content.hasProperty("statistic")) {
76 statistic = content.getProperty("statistic").getString();
77 }
78 } catch (RepositoryException e) {
79 log.error("Problem while getting statistic type: " + e.getMessage());
80 }
81 return statistic;
82 }
83
84
85
86
87
88
89 public Collection<ContentMap> getEntries() {
90 Collection<Node> items = super.getPlanetItems("statistics/" + getStatistic(), "and t.postCount > 0", "order by t.postCount desc, t.author asc", true);
91 List<ContentMap> wrappers = new ArrayList<>();
92 for (Node node : items) {
93 wrappers.add(new ContentMap(node));
94 }
95 return wrappers;
96 }
97 }