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 javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.ws.rs.WebApplicationException; |
25 |
|
import javax.ws.rs.core.Response; |
26 |
|
import javax.ws.rs.core.Response.Status; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.rest.XWikiRestException; |
30 |
|
import org.xwiki.rest.internal.ModelFactory; |
31 |
|
import org.xwiki.rest.internal.Utils; |
32 |
|
import org.xwiki.rest.model.jaxb.Object; |
33 |
|
import org.xwiki.rest.resources.objects.ObjectResource; |
34 |
|
|
35 |
|
import com.xpn.xwiki.XWikiException; |
36 |
|
import com.xpn.xwiki.api.Document; |
37 |
|
import com.xpn.xwiki.objects.BaseObject; |
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@Component |
43 |
|
@Named("org.xwiki.rest.internal.resources.objects.ObjectResourceImpl") |
|
|
| 84.4% |
Uncovered Elements: 7 (45) |
Complexity: 11 |
Complexity Density: 0.34 |
|
44 |
|
public class ObjectResourceImpl extends BaseObjectsResource implements ObjectResource |
45 |
|
{ |
46 |
|
@Inject |
47 |
|
private ModelFactory factory; |
48 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
49 |
26 |
@Override... |
50 |
|
public Object getObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, |
51 |
|
Boolean withPrettyNames) throws XWikiRestException |
52 |
|
{ |
53 |
26 |
try { |
54 |
26 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
55 |
|
|
56 |
26 |
Document doc = documentInfo.getDocument(); |
57 |
|
|
58 |
26 |
com.xpn.xwiki.objects.BaseObject baseObject = getBaseObject(doc, className, objectNumber); |
59 |
26 |
if (baseObject == null) { |
60 |
2 |
throw new WebApplicationException(Status.NOT_FOUND); |
61 |
|
} |
62 |
|
|
63 |
24 |
return this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, withPrettyNames); |
64 |
|
} catch (XWikiException e) { |
65 |
0 |
throw new XWikiRestException(e); |
66 |
|
} |
67 |
|
} |
68 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
69 |
8 |
@Override... |
70 |
|
public Response updateObject(String wikiName, String spaceName, String pageName, String className, |
71 |
|
Integer objectNumber, Object restObject) throws XWikiRestException |
72 |
|
{ |
73 |
8 |
try { |
74 |
8 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
75 |
|
|
76 |
8 |
Document doc = documentInfo.getDocument(); |
77 |
|
|
78 |
8 |
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) { |
79 |
1 |
throw new WebApplicationException(Status.UNAUTHORIZED); |
80 |
|
} |
81 |
|
|
82 |
7 |
com.xpn.xwiki.api.Object xwikiObject = doc.getObject(className, objectNumber); |
83 |
7 |
if (xwikiObject == null) { |
84 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
85 |
|
} |
86 |
|
|
87 |
7 |
this.factory.toObject(xwikiObject, restObject); |
88 |
|
|
89 |
7 |
doc.save(); |
90 |
|
|
91 |
7 |
BaseObject baseObject = getBaseObject(doc, className, objectNumber); |
92 |
|
|
93 |
7 |
return Response.status(Status.ACCEPTED) |
94 |
|
.entity(this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, false)).build(); |
95 |
|
} catch (XWikiException e) { |
96 |
0 |
throw new XWikiRestException(e); |
97 |
|
} |
98 |
|
} |
99 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
100 |
2 |
@Override... |
101 |
|
public void deleteObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber) |
102 |
|
throws XWikiRestException |
103 |
|
{ |
104 |
2 |
try { |
105 |
2 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
106 |
|
|
107 |
2 |
Document doc = documentInfo.getDocument(); |
108 |
|
|
109 |
2 |
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) { |
110 |
1 |
throw new WebApplicationException(Status.UNAUTHORIZED); |
111 |
|
} |
112 |
|
|
113 |
1 |
com.xpn.xwiki.api.Object object = doc.getObject(className, objectNumber); |
114 |
1 |
if (object == null) { |
115 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
116 |
|
} |
117 |
|
|
118 |
1 |
doc.removeObject(object); |
119 |
|
|
120 |
1 |
doc.save(); |
121 |
|
} catch (XWikiException e) { |
122 |
0 |
throw new XWikiRestException(e); |
123 |
|
} |
124 |
|
} |
125 |
|
} |