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.Properties; |
35 |
|
import org.xwiki.rest.resources.classes.ClassPropertiesResource; |
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.ClassPropertiesResourceImpl") |
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 3 |
Complexity Density: 0.18 |
|
45 |
|
public class ClassPropertiesResourceImpl extends XWikiResource implements ClassPropertiesResource |
46 |
|
{ |
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 3 |
Complexity Density: 0.18 |
|
47 |
25 |
@Override... |
48 |
|
public Properties getClassProperties(String wikiName, String className) throws XWikiRestException |
49 |
|
{ |
50 |
25 |
String database = Utils.getXWikiContext(componentManager).getWikiId(); |
51 |
|
|
52 |
25 |
try { |
53 |
25 |
Utils.getXWikiContext(componentManager).setWikiId(wikiName); |
54 |
|
|
55 |
25 |
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className); |
56 |
25 |
if (xwikiClass == null) { |
57 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
58 |
|
} |
59 |
|
|
60 |
25 |
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass); |
61 |
|
|
62 |
25 |
Properties properties = objectFactory.createProperties(); |
63 |
25 |
properties.getProperties().addAll(clazz.getProperties()); |
64 |
|
|
65 |
25 |
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, |
66 |
|
xwikiClass.getName()).toString(); |
67 |
25 |
Link classLink = objectFactory.createLink(); |
68 |
25 |
classLink.setHref(classUri); |
69 |
25 |
classLink.setRel(Relations.CLASS); |
70 |
25 |
properties.getLinks().add(classLink); |
71 |
|
|
72 |
25 |
return properties; |
73 |
|
} catch (XWikiException e) { |
74 |
0 |
throw new XWikiRestException(e); |
75 |
|
} finally { |
76 |
25 |
Utils.getXWikiContext(componentManager).setWikiId(database); |
77 |
|
} |
78 |
|
} |
79 |
|
} |