Search in sources :

Example 6 with MultiStatus

use of org.apache.jackrabbit.webdav.MultiStatus in project jackrabbit by apache.

the class RepositoryServiceImpl method executeQuery.

@Override
public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language, Map<String, String> namespaces, long limit, long offset, Map<String, QValue> values) throws RepositoryException {
    HttpSearch request = null;
    try {
        String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
        SearchInfo sInfo = new SearchInfo(language, ItemResourceConstants.NAMESPACE, statement, namespaces);
        if (limit != -1) {
            sInfo.setNumberResults(limit);
        }
        if (offset != -1) {
            sInfo.setOffset(offset);
        }
        if (!(values == null || values.isEmpty())) {
            throw new UnsupportedOperationException("Implementation missing:  JCR-2107");
        }
        request = new HttpSearch(uri, sInfo);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatus ms = request.getResponseBodyAsMultiStatus(response);
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        return new QueryInfoImpl(ms, idFactory, resolver, valueFactory, getQValueFactory());
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) SearchInfo(org.apache.jackrabbit.webdav.search.SearchInfo) DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) HttpSearch(org.apache.jackrabbit.webdav.client.methods.HttpSearch) IOException(java.io.IOException)

Example 7 with MultiStatus

use of org.apache.jackrabbit.webdav.MultiStatus in project jackrabbit by apache.

the class SearchResourceImpl method search.

/**
     * Execute the query defined by the given <code>sInfo</code>.
     *
     * @see SearchResource#search(org.apache.jackrabbit.webdav.search.SearchInfo)
     */
public MultiStatus search(SearchInfo sInfo) throws DavException {
    try {
        QueryResult result = getQuery(sInfo).execute();
        MultiStatus ms = new MultiStatus();
        if (ItemResourceConstants.NAMESPACE.equals(sInfo.getLanguageNameSpace())) {
            ms.setResponseDescription("Columns: " + encode(result.getColumnNames()) + "\nSelectors: " + encode(result.getSelectorNames()));
        } else {
            ms.setResponseDescription(encode(result.getColumnNames()));
        }
        queryResultToMultiStatus(result, ms);
        return ms;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) QueryResult(javax.jcr.query.QueryResult) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException)

Example 8 with MultiStatus

use of org.apache.jackrabbit.webdav.MultiStatus in project jackrabbit by apache.

the class VersionControlledItemCollection method update.

/**
     * Perform an update on this resource. Depending on the format of the <code>updateInfo</code>
     * this is translated to one of the following methods defined by the JCR API:
     * <ul>
     * <li>{@link Node#restore(javax.jcr.version.Version, boolean)}</li>
     * <li>{@link Node#restore(javax.jcr.version.Version, String, boolean)}</li>
     * <li>{@link Node#restoreByLabel(String, boolean)}</li>
     * <li>{@link Node#update(String)}</li>
     * </ul>
     * <p>
     * Limitation: note that the <code>MultiStatus</code> returned by this method
     * will not list any nodes that have been removed due to an Uuid conflict.
     *
     * @param updateInfo
     * @return
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
     */
//TODO: with jcr the node must not be versionable in order to perform Node.update.
@Override
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
    if (updateInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        Node node = (Node) item;
        Element udElem = updateInfo.getUpdateElement();
        boolean removeExisting = DomUtil.hasChildElement(udElem, XML_REMOVEEXISTING, NAMESPACE);
        // register eventListener in order to be able to report the modified resources.
        EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
        registerEventListener(el, node.getPath());
        // perform the update/restore according to the update info
        if (updateInfo.getVersionHref() != null) {
            String[] hrefs = updateInfo.getVersionHref();
            if (hrefs.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body missing version href or containing multiple version hrefs.");
            }
            String versionPath = getLocatorFromHref(hrefs[0]).getRepositoryPath();
            String versionName = getItemName(versionPath);
            String relPath = DomUtil.getChildText(udElem, XML_RELPATH, NAMESPACE);
            if (relPath == null) {
                // restore version by name
                node.restore(versionName, removeExisting);
            } else if (node.hasNode(relPath)) {
                Version v = node.getNode(relPath).getVersionHistory().getVersion(versionName);
                node.restore(v, relPath, removeExisting);
            } else {
                Version v = (Version) getRepositorySession().getNode(versionPath);
                node.restore(v, relPath, removeExisting);
            }
        } else if (updateInfo.getLabelName() != null) {
            String[] labels = updateInfo.getLabelName();
            if (labels.length != 1) {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: Multiple labels specified.");
            }
            node.restoreByLabel(labels[0], removeExisting);
        } else if (updateInfo.getWorkspaceHref() != null) {
            String href = obtainAbsolutePathFromUri(updateInfo.getWorkspaceHref());
            String workspaceName = getLocatorFromHref(href).getWorkspaceName();
            node.update(workspaceName);
        } else {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body.");
        }
        // unregister the event listener again
        unregisterEventListener(el);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Element(org.w3c.dom.Element) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) EventListener(javax.jcr.observation.EventListener)

