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 public class FeedStatisticsModel<RD extends TemplateDefinition> extends AbstractFeedModel<TemplateDefinition> {
57
58 private static final String DEFAULT_STATISTIC = "authors";
59
60 public FeedStatisticsModel(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
61 super(content, definition, parent, templatingFunctions);
62 }
63
64 @Override
65 public String execute() {
66 return super.execute();
67 }
68
69
70
71
72
73
74 private String getStatistic() {
75 String statistic = DEFAULT_STATISTIC;
76
77 try {
78 if (content.hasProperty("statistic")) {
79 statistic = content.getProperty("statistic").getString();
80 }
81 } catch (RepositoryException e) {
82 log.error("Problem while getting statistic type: " + e.getMessage());
83 }
84 return statistic;
85 }
86
87
88
89
90
91
92 public Collection<ContentWrapper> getItems() {
93 Collection<Node> items = super.getPlanetItems("statistics/" + getStatistic(), "and t.postCount > 0", "order by t.postCount desc, t.author asc", true);
94 List<ContentWrapper> wrappers = new ArrayList<ContentWrapper>();
95 for (Node node : items) {
96 Content content = ContentUtil.asContent(node);
97 wrappers.add(new NodeMapWrapper(content, content.getHandle()));
98 }
99 return wrappers;
100 }
101
102 }