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

File PageHistoryResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
18
1
1
89
53
2
0.11
18
1
2

Classes

Class Line # Actions
PageHistoryResourceImpl 46 18 0% 2 1
0.9473684494.7%
 

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.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 $Id: 39b4bc777e198d9d8a11d2899a6bd84045374471 $
43    */
44    @Component
45    @Named("org.xwiki.rest.internal.resources.pages.PageHistoryResourceImpl")
 
46    public class PageHistoryResourceImpl extends XWikiResource implements PageHistoryResource
47    {
 
48  7 toggle @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    // Note that the query is made to work with Oracle which treats empty strings as null.
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    }