Search in sources :

Example 56 with Document

use of com.xpn.xwiki.api.Document 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)

Example 57 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class ObjectsAtPageVersionResourceImpl method getObjects.

@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String version, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
        Document doc = documentInfo.getDocument();
        Objects objects = objectFactory.createObjects();
        List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
        for (com.xpn.xwiki.objects.BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, true, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 58 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class ObjectsResourceImpl method getObjects.

@Override
public Objects getObjects(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();
        Objects objects = objectFactory.createObjects();
        List<BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<BaseObject> ri = new RangeIterable<BaseObject>(objectList, start, number);
        for (BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Objects(org.xwiki.rest.model.jaxb.Objects) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 59 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class ModifiablePageResource method putPage.

public Response putPage(DocumentInfo documentInfo, Page page, Boolean minorRevision) throws XWikiException {
    Document doc = documentInfo.getDocument();
    // Save the document only if there is actually something to do if if the document does not exist
    if (this.factory.toDocument(doc, page) || doc.isNew()) {
        doc.save(page.getComment(), Boolean.TRUE.equals(minorRevision));
        page = this.factory.toRestPage(uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, false, false, false, false, false);
        if (documentInfo.isCreated()) {
            return Response.created(uriInfo.getAbsolutePath()).entity(page).build();
        } else {
            return Response.status(Status.ACCEPTED).entity(page).build();
        }
    } else {
        return Response.status(Status.NOT_MODIFIED).build();
    }
}
Also used : Document(com.xpn.xwiki.api.Document)

Example 60 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class PageChildrenResourceImpl method getPageChildren.

@Override
public Pages getPageChildren(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();
        Pages pages = objectFactory.createPages();
        /* Use an explicit query to improve performance */
        String queryString = "select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc";
        List<String> childPageFullNames = queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset(start).setLimit(number).execute();
        for (String childPageFullName : childPageFullNames) {
            String pageId = Utils.getPageId(wikiName, childPageFullName);
            if (!Utils.getXWikiApi(componentManager).exists(pageId)) {
                getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceName);
            } else {
                Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId);
                /* We only add pages we have the right to access */
                if (childDoc != null) {
                    pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames));
                }
            }
        }
        return pages;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Aggregations

Document (com.xpn.xwiki.api.Document)97 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)60 XWikiException (com.xpn.xwiki.XWikiException)41 XWikiRestException (org.xwiki.rest.XWikiRestException)40 DocumentReference (org.xwiki.model.reference.DocumentReference)37 BaseObject (com.xpn.xwiki.objects.BaseObject)24 Test (org.junit.Test)23 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)16 Attachment (com.xpn.xwiki.api.Attachment)14 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)14 Vector (java.util.Vector)12 Link (org.xwiki.rest.model.jaxb.Link)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)7 Date (java.util.Date)7 XWiki (com.xpn.xwiki.api.XWiki)6 RangeIterable (org.xwiki.rest.internal.RangeIterable)6 Object (org.xwiki.rest.model.jaxb.Object)6 XWiki (com.xpn.xwiki.XWiki)5