use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ObjectPropertyAtPageVersionResourceImpl method getObjectProperty.
@Override
public Property getObjectProperty(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, String propertyName, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
xwikiDocument = Utils.getXWiki(componentManager).getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyNames);
for (Property property : object.getProperties()) {
if (property.getName().equals(propertyName)) {
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), version, object.getClassName(), object.getNumber()).toString();
Link objectLink = objectFactory.createLink();
objectLink.setHref(objectUri);
objectLink.setRel(Relations.OBJECT);
property.getLinks().add(objectLink);
return property;
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class DefaultClassPropertyValuesProvider method getPropertyType.
private String getPropertyType(ClassPropertyReference propertyReference) throws XWikiRestException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(propertyReference.getParent(), xcontext);
BaseClass xclass = document.getXClass();
PropertyInterface xproperty = xclass.get(propertyReference.getName());
if (xproperty instanceof PropertyClass) {
return ((PropertyClass) xproperty).getClassType();
} else {
throw new XWikiRestException(String.format("No such property [%s].", this.entityReferenceSerializer.serialize(propertyReference)));
}
} catch (XWikiException e) {
throw new XWikiRestException(String.format("Failed to determine the property type for [{}].", this.entityReferenceSerializer.serialize(propertyReference)));
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class CommentVersionResourceImpl method getCommentVersion.
@Override
public Comment getCommentVersion(String wikiName, String spaceName, String pageName, String version, Integer id, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
for (com.xpn.xwiki.api.Object xwikiComment : xwikiComments) {
if (id.equals(xwikiComment.getNumber())) {
return DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames);
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class WikisResourceImpl method getWikis.
@Override
public Wikis getWikis() throws XWikiRestException {
try {
Wikis wikis = objectFactory.createWikis();
for (String wikiId : this.wikiDescriptorManager.getAllIds()) {
// Allow listing a wiki if:
// - the user has view access to it
// - or the wiki accepts global users and is not an invitation-based wiki
// - or the current user has a pending invitation to the wiki
// Note 1: To check if a user has view access to a wiki we check if the user can access the home page
// of the "XWiki" space. We do this because this needs to be allowed in view for the wiki to
// work properly.
// Note 2: it would be nicer to have an API for this.
// Note 3: this strategy is copied from WikisLiveTableResults.xml
EntityReference absoluteCommentReference = new EntityReference(this.defaultDocumentReferenceProvider.get().getName(), EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new EntityReference(wikiId, EntityType.WIKI)));
DocumentReference currentUserReference = getXWikiContext().getUserReference();
if (this.authorizationManager.hasAccess(Right.VIEW, absoluteCommentReference) || (this.wikiUserManager.getUserScope(wikiId) != UserScope.LOCAL_ONLY && this.wikiUserManager.getMembershipType(wikiId) != MembershipType.INVITE) || this.wikiUserManager.hasPendingInvitation(currentUserReference, wikiId)) {
wikis.getWikis().add(DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiId));
}
}
String queryUri = Utils.createURI(uriInfo.getBaseUri(), WikisSearchQueryResource.class).toString();
Link queryLink = objectFactory.createLink();
queryLink.setHref(queryUri);
queryLink.setRel(Relations.QUERY);
wikis.getLinks().add(queryLink);
return wikis;
} catch (Exception e) {
throw new XWikiRestException("Failed to get the list of wikis", e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AbstractParametrizedRestURLGenerator method getBaseURI.
protected URI getBaseURI() throws XWikiRestException {
try {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
StringBuilder url = new StringBuilder();
url.append(context.getURLFactory().getServerURL(context));
url.append('/');
String webAppPath = xwiki.getWebAppPath(context);
if (!webAppPath.equals("/")) {
url.append(webAppPath);
}
url.append("rest");
return new URI(url.toString());
} catch (URISyntaxException | MalformedURLException e) {
throw new XWikiRestException("Failed to generate a proper base URI.", e);
}
}
Aggregations