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

File ObjectResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
32
3
1
125
81
11
0.34
10.67
3
3.67

Classes

Class Line # Actions
ObjectResourceImpl 44 32 0% 11 7
0.8444444584.4%
 

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.Inject;
23    import javax.inject.Named;
24    import javax.ws.rs.WebApplicationException;
25    import javax.ws.rs.core.Response;
26    import javax.ws.rs.core.Response.Status;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.rest.XWikiRestException;
30    import org.xwiki.rest.internal.ModelFactory;
31    import org.xwiki.rest.internal.Utils;
32    import org.xwiki.rest.model.jaxb.Object;
33    import org.xwiki.rest.resources.objects.ObjectResource;
34   
35    import com.xpn.xwiki.XWikiException;
36    import com.xpn.xwiki.api.Document;
37    import com.xpn.xwiki.objects.BaseObject;
38   
39    /**
40    * @version $Id: f797e581e19f897c07427d408629aeab7520f0d0 $
41    */
42    @Component
43    @Named("org.xwiki.rest.internal.resources.objects.ObjectResourceImpl")
 
44    public class ObjectResourceImpl extends BaseObjectsResource implements ObjectResource
45    {
46    @Inject
47    private ModelFactory factory;
48   
 
49  26 toggle @Override
50    public Object getObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber,
51    Boolean withPrettyNames) throws XWikiRestException
52    {
53  26 try {
54  26 DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
55   
56  26 Document doc = documentInfo.getDocument();
57   
58  26 com.xpn.xwiki.objects.BaseObject baseObject = getBaseObject(doc, className, objectNumber);
59  26 if (baseObject == null) {
60  2 throw new WebApplicationException(Status.NOT_FOUND);
61    }
62   
63  24 return this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, withPrettyNames);
64    } catch (XWikiException e) {
65  0 throw new XWikiRestException(e);
66    }
67    }
68   
 
69  8 toggle @Override
70    public Response updateObject(String wikiName, String spaceName, String pageName, String className,
71    Integer objectNumber, Object restObject) throws XWikiRestException
72    {
73  8 try {
74  8 DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
75   
76  8 Document doc = documentInfo.getDocument();
77   
78  8 if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
79  1 throw new WebApplicationException(Status.UNAUTHORIZED);
80    }
81   
82  7 com.xpn.xwiki.api.Object xwikiObject = doc.getObject(className, objectNumber);
83  7 if (xwikiObject == null) {
84  0 throw new WebApplicationException(Status.NOT_FOUND);
85    }
86   
87  7 this.factory.toObject(xwikiObject, restObject);
88   
89  7 doc.save();
90   
91  7 BaseObject baseObject = getBaseObject(doc, className, objectNumber);
92   
93  7 return Response.status(Status.ACCEPTED)
94    .entity(this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, false)).build();
95    } catch (XWikiException e) {
96  0 throw new XWikiRestException(e);
97    }
98    }
99   
 
100  2 toggle @Override
101    public void deleteObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber)
102    throws XWikiRestException
103    {
104  2 try {
105  2 DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
106   
107  2 Document doc = documentInfo.getDocument();
108   
109  2 if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
110  1 throw new WebApplicationException(Status.UNAUTHORIZED);
111    }
112   
113  1 com.xpn.xwiki.api.Object object = doc.getObject(className, objectNumber);
114  1 if (object == null) {
115  0 throw new WebApplicationException(Status.NOT_FOUND);
116    }
117   
118  1 doc.removeObject(object);
119   
120  1 doc.save();
121    } catch (XWikiException e) {
122  0 throw new XWikiRestException(e);
123    }
124    }
125    }