1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal.resources.attachments

File AttachmentHistoryResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
20
1
1
98
63
3
0.15
20
1
3

Classes

Class Line # Actions
AttachmentHistoryResourceImpl 48 20 0% 3 3
0.869565287%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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 $Id: b7468abc0a288d8ef8b2d7cfdf477e22fc6d7336 $
45    */
46    @Component
47    @Named("org.xwiki.rest.internal.resources.attachments.AttachmentHistoryResourceImpl")
 
48    public class AttachmentHistoryResourceImpl extends XWikiResource implements AttachmentHistoryResource
49    {
 
50  1 toggle @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    }