Example 9 with MultiStatus

use of org.apache.jackrabbit.webdav.MultiStatus in project jackrabbit by apache.

the class WorkspaceResourceImpl method update.

/**
     * While RFC 3253 does not define any version-related operations for the
     * workspace resource, this implementation uses {@link VersionControlledResource#update(UpdateInfo)}
     * to map {@link Workspace#restore(javax.jcr.version.Version[], boolean)} to
     * a WebDAV call.
     * <p>
     * Limitation: note that the <code>MultiStatus</code> returned by this method
     * will not list any nodes that have been removed due to an Uuid conflict.
     *
     * @param updateInfo
     * @return
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#update(org.apache.jackrabbit.webdav.version.UpdateInfo)
     */
@Override
public MultiStatus update(UpdateInfo updateInfo) throws DavException {
    if (updateInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid update request body required.");
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    Session session = getRepositorySession();
    MultiStatus ms = new MultiStatus();
    try {
        Element udElem = updateInfo.getUpdateElement();
        boolean removeExisting = DomUtil.hasChildElement(udElem, ItemResourceConstants.XML_REMOVEEXISTING, ItemResourceConstants.NAMESPACE);
        // register eventListener in order to be able to report the modified resources.
        EventListener el = new EListener(updateInfo.getPropertyNameSet(), ms);
        registerEventListener(el, session.getRootNode().getPath());
        String[] hrefs = updateInfo.getVersionHref();
        if (hrefs == null || hrefs.length < 1) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: at least a single version href must be specified.");
        }
        // perform the update/restore according to the update info
        Version[] versions = new Version[hrefs.length];
        for (int i = 0; i < hrefs.length; i++) {
            DavResourceLocator vLoc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), hrefs[i]);
            String versionPath = vLoc.getRepositoryPath();
            Item item = getRepositorySession().getItem(versionPath);
            if (item instanceof Version) {
                versions[i] = (Version) item;
            } else {
                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid update request body: href does not identify a version " + hrefs[i]);
            }
        }
        session.getWorkspace().restore(versions, removeExisting);
        // unregister the event listener again
        unregisterEventListener(el);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) Item(javax.jcr.Item) Version(javax.jcr.version.Version) EventListener(javax.jcr.observation.EventListener) Session(javax.jcr.Session) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 10 with MultiStatus

use of org.apache.jackrabbit.webdav.MultiStatus in project jackrabbit by apache.

the class VersionControlledItemCollection method merge.

/**
     * Merge the repository node represented by this resource according to the
     * information present in the given {@link MergeInfo} object.
     *
     * @param mergeInfo
     * @return <code>MultiStatus</code> recording all repository items modified
     * by this merge call as well as the resources that a client must modify to
     * complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
     * @see Node#merge(String, boolean)
     */
//TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
    if (mergeInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        // NOTE: RFC requires that all modified resources are reported in the
        // multistatus response. this doesn't work however with the remoting
        // there is no way to distinguish the 'failedId's from any other
        // resources that got modified by this merge operation -> omitted.
        // todo: RFC allows multiple href elements inside the DAV:source element
        String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();
        String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
        boolean isShallow = "0".equals(depth);
        NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
        // add resources to the multistatus, that failed to be merged
        while (failed.hasNext()) {
            Node failedNode = failed.nextNode();
            DavResourceLocator loc = getLocatorFromItem(failedNode);
            DavResource res = createResourceFromLocator(loc);
            ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)20 HttpResponse (org.apache.http.HttpResponse)8 RepositoryException (javax.jcr.RepositoryException)7 DavException (org.apache.jackrabbit.webdav.DavException)6 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)6 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)5 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)4 Element (org.w3c.dom.Element)4 Node (javax.jcr.Node)3 HttpClient (org.apache.http.client.HttpClient)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 IOException (java.io.IOException)2 EventListener (javax.jcr.observation.EventListener)2 Version (javax.jcr.version.Version)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)2 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)2 VersionControlledResource (org.apache.jackrabbit.webdav.version.VersionControlledResource)2 URI (java.net.URI)1 Item (javax.jcr.Item)1