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);
}
}
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());
}
}
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());
}
}
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);
}
}
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);
}
}
Aggregations