1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal.resources; |
21 |
|
|
22 |
|
import java.sql.Timestamp; |
23 |
|
import java.util.Date; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import javax.inject.Named; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.query.Query; |
30 |
|
import org.xwiki.query.QueryException; |
31 |
|
import org.xwiki.rest.XWikiResource; |
32 |
|
import org.xwiki.rest.XWikiRestException; |
33 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
34 |
|
import org.xwiki.rest.internal.Utils; |
35 |
|
import org.xwiki.rest.model.jaxb.History; |
36 |
|
import org.xwiki.rest.model.jaxb.HistorySummary; |
37 |
|
import org.xwiki.rest.resources.ModificationsResource; |
38 |
|
|
39 |
|
import com.xpn.xwiki.doc.rcs.XWikiRCSNodeId; |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("org.xwiki.rest.internal.resources.ModificationsResourceImpl") |
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
|
46 |
|
public class ModificationsResourceImpl extends XWikiResource implements ModificationsResource |
47 |
|
{ |
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 3 |
Complexity Density: 0.14 |
|
48 |
1 |
@Override... |
49 |
|
public History getModifications(String wikiName, Integer start, Integer number, String order, Long ts, |
50 |
|
Boolean withPrettyNames) throws XWikiRestException |
51 |
|
{ |
52 |
1 |
try { |
53 |
1 |
History history = new History(); |
54 |
|
|
55 |
1 |
String query = String.format("select doc.space, doc.name, doc.language, rcs.id, rcs.date, rcs.author," |
56 |
|
+ " rcs.comment from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" |
57 |
|
+ " rcs.date > :date order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", |
58 |
|
order, order, order); |
59 |
|
|
60 |
1 |
List<Object> queryResult = null; |
61 |
1 |
queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("date", new Date(ts)).setLimit(number) |
62 |
|
.setOffset(start).setWiki(wikiName).execute(); |
63 |
|
|
64 |
1 |
for (Object object : queryResult) { |
65 |
25 |
Object[] fields = (Object[]) object; |
66 |
|
|
67 |
25 |
String spaceId = (String) fields[0]; |
68 |
25 |
List<String> spaces = Utils.getSpacesFromSpaceId(spaceId); |
69 |
25 |
String pageName = (String) fields[1]; |
70 |
25 |
String language = (String) fields[2]; |
71 |
25 |
if (language.equals("")) { |
72 |
25 |
language = null; |
73 |
|
} |
74 |
25 |
XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[3]; |
75 |
25 |
Timestamp timestamp = (Timestamp) fields[4]; |
76 |
25 |
Date modified = new Date(timestamp.getTime()); |
77 |
25 |
String modifier = (String) fields[5]; |
78 |
25 |
String comment = (String) fields[6]; |
79 |
|
|
80 |
25 |
HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, |
81 |
|
uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, |
82 |
|
modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames); |
83 |
|
|
84 |
25 |
history.getHistorySummaries().add(historySummary); |
85 |
|
} |
86 |
|
|
87 |
1 |
return history; |
88 |
|
} catch (QueryException e) { |
89 |
0 |
throw new XWikiRestException(e); |
90 |
|
} |
91 |
|
} |
92 |
|
} |