1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal.resources.objects

File ObjectPropertyAtPageVersionResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
19
1
1
93
59
4
0.21
19
1
4

Classes

Class Line # Actions
ObjectPropertyAtPageVersionResourceImpl 47 19 0% 4 5
0.791666779.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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 $Id: 95de752a1fc3688267311dfb149fe93d549ccaad $
44    */
45    @Component
46    @Named("org.xwiki.rest.internal.resources.objects.ObjectPropertyAtPageVersionResourceImpl")
 
47    public class ObjectPropertyAtPageVersionResourceImpl extends XWikiResource implements
48    ObjectPropertyAtPageVersionResource
49    {
 
50  5 toggle @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    }