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.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 |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("org.xwiki.rest.internal.resources.objects.AllObjectsForClassNameResourceImpl") |
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 3 |
Complexity Density: 0.15 |
|
45 |
|
public class AllObjectsForClassNameResourceImpl extends XWikiResource implements AllObjectsForClassNameResource |
46 |
|
{ |
|
|
| 86.4% |
Uncovered Elements: 3 (22) |
Complexity: 3 |
Complexity Density: 0.15 |
|
47 |
25 |
@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 |
|
} |