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.util.QueryUtil; |
37 |
|
import info.magnolia.context.MgnlContext; |
38 |
|
import info.magnolia.dam.templating.functions.DamTemplatingFunctions; |
39 |
|
import info.magnolia.jcr.util.SessionUtil; |
40 |
|
import info.magnolia.module.rssaggregator.RSSAggregatorConstants; |
41 |
|
import info.magnolia.module.rssaggregator.util.PagerUtil; |
42 |
|
import info.magnolia.module.rssaggregator.util.PlanetUtil; |
43 |
|
import info.magnolia.rendering.model.RenderingModel; |
44 |
|
import info.magnolia.rendering.template.TemplateDefinition; |
45 |
|
import info.magnolia.templating.functions.TemplatingFunctions; |
46 |
|
|
47 |
|
import java.util.ArrayList; |
48 |
|
import java.util.Collection; |
49 |
|
import java.util.Collections; |
50 |
|
import java.util.Comparator; |
51 |
|
import java.util.Date; |
52 |
|
import java.util.List; |
53 |
|
|
54 |
|
import javax.inject.Inject; |
55 |
|
import javax.jcr.Node; |
56 |
|
import javax.jcr.NodeIterator; |
57 |
|
import javax.jcr.RepositoryException; |
58 |
|
|
59 |
|
import org.apache.commons.lang.StringUtils; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 64 (64) |
Complexity: 19 |
Complexity Density: 0.42 |
|
67 |
|
public class PlanetFeedModel<RD extends TemplateDefinition> extends AbstractFeedModel<TemplateDefinition> { |
68 |
|
|
69 |
|
private static final String ARCHIVE_NODE = "planetData"; |
70 |
|
private static final String DATE_PROPERTY = "pubDate"; |
71 |
|
private final DamTemplatingFunctions damTemplatingFunction; |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
73 |
0 |
@Inject... |
74 |
|
public PlanetFeedModel(Node content, RD definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions, DamTemplatingFunctions damTemplatingFunction) { |
75 |
0 |
super(content, definition, parent, templatingFunctions); |
76 |
0 |
this.damTemplatingFunction = damTemplatingFunction; |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
@Override... |
80 |
|
public String execute() { |
81 |
0 |
return "success"; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
84 |
0 |
public PagerUtil getPager() throws RepositoryException {... |
85 |
0 |
PagerUtil pager = null; |
86 |
0 |
Collection<Node> listItems = getItems(); |
87 |
0 |
if (!listItems.isEmpty()) { |
88 |
|
|
89 |
0 |
final String currentPageLink; |
90 |
0 |
if (MgnlContext.isWebContext() && MgnlContext.getAggregationState() != null) { |
91 |
0 |
currentPageLink = MgnlContext.getAggregationState().getOriginalURL(); |
92 |
|
} else { |
93 |
0 |
currentPageLink = templatingFunctions.link(MgnlContext.getAggregationState().getMainContent().getJCRNode()); |
94 |
|
} |
95 |
|
|
96 |
0 |
pager = new PagerUtil(currentPageLink, listItems, content); |
97 |
|
} |
98 |
0 |
return pager; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
101 |
0 |
public Collection<Node> getItems() {... |
102 |
0 |
List<Node> listItems = new ArrayList<Node>(); |
103 |
|
|
104 |
0 |
try { |
105 |
0 |
if (content.hasProperty("link")) { |
106 |
0 |
Node rssParent = SessionUtil.getNode(RSSAggregatorConstants.WORKSPACE, content.getProperty("link").getString()); |
107 |
|
|
108 |
0 |
String sql2 = "select * from [mgnl:content] as t where ISDESCENDANTNODE([" + rssParent.getPath() + "/" + ARCHIVE_NODE |
109 |
|
+ "]) and t.hidden = 'false'"; |
110 |
|
|
111 |
0 |
NodeIterator nit = QueryUtil.search(RSSAggregatorConstants.WORKSPACE, sql2); |
112 |
0 |
while (nit.hasNext()) { |
113 |
0 |
Node post = nit.nextNode(); |
114 |
0 |
listItems.add(post); |
115 |
|
} |
116 |
0 |
sort(listItems); |
117 |
|
} else { |
118 |
0 |
log.info("No feed specified for planet feeds."); |
119 |
|
} |
120 |
|
} catch (Exception e) { |
121 |
0 |
log.error("Problem while retrieving post items: " + e.getMessage()); |
122 |
|
} |
123 |
0 |
return listItems; |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
protected void sort(Collection<Node> listItems) {... |
127 |
0 |
Collections.sort((List<Node>) listItems, new Comparator<Node>() { |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
129 |
0 |
@Override... |
130 |
|
public int compare(Node n1, Node n2) { |
131 |
0 |
try { |
132 |
0 |
Date d1 = n1.getProperty(DATE_PROPERTY).getDate().getTime(); |
133 |
0 |
Date d2 = n2.getProperty(DATE_PROPERTY).getDate().getTime(); |
134 |
|
|
135 |
0 |
return d2.compareTo(d1); |
136 |
|
} catch (RepositoryException e) { |
137 |
0 |
log.error("Problem while sorting posts: " + e.getMessage()); |
138 |
|
} |
139 |
0 |
return 0; |
140 |
|
} |
141 |
|
}); |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0 |
public String getDescription(String entryDescription, Integer abbreviation) {... |
145 |
0 |
return PlanetUtil.formatDescription(entryDescription, abbreviation); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@param |
152 |
|
@return |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
154 |
0 |
public String getHackergotchi(String feedLink) {... |
155 |
0 |
try { |
156 |
0 |
Node rssParent = SessionUtil.getNode(RSSAggregatorConstants.WORKSPACE, content.getProperty("link").getString()); |
157 |
0 |
String assetId = getFeedProperty(rssParent, FEEDS_NODE, "link", feedLink, "img"); |
158 |
0 |
if (!StringUtils.isBlank(assetId)) { |
159 |
0 |
return damTemplatingFunction.getAssetLink(assetId); |
160 |
|
} |
161 |
|
} catch (RepositoryException e) { |
162 |
0 |
log.error("Problem while fetching Hackergotchi: " + e.getMessage()); |
163 |
|
} |
164 |
0 |
return null; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
@return |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
173 |
0 |
@Override... |
174 |
|
public String getFeedTitle(String feedLink) { |
175 |
0 |
try { |
176 |
0 |
Node rssParent = SessionUtil.getNode(RSSAggregatorConstants.WORKSPACE, content.getProperty("link").getString()); |
177 |
0 |
return getFeedProperty(rssParent, "feeds", "link", feedLink, "title"); |
178 |
|
} catch (RepositoryException e) { |
179 |
0 |
log.error("Problem while fetching feed title for the main planet feed: " + e.getMessage()); |
180 |
|
} |
181 |
0 |
return null; |
182 |
|
} |
183 |
|
|
184 |
|
} |