| 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.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.Link; |
| 33 |
|
import org.xwiki.rest.model.jaxb.Object; |
| 34 |
|
import org.xwiki.rest.model.jaxb.Property; |
| 35 |
|
import org.xwiki.rest.resources.objects.ObjectAtPageVersionResource; |
| 36 |
|
import org.xwiki.rest.resources.objects.ObjectPropertyAtPageVersionResource; |
| 37 |
|
|
| 38 |
|
import com.xpn.xwiki.XWikiException; |
| 39 |
|
import com.xpn.xwiki.api.Document; |
| 40 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@version |
| 44 |
|
|
| 45 |
|
@Component |
| 46 |
|
@Named("org.xwiki.rest.internal.resources.objects.ObjectPropertyAtPageVersionResourceImpl") |
| |
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 4 |
Complexity Density: 0.21 |
|
| 47 |
|
public class ObjectPropertyAtPageVersionResourceImpl extends XWikiResource implements |
| 48 |
|
ObjectPropertyAtPageVersionResource |
| 49 |
|
{ |
| |
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
| 50 |
5 |
@Override... |
| 51 |
|
public Property getObjectProperty(String wikiName, String spaceName, String pageName, String version, |
| 52 |
|
String className, Integer objectNumber, String propertyName, Boolean withPrettyNames) throws |
| 53 |
|
XWikiRestException |
| 54 |
|
{ |
| 55 |
5 |
try { |
| 56 |
5 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false); |
| 57 |
|
|
| 58 |
5 |
Document doc = documentInfo.getDocument(); |
| 59 |
|
|
| 60 |
5 |
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager) |
| 61 |
|
.getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager)); |
| 62 |
|
|
| 63 |
5 |
xwikiDocument = Utils.getXWiki(componentManager) |
| 64 |
|
.getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager)); |
| 65 |
|
|
| 66 |
5 |
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber); |
| 67 |
5 |
if (baseObject == null) { |
| 68 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
5 |
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext( |
| 72 |
|
componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyNames); |
| 73 |
|
|
| 74 |
5 |
for (Property property : object.getProperties()) { |
| 75 |
5 |
if (property.getName().equals(propertyName)) { |
| 76 |
5 |
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectAtPageVersionResource.class, |
| 77 |
|
doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), version, |
| 78 |
|
object.getClassName(), object.getNumber()).toString(); |
| 79 |
5 |
Link objectLink = objectFactory.createLink(); |
| 80 |
5 |
objectLink.setHref(objectUri); |
| 81 |
5 |
objectLink.setRel(Relations.OBJECT); |
| 82 |
5 |
property.getLinks().add(objectLink); |
| 83 |
|
|
| 84 |
5 |
return property; |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
| 89 |
|
} catch (XWikiException e) { |
| 90 |
0 |
throw new XWikiRestException(e); |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
|
} |