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.classes; |
21 |
|
|
22 |
|
import javax.inject.Named; |
23 |
|
import javax.ws.rs.WebApplicationException; |
24 |
|
import javax.ws.rs.core.Response.Status; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.rest.Relations; |
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.Class; |
33 |
|
import org.xwiki.rest.model.jaxb.Link; |
34 |
|
import org.xwiki.rest.model.jaxb.Property; |
35 |
|
import org.xwiki.rest.resources.classes.ClassPropertyResource; |
36 |
|
import org.xwiki.rest.resources.classes.ClassResource; |
37 |
|
|
38 |
|
import com.xpn.xwiki.XWikiException; |
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("org.xwiki.rest.internal.resources.classes.ClassPropertyResourceImpl") |
|
|
| 82.6% |
Uncovered Elements: 4 (23) |
Complexity: 4 |
Complexity Density: 0.22 |
|
45 |
|
public class ClassPropertyResourceImpl extends XWikiResource implements ClassPropertyResource |
46 |
|
{ |
|
|
| 81.8% |
Uncovered Elements: 4 (22) |
Complexity: 4 |
Complexity Density: 0.22 |
|
47 |
183 |
@Override... |
48 |
|
public Property getClassProperty(String wikiName, String className, String propertyName) throws XWikiRestException |
49 |
|
{ |
50 |
183 |
String database = Utils.getXWikiContext(componentManager).getWikiId(); |
51 |
|
|
52 |
183 |
try { |
53 |
183 |
Utils.getXWikiContext(componentManager).setWikiId(wikiName); |
54 |
|
|
55 |
183 |
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className); |
56 |
183 |
if (xwikiClass == null) { |
57 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
58 |
|
} |
59 |
|
|
60 |
183 |
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass); |
61 |
|
|
62 |
183 |
for (Property property : clazz.getProperties()) { |
63 |
3539 |
if (property.getName().equals(propertyName)) { |
64 |
183 |
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, |
65 |
|
xwikiClass.getName()).toString(); |
66 |
183 |
Link classLink = objectFactory.createLink(); |
67 |
183 |
classLink.setHref(classUri); |
68 |
183 |
classLink.setRel(Relations.CLASS); |
69 |
183 |
property.getLinks().add(classLink); |
70 |
|
|
71 |
183 |
return property; |
72 |
|
} |
73 |
|
} |
74 |
|
|
75 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
76 |
|
} catch (XWikiException e) { |
77 |
0 |
throw new XWikiRestException(e); |
78 |
|
} finally { |
79 |
183 |
Utils.getXWikiContext(componentManager).setWikiId(database); |
80 |
|
} |
81 |
|
} |
82 |
|
} |