1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.feed; |
21 |
|
|
22 |
|
import java.util.Date; |
23 |
|
|
24 |
|
import org.xwiki.context.Execution; |
25 |
|
import org.xwiki.context.ExecutionContext; |
26 |
|
|
27 |
|
import com.xpn.xwiki.XWikiContext; |
28 |
|
import com.xpn.xwiki.XWikiException; |
29 |
|
import com.xpn.xwiki.util.AbstractXWikiRunnable; |
30 |
|
import com.xpn.xwiki.web.Utils; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 77 (77) |
Complexity: 24 |
Complexity Density: 0.47 |
|
32 |
|
public class UpdateThread extends AbstractXWikiRunnable |
33 |
|
{ |
34 |
|
protected boolean fullContent; |
35 |
|
|
36 |
|
protected String space; |
37 |
|
|
38 |
|
protected FeedPlugin feedPlugin; |
39 |
|
|
40 |
|
protected int scheduleTimer; |
41 |
|
|
42 |
|
protected boolean updateInProgress = false; |
43 |
|
|
44 |
|
protected boolean forceUpdate = false; |
45 |
|
|
46 |
|
protected boolean stopUpdate = false; |
47 |
|
|
48 |
|
protected Date startDate; |
49 |
|
|
50 |
|
protected Date endDate; |
51 |
|
|
52 |
|
protected int nbLoadedArticles; |
53 |
|
|
54 |
|
protected int nbLoadedFeeds; |
55 |
|
|
56 |
|
protected int nbLoadedFeedsErrors; |
57 |
|
|
58 |
|
protected Exception exception; |
59 |
|
|
60 |
|
private XWikiContext xwikiContext; |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
62 |
0 |
public UpdateThread(String spaceReference, boolean fullContent, int scheduleTimer, FeedPlugin feedPlugin,... |
63 |
|
XWikiContext context) |
64 |
|
{ |
65 |
0 |
this.xwikiContext = context.clone(); |
66 |
0 |
this.fullContent = fullContent; |
67 |
0 |
this.space = spaceReference; |
68 |
0 |
this.feedPlugin = feedPlugin; |
69 |
0 |
this.scheduleTimer = scheduleTimer; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
72 |
0 |
@Override... |
73 |
|
protected void declareProperties(ExecutionContext executionContext) |
74 |
|
{ |
75 |
0 |
xwikiContext.declareInExecutionContext(executionContext); |
76 |
0 |
xwikiContext = null; |
77 |
|
} |
78 |
|
|
79 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 6 |
Complexity Density: 0.27 |
|
80 |
0 |
public void update()... |
81 |
|
{ |
82 |
0 |
if (!stopUpdate) { |
83 |
0 |
if (updateInProgress == false) { |
84 |
0 |
updateInProgress = true; |
85 |
0 |
nbLoadedFeeds = 0; |
86 |
0 |
nbLoadedFeedsErrors = 0; |
87 |
0 |
exception = null; |
88 |
0 |
nbLoadedArticles = 0; |
89 |
0 |
endDate = null; |
90 |
0 |
startDate = new Date(); |
91 |
0 |
XWikiContext context = getXWikiContext(); |
92 |
0 |
try { |
93 |
|
|
94 |
0 |
context.getWiki().getStore().cleanUp(context); |
95 |
|
|
96 |
0 |
nbLoadedArticles = feedPlugin.updateFeedsInSpace(space, fullContent, true, false, context); |
97 |
|
} catch (XWikiException e) { |
98 |
0 |
exception = e; |
99 |
0 |
e.printStackTrace(); |
100 |
|
} finally { |
101 |
0 |
updateInProgress = false; |
102 |
0 |
endDate = new Date(); |
103 |
0 |
context.getWiki().getStore().cleanUp(context); |
104 |
|
} |
105 |
|
|
106 |
0 |
if ((forceUpdate == true) && (stopUpdate == false)) { |
107 |
0 |
forceUpdate = false; |
108 |
0 |
update(); |
109 |
|
} |
110 |
|
} else { |
111 |
|
|
112 |
0 |
forceUpdate = true; |
113 |
|
} |
114 |
|
} |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
private XWikiContext getXWikiContext()... |
118 |
|
{ |
119 |
0 |
return (XWikiContext) Utils.getComponent(Execution.class).getContext().getProperty("xwikicontext"); |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
public String getSpace()... |
123 |
|
{ |
124 |
0 |
return space; |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
0 |
public boolean isUpdateInProgress()... |
128 |
|
{ |
129 |
0 |
return updateInProgress; |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0 |
public Date getStartDate()... |
133 |
|
{ |
134 |
0 |
return startDate; |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
public Date getEndDate()... |
138 |
|
{ |
139 |
0 |
return endDate; |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0 |
public int getNbLoadedArticles()... |
143 |
|
{ |
144 |
0 |
return nbLoadedArticles; |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
0 |
public Exception getException()... |
148 |
|
{ |
149 |
0 |
return exception; |
150 |
|
} |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
152 |
0 |
public void stopUpdate()... |
153 |
|
{ |
154 |
0 |
if (!updateInProgress) { |
155 |
0 |
feedPlugin.removeUpdateThread(space, this, getXWikiContext()); |
156 |
|
} |
157 |
0 |
stopUpdate = true; |
158 |
|
} |
159 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
0 |
public int getNbLoadedFeeds()... |
161 |
|
{ |
162 |
0 |
return nbLoadedFeeds; |
163 |
|
} |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
0 |
public void setNbLoadedFeeds(int nbLoadedFeeds)... |
166 |
|
{ |
167 |
0 |
this.nbLoadedFeeds = nbLoadedFeeds; |
168 |
|
} |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
0 |
public int getNbLoadedFeedsErrors()... |
171 |
|
{ |
172 |
0 |
return nbLoadedFeedsErrors; |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
public void setNbLoadedFeedsErrors(int nbLoadedFeedsErrors)... |
176 |
|
{ |
177 |
0 |
this.nbLoadedFeedsErrors = nbLoadedFeedsErrors; |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
180 |
0 |
@Override... |
181 |
|
protected void runInternal() |
182 |
|
{ |
183 |
0 |
while (true) { |
184 |
0 |
update(); |
185 |
0 |
if (stopUpdate) { |
186 |
0 |
feedPlugin.removeUpdateThread(space, this, getXWikiContext()); |
187 |
0 |
break; |
188 |
|
} |
189 |
0 |
try { |
190 |
0 |
Thread.sleep(scheduleTimer); |
191 |
|
} catch (InterruptedException e) { |
192 |
0 |
break; |
193 |
|
} |
194 |
|
} |
195 |
|
} |
196 |
|
} |