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.attachments; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import javax.inject.Named; |
27 |
|
import javax.ws.rs.WebApplicationException; |
28 |
|
import javax.ws.rs.core.Response.Status; |
29 |
|
|
30 |
|
import org.suigeneris.jrcs.rcs.Version; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.rest.XWikiResource; |
33 |
|
import org.xwiki.rest.XWikiRestException; |
34 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
35 |
|
import org.xwiki.rest.internal.RangeIterable; |
36 |
|
import org.xwiki.rest.internal.Utils; |
37 |
|
import org.xwiki.rest.model.jaxb.Attachments; |
38 |
|
import org.xwiki.rest.resources.attachments.AttachmentHistoryResource; |
39 |
|
|
40 |
|
import com.xpn.xwiki.XWikiException; |
41 |
|
import com.xpn.xwiki.api.Document; |
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("org.xwiki.rest.internal.resources.attachments.AttachmentHistoryResourceImpl") |
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 3 |
Complexity Density: 0.15 |
|
48 |
|
public class AttachmentHistoryResourceImpl extends XWikiResource implements AttachmentHistoryResource |
49 |
|
{ |
|
|
| 86.4% |
Uncovered Elements: 3 (22) |
Complexity: 3 |
Complexity Density: 0.15 |
|
50 |
1 |
@Override... |
51 |
|
public Attachments getAttachmentHistory(String wikiName, String spaceName, String pageName, String attachmentName, |
52 |
|
Integer start, Integer number) throws XWikiRestException |
53 |
|
{ |
54 |
1 |
try { |
55 |
1 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
56 |
1 |
Document doc = documentInfo.getDocument(); |
57 |
|
|
58 |
1 |
final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName); |
59 |
1 |
if (xwikiAttachment == null) { |
60 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
61 |
|
} |
62 |
|
|
63 |
1 |
Attachments attachments = new Attachments(); |
64 |
|
|
65 |
1 |
Version[] versions = xwikiAttachment.getVersions(); |
66 |
1 |
List<Version> versionList = new ArrayList<Version>(); |
67 |
1 |
for (Version version : versions) { |
68 |
4 |
versionList.add(version); |
69 |
|
} |
70 |
|
|
71 |
1 |
RangeIterable<Version> ri = new RangeIterable<Version>(versionList, start, number); |
72 |
|
|
73 |
1 |
for (Version version : ri) { |
74 |
4 |
com.xpn.xwiki.api.Attachment xwikiAttachmentAtVersion = |
75 |
|
xwikiAttachment.getAttachmentRevision(version.toString()); |
76 |
|
|
77 |
4 |
URL url = |
78 |
|
Utils.getXWikiContext(componentManager).getURLFactory() |
79 |
|
.createAttachmentRevisionURL(attachmentName, |
80 |
|
spaceName, doc.getName(), version.toString(), null, wikiName, |
81 |
|
Utils.getXWikiContext(componentManager)); |
82 |
4 |
String attachmentXWikiAbsoluteUrl = url.toString(); |
83 |
4 |
String attachmentXWikiRelativeUrl = |
84 |
|
Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, |
85 |
|
Utils.getXWikiContext(componentManager)); |
86 |
|
|
87 |
4 |
attachments.getAttachments().add( |
88 |
|
DomainObjectFactory.createAttachmentAtVersion(objectFactory, uriInfo.getBaseUri(), |
89 |
|
xwikiAttachmentAtVersion, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, |
90 |
|
Utils.getXWikiApi(componentManager), false)); |
91 |
|
} |
92 |
|
|
93 |
1 |
return attachments; |
94 |
|
} catch (XWikiException e) { |
95 |
0 |
throw new XWikiRestException(e); |
96 |
|
} |
97 |
|
} |
98 |
|
} |