Search in sources :

Example 21 with XWikiRestException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Object(org.xwiki.rest.model.jaxb.Object) ObjectAtPageVersionResource(org.xwiki.rest.resources.objects.ObjectAtPageVersionResource) Property(org.xwiki.rest.model.jaxb.Property) Link(org.xwiki.rest.model.jaxb.Link) XWikiException(com.xpn.xwiki.XWikiException)

Example 22 with XWikiRestException

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)));
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) XWikiRestException(org.xwiki.rest.XWikiRestException) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException)

Example 23 with XWikiRestException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 24 with XWikiRestException

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);
    }
}
Also used : WikisSearchQueryResource(org.xwiki.rest.resources.wikis.WikisSearchQueryResource) XWikiRestException(org.xwiki.rest.XWikiRestException) Wikis(org.xwiki.rest.model.jaxb.Wikis) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Link(org.xwiki.rest.model.jaxb.Link) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 25 with XWikiRestException

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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