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.cms.core.Content;
37 import info.magnolia.cms.util.ContentUtil;
38 import info.magnolia.cms.util.ContentWrapper;
39 import info.magnolia.cms.util.NodeMapWrapper;
40 import info.magnolia.rendering.model.RenderingModel;
41 import info.magnolia.rendering.template.TemplateDefinition;
42 import info.magnolia.templating.functions.TemplatingFunctions;
43
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.List;
47
48 import javax.jcr.Node;
49 import javax.jcr.RepositoryException;
50
51
52
53
54
55
56
57 public class FeedStatisticsModel<RD extends TemplateDefinition> extends AbstractFeedModel<TemplateDefinition> {
58
59 private static final String DEFAULT_STATISTIC = "authors";
60
61 public FeedStatisticsModel(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
62 super(content, definition, parent, templatingFunctions);
63 }
64
65 @Override
66 public String execute() {
67 return super.execute();
68 }
69
70
71
72
73
74
75 private String getStatistic() {
76 String statistic = DEFAULT_STATISTIC;
77
78 try {
79 if (content.hasProperty("statistic")) {
80 statistic = content.getProperty("statistic").getString();
81 }
82 } catch (RepositoryException e) {
83 log.error("Problem while getting statistic type: " + e.getMessage());
84 }
85 return statistic;
86 }
87
88
89
90
91
92
93 public Collection<ContentWrapper> getItems() {
94 Collection<Node> items = super.getPlanetItems("statistics/" + getStatistic(), "and t.postCount > 0", "order by t.postCount desc, t.author asc", true);
95 List<ContentWrapper> wrappers = new ArrayList<ContentWrapper>();
96 for (Node node : items) {
97 Content content = ContentUtil.asContent(node);
98 wrappers.add(new NodeMapWrapper(content, content.getHandle()));
99 }
100 return wrappers;
101 }
102
103 }