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.pages; |
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.pages.PageHistoryResource; |
38 |
|
|
39 |
|
import com.xpn.xwiki.doc.rcs.XWikiRCSNodeId; |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("org.xwiki.rest.internal.resources.pages.PageHistoryResourceImpl") |
|
|
| 94.7% |
Uncovered Elements: 1 (19) |
Complexity: 2 |
Complexity Density: 0.11 |
|
46 |
|
public class PageHistoryResourceImpl extends XWikiResource implements PageHistoryResource |
47 |
|
{ |
|
|
| 94.4% |
Uncovered Elements: 1 (18) |
Complexity: 2 |
Complexity Density: 0.11 |
|
48 |
7 |
@Override... |
49 |
|
public History getPageHistory(String wikiName, String spaceName, String pageName, Integer start, Integer number, |
50 |
|
String order, Boolean withPrettyNames) throws XWikiRestException |
51 |
|
{ |
52 |
7 |
List<String> spaces = parseSpaceSegments(spaceName); |
53 |
7 |
String spaceId = Utils.getLocalSpaceId(spaces); |
54 |
|
|
55 |
7 |
History history = new History(); |
56 |
|
|
57 |
7 |
try { |
58 |
|
|
59 |
7 |
String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" |
60 |
|
+ " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" |
61 |
|
+ " doc.space = :space and doc.name = :name and (doc.language = '' or doc.language is null)" |
62 |
|
+ " order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order); |
63 |
|
|
64 |
7 |
List<Object> queryResult = null; |
65 |
7 |
queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("space", spaceId).bindValue("name", |
66 |
|
pageName).setLimit(number).setOffset(start).setWiki(wikiName).execute(); |
67 |
|
|
68 |
7 |
for (Object object : queryResult) { |
69 |
7 |
Object[] fields = (Object[]) object; |
70 |
|
|
71 |
7 |
XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2]; |
72 |
7 |
Timestamp timestamp = (Timestamp) fields[3]; |
73 |
7 |
Date modified = new Date(timestamp.getTime()); |
74 |
7 |
String modifier = (String) fields[4]; |
75 |
7 |
String comment = (String) fields[5]; |
76 |
|
|
77 |
7 |
HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, |
78 |
|
uriInfo.getBaseUri(), wikiName, spaces, pageName, null, nodeId.getVersion(), modifier, |
79 |
|
modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames); |
80 |
|
|
81 |
7 |
history.getHistorySummaries().add(historySummary); |
82 |
|
} |
83 |
|
} catch (QueryException e) { |
84 |
0 |
throw new XWikiRestException(e); |
85 |
|
} |
86 |
|
|
87 |
7 |
return history; |
88 |
|
} |
89 |
|
} |