use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentsResourceImpl method getAttachments.
@Override
public Attachments getAttachments(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
return getAttachmentsForDocument(doc, start, number, withPrettyNames);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AbstractClassPropertyValuesProvider method getValues.
@Override
public PropertyValues getValues(ClassPropertyReference propertyReference, int limit, Object... filterParameters) throws XWikiRestException {
T propertyDefinition = getPropertyDefinition(propertyReference);
String filter = "";
if (filterParameters.length > 0 && filterParameters[0] != null) {
filter = filterParameters[0].toString();
}
try {
if (filter.isEmpty() || limit <= 0) {
return getAllowedValues(propertyDefinition, limit, filter);
} else {
return getMixedValues(propertyDefinition, limit, filter);
}
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ClassPropertyResourceImpl method getClassProperty.
@Override
public Property getClassProperty(String wikiName, String className, String propertyName) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
if (xwikiClass == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass);
for (Property property : clazz.getProperties()) {
if (property.getName().equals(propertyName)) {
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
Link classLink = objectFactory.createLink();
classLink.setHref(classUri);
classLink.setRel(Relations.CLASS);
property.getLinks().add(classLink);
return property;
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class SpaceSearchResourceImpl method search.
@Override
public SearchResults search(String wikiName, String spaceName, String keywords, List<String> searchScopeStrings, Integer number, Integer start, String orderField, String order, Boolean withPrettyNames) throws XWikiRestException {
List<String> spaces = parseSpaceSegments(spaceName);
try {
SearchResults searchResults = objectFactory.createSearchResults();
searchResults.setTemplate(String.format("%s?%s", Utils.createURI(uriInfo.getBaseUri(), SpaceSearchResource.class, wikiName, spaces).toString(), SEARCH_TEMPLATE_INFO));
List<SearchScope> searchScopes = parseSearchScopeStrings(searchScopeStrings);
searchResults.getSearchResults().addAll(search(searchScopes, keywords, wikiName, Utils.getLocalSpaceId(spaces), Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), number, start, true, orderField, order, withPrettyNames));
return searchResults;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class CurrentUserPropertyResourceImpl method setNextPropertyValue.
@Override
public Response setNextPropertyValue(String propertyName) throws XWikiRestException {
XWikiContext xcontext = (XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
try {
// For Guest users, raise an error
if (xcontext.getUserReference() == null) {
throw new XWikiRestException(String.format("Cannot change property [%s] since the current user is guest", propertyName));
}
XWikiDocument userDocument = xcontext.getWiki().getDocument(xcontext.getUserReference(), xcontext);
if (!this.authorizationManager.hasAccess(Right.EDIT, userDocument.getDocumentReference())) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
BaseObject object = userDocument.getXObject(USER_REFERENCE);
if (object == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
// Find the value to replace:
// - for a boolean type, if true then the new value is false, if false then then new value is true
// - for a static list type, find the next value in the list. Note that multiselect lists are not handled
java.lang.Object newValue = computeNewValue(object, propertyName, xcontext);
if (newValue != null) {
object.set(propertyName, newValue, xcontext);
xcontext.getWiki().saveDocument(userDocument, "Setting next value", true, xcontext);
return buildResponse(userDocument, propertyName, xcontext);
} else {
return Response.status(Status.NOT_MODIFIED).build();
}
} catch (XWikiException e) {
throw new XWikiRestException(String.format("Failed to change property [%s] for user [%s]", propertyName, xcontext.getUserReference()), e);
}
}
Aggregations