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.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.XWikiRestException; |
29 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
30 |
|
import org.xwiki.rest.internal.Utils; |
31 |
|
import org.xwiki.rest.model.jaxb.Link; |
32 |
|
import org.xwiki.rest.model.jaxb.Object; |
33 |
|
import org.xwiki.rest.model.jaxb.Properties; |
34 |
|
import org.xwiki.rest.resources.objects.ObjectPropertiesResource; |
35 |
|
import org.xwiki.rest.resources.objects.ObjectResource; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.api.Document; |
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("org.xwiki.rest.internal.resources.objects.ObjectPropertiesResourceImpl") |
45 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 3 |
Complexity Density: 0.19 |
|
46 |
|
public class ObjectPropertiesResourceImpl extends BaseObjectsResource implements ObjectPropertiesResource |
47 |
|
{ |
|
|
| 83.3% |
Uncovered Elements: 3 (18) |
Complexity: 3 |
Complexity Density: 0.19 |
|
48 |
1 |
@Override... |
49 |
|
public Properties getObjectProperties(String wikiName, String spaceName, String pageName, String className, |
50 |
|
Integer objectNumber, Boolean withPrettyNames) throws XWikiRestException |
51 |
|
{ |
52 |
1 |
try { |
53 |
1 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
54 |
|
|
55 |
1 |
Document doc = documentInfo.getDocument(); |
56 |
|
|
57 |
1 |
com.xpn.xwiki.objects.BaseObject baseObject = getBaseObject(doc, className, objectNumber); |
58 |
1 |
if (baseObject == null) { |
59 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
60 |
|
} |
61 |
|
|
62 |
1 |
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext( |
63 |
|
componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), withPrettyNames); |
64 |
|
|
65 |
1 |
Properties properties = objectFactory.createProperties(); |
66 |
1 |
properties.getProperties().addAll(object.getProperties()); |
67 |
|
|
68 |
1 |
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectResource.class, doc.getWiki(), |
69 |
|
Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), object.getClassName(), |
70 |
|
object.getNumber()).toString(); |
71 |
1 |
Link objectLink = objectFactory.createLink(); |
72 |
1 |
objectLink.setHref(objectUri); |
73 |
1 |
objectLink.setRel(Relations.OBJECT); |
74 |
1 |
properties.getLinks().add(objectLink); |
75 |
|
|
76 |
1 |
return properties; |
77 |
|
} catch (XWikiException e) { |
78 |
0 |
throw new XWikiRestException(e); |
79 |
|
} |
80 |
|
} |
81 |
|
} |