Search in sources :

Example 31 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DefaultWikiManagerREST method createWiki.

@Override
@POST
public Response createWiki(@QueryParam("template") String template, Wiki wiki) throws XWikiRestException {
    XWikiContext xcontext = getXWikiContext();
    WikiDescriptor descriptor = null;
    try {
        // Create the wiki
        descriptor = wikiManager.create(wiki.getId(), wiki.getId(), true);
        // Change the descriptor
        if (wiki.getOwner() != null) {
            descriptor.setOwnerId(wiki.getOwner());
        } else {
            descriptor.setOwnerId(entityReferenceSerializer.serialize(xcontext.getUserReference()));
        }
        descriptor.setPrettyName(wiki.getName());
        descriptor.setDescription(wiki.getDescription());
        // Save the descriptor
        wikiDescriptorManager.saveDescriptor(descriptor);
        // Apply a template (if needed)
        if (template != null) {
            WikiProvisioningJob job = wikiTemplateManager.applyTemplate(descriptor.getId(), template);
            job.join();
        }
        // Build the response
        Wiki result = createWiki(objectFactory, uriInfo.getBaseUri(), wiki.getId(), wiki.getOwner(), wiki.getDescription());
        // Add a link to the WebHome of the newly created wiki.
        Link home = objectFactory.createLink();
        home.setRel(Relations.HOME);
        home.setHref(xcontext.getWiki().getURL(descriptor.getMainPageReference(), "view", xcontext));
        result.getLinks().add(home);
        // Return the final response
        return Response.created(UriBuilder.fromUri(uriInfo.getBaseUri()).path(WikiResource.class).build(wiki.getId())).entity(result).build();
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) Wiki(org.xwiki.rest.model.jaxb.Wiki) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Link(org.xwiki.rest.model.jaxb.Link) XWikiRestException(org.xwiki.rest.XWikiRestException) WikiProvisioningJob(org.xwiki.wiki.provisioning.WikiProvisioningJob) POST(javax.ws.rs.POST)

Example 32 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DBListClassPropertyValuesProviderTest method getValuesForMissingProperty.

@Test
public void getValuesForMissingProperty() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("status", this.classReference);
    when(this.entityReferenceSerializer.serialize(propertyReference)).thenReturn("status reference");
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 0);
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("Property [status reference] not found.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 33 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class DefaultClassPropertyValuesProviderTest method getValuesWithMissingProvider.

@Test
public void getValuesWithMissingProvider() throws Exception {
    ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
    ComponentManager contextComponentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(contextComponentManager.getInstance(ClassPropertyValuesProvider.class, "DBList")).thenThrow(new ComponentLookupException("Component not found."));
    try {
        this.mocker.getComponentUnderTest().getValues(propertyReference, 13, "one");
        fail();
    } catch (XWikiRestException expected) {
        assertEquals("There's no value provider registered for the [DBList] property type.", expected.getMessage());
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) Test(org.junit.Test)

Example 34 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class ObjectResourceImpl method getObject.

@Override
public Object getObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        com.xpn.xwiki.objects.BaseObject baseObject = getBaseObject(doc, className, objectNumber);
        if (baseObject == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        return this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, withPrettyNames);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : BaseObject(com.xpn.xwiki.objects.BaseObject) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 35 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class ObjectResourceImpl method updateObject.

@Override
public Response updateObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, Boolean minorRevision, Object restObject) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        com.xpn.xwiki.api.Object xwikiObject = doc.getObject(className, objectNumber);
        if (xwikiObject == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        this.factory.toObject(xwikiObject, restObject);
        doc.save("", Boolean.TRUE.equals(minorRevision));
        BaseObject baseObject = getBaseObject(doc, className, objectNumber);
        return Response.status(Status.ACCEPTED).entity(this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, false)).build();
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiRestException (org.xwiki.rest.XWikiRestException)71 XWikiException (com.xpn.xwiki.XWikiException)46 Document (com.xpn.xwiki.api.Document)40 WebApplicationException (javax.ws.rs.WebApplicationException)26 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 Link (org.xwiki.rest.model.jaxb.Link)12 QueryException (org.xwiki.query.QueryException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)7 RangeIterable (org.xwiki.rest.internal.RangeIterable)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 Object (org.xwiki.rest.model.jaxb.Object)5 Property (org.xwiki.rest.model.jaxb.Property)5 Date (java.util.Date)4 Test (org.junit.Test)4 ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)4 Objects (org.xwiki.rest.model.jaxb.Objects)4 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)3 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 URI (java.net.URI)3 URL (java.net.URL)3