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();
}
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations