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

File AllObjectsForClassNameResourceImpl.java

 

Coverage histogram

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

Code metrics

2
20
1
1
92
56
3
0.15
20
1
3

Classes

Class Line # Actions
AllObjectsForClassNameResourceImpl 45 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.objects;
21   
22    import java.util.List;
23   
24    import javax.inject.Named;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.query.Query;
28    import org.xwiki.rest.XWikiResource;
29    import org.xwiki.rest.XWikiRestException;
30    import org.xwiki.rest.internal.DomainObjectFactory;
31    import org.xwiki.rest.internal.Utils;
32    import org.xwiki.rest.model.jaxb.ObjectSummary;
33    import org.xwiki.rest.model.jaxb.Objects;
34    import org.xwiki.rest.resources.objects.AllObjectsForClassNameResource;
35   
36    import com.xpn.xwiki.api.Document;
37    import com.xpn.xwiki.doc.XWikiDocument;
38    import com.xpn.xwiki.objects.BaseObject;
39   
40    /**
41    * @version $Id: 3852ae1b9e5504e45b52ad7e0b62256f842f2929 $
42    */
43    @Component
44    @Named("org.xwiki.rest.internal.resources.objects.AllObjectsForClassNameResourceImpl")
 
45    public class AllObjectsForClassNameResourceImpl extends XWikiResource implements AllObjectsForClassNameResource
46    {
 
47  25 toggle @Override
48    public Objects getObjects(String wikiName, String className, Integer start, Integer number, String order,
49    Boolean withPrettyNames) throws XWikiRestException
50    {
51  25 String database = Utils.getXWikiContext(componentManager).getWikiId();
52   
53  25 try {
54  25 Objects objects = new Objects();
55   
56  25 Utils.getXWikiContext(componentManager).setWikiId(wikiName);
57   
58  25 String query =
59    "select doc, obj from BaseObject as obj, XWikiDocument as doc where obj.name=doc.fullName and obj.className=:className";
60  25 if ("date".equals(order)) {
61  0 query += " order by doc.date desc";
62    }
63   
64  25 List<Object> queryResult = null;
65  25 queryResult =
66    queryManager.createQuery(query, Query.XWQL).bindValue("className", className).setLimit(number)
67    .setOffset(start).execute();
68   
69  25 for (Object object : queryResult) {
70  3 Object[] fields = (Object[]) object;
71   
72  3 XWikiDocument xwikiDocument = (XWikiDocument) fields[0];
73  3 xwikiDocument.setDatabase(wikiName);
74  3 Document doc = new Document(xwikiDocument, Utils.getXWikiContext(componentManager));
75  3 BaseObject xwikiObject = (BaseObject) fields[1];
76   
77  3 ObjectSummary objectSummary = DomainObjectFactory
78    .createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(
79    componentManager), doc, xwikiObject, false, Utils.getXWikiApi(componentManager),
80    withPrettyNames);
81   
82  3 objects.getObjectSummaries().add(objectSummary);
83    }
84   
85  25 return objects;
86    } catch (Exception e) {
87  0 throw new XWikiRestException(e);
88    } finally {
89  25 Utils.getXWikiContext(componentManager).setWikiId(database);
90    }
91    }
92    }