use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DefaultItemCollection method orderMembers.
/**
* Reorder the child nodes of the repository item represented by this
* resource as indicated by the specified {@link OrderPatch} object.
*
* @param orderPatch
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.ordering.OrderingResource#orderMembers(org.apache.jackrabbit.webdav.ordering.OrderPatch)
* @see Node#orderBefore(String, String)
*/
@Override
public void orderMembers(OrderPatch orderPatch) throws DavException {
if (!isOrderable()) {
throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
}
// only custom ordering is allowed
if (!OrderingConstants.ORDERING_TYPE_CUSTOM.equalsIgnoreCase(orderPatch.getOrderingType())) {
throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Only DAV:custom ordering type supported.");
}
Node n = (Node) item;
try {
for (OrderPatch.Member instruction : orderPatch.getOrderInstructions()) {
String srcRelPath = Text.unescape(instruction.getMemberHandle());
Position pos = instruction.getPosition();
String destRelPath = getRelDestinationPath(pos, n.getNodes());
// preform the reordering
n.orderBefore(srcRelPath, destRelPath);
}
complete();
} catch (RepositoryException e) {
// UnsupportedRepositoryException should not occur
throw new JcrDavException(e);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class DefaultItemCollection method refreshLock.
/**
* Refreshes the lock on this resource. With this implementation the
* {@link javax.jcr.lock lock} present on the underlying {@link javax.jcr.Node node}
* is refreshed. The timeout indicated by the <code>LockInfo</code>
* object is ignored.
*
* @param reqLockInfo LockInfo as build from the request.
* @param lockToken
* @return the updated lock info object.
* @throws org.apache.jackrabbit.webdav.DavException in case the lock could not be refreshed.
* @see org.apache.jackrabbit.webdav.DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String)
* @see javax.jcr.lock.Lock#refresh()
*/
@Override
public ActiveLock refreshLock(LockInfo reqLockInfo, String lockToken) throws DavException {
if (lockToken == null) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
ActiveLock lock = getLock(reqLockInfo.getType(), reqLockInfo.getScope());
if (lock == null) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given scope/type present on this resource.");
}
if (Type.WRITE.equals(lock.getType())) {
try {
Lock jcrLock = ((Node) item).getLock();
jcrLock.refresh();
return new JcrActiveLock(jcrLock);
} catch (RepositoryException e) {
/*
NOTE: LockException is only thrown by Lock.refresh()
the lock exception thrown by Node.getLock() was circumvented
by the init test if there is a lock applied...
NOTE: UnsupportedRepositoryOperationException should not occur
*/
throw new JcrDavException(e);
}
} else {
return super.refreshLock(reqLockInfo, lockToken);
}
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class SearchResourceImpl method getQuery.
/**
* Create a query from the information present in the <code>sInfo</code>
* object.<br>The following JCR specific logic is applied:
* <ul>
* <li>If the requested resource represents a node with nodetype nt:query, the
* request body is ignored and the query defined with the node is executed
* instead.</li>
* <li>If the requested resource does not represent an existing item, the
* specified query is persisted by calling {@link Query#storeAsNode(String)}.</li>
* </ul>
* @param sInfo defining the query to be executed
* @return <code>Query</code> object.
* @throws javax.jcr.query.InvalidQueryException if the query defined by <code>sInfo</code> is invalid
* @throws RepositoryException the query manager cannot be accessed or if
* another error occurs.
* @throws DavException if <code>sInfo</code> is <code>null</code> and
* the underlying repository item is not an nt:query node or if an error
* occurs when calling {@link Query#storeAsNode(String)}/
*/
private Query getQuery(SearchInfo sInfo) throws InvalidQueryException, RepositoryException, DavException {
Session session = getRepositorySession();
NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
Node rootNode = session.getRootNode();
QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
// test if query is defined by requested repository node
String itemPath = locator.getRepositoryPath();
if (itemPath != null && !rootNode.getPath().equals(itemPath)) {
String qNodeRelPath = itemPath.substring(1);
if (rootNode.hasNode(qNodeRelPath)) {
Node qNode = rootNode.getNode(qNodeRelPath);
if (qNode.isNodeType(JcrConstants.NT_QUERY)) {
return qMgr.getQuery(qNode);
}
}
}
Query q;
if (sInfo != null) {
// apply namespace mappings to session
Map<String, String> namespaces = sInfo.getNamespaces();
try {
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
String prefix = entry.getKey();
String uri = entry.getValue();
session.setNamespacePrefix(prefix, uri);
}
q = qMgr.createQuery(sInfo.getQuery(), sInfo.getLanguageName());
if (SearchInfo.NRESULTS_UNDEFINED != sInfo.getNumberResults()) {
q.setLimit(sInfo.getNumberResults());
}
if (SearchInfo.OFFSET_UNDEFINED != sInfo.getOffset()) {
q.setOffset(sInfo.getOffset());
}
} finally {
// reset namespace mappings
for (String uri : namespaces.values()) {
try {
session.setNamespacePrefix(nsReg.getPrefix(uri), uri);
} catch (RepositoryException e) {
log.warn("Unable to reset mapping of namespace: " + uri);
}
}
}
} else {
throw new DavException(DavServletResponse.SC_BAD_REQUEST, locator.getResourcePath() + " is not a nt:query node -> searchRequest body required.");
}
/* test if resource path does not exist -> thus indicating that
the query must be made persistent by calling Query.save(String) */
if (itemPath != null && !getRepositorySession().itemExists(itemPath)) {
try {
q.storeAsNode(itemPath);
} catch (RepositoryException e) {
// ItemExistsException should never occur.
throw new JcrDavException(e);
}
}
return q;
}
use of org.apache.jackrabbit.webdav.DavException 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;
}
use of org.apache.jackrabbit.webdav.DavException in project jackrabbit by apache.
the class VersionControlledItemCollection method resolveMergeConflict.
/**
* Resolve one or multiple merge conflicts present on this resource. Please
* note that the 'setProperties' or 'removeProperties' set my contain additional
* resource properties, that need to be changed. Those properties are left
* untouched, whereas the {@link #AUTO_MERGE_SET DAV:auto-merge-set}, is
* removed from the list upon successful resolution of a merge conflict.<br>
* If the removeProperties or setProperties set do not contain the mentioned
* merge conflict resource properties or if the value of those properties do
* not allow for a resolution of an existing merge conflict, this method
* returns silently.
*
* @param changeList
* @throws org.apache.jackrabbit.webdav.DavException
* @see Node#doneMerge(Version)
* @see Node#cancelMerge(Version)
*/
private void resolveMergeConflict(List<? extends PropEntry> changeList) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
Node n = (Node) item;
VersionManager vMgr = getVersionManager();
String path = item.getPath();
DavProperty<?> autoMergeSet = null;
DavProperty<?> predecessorSet = null;
/* find DAV:auto-merge-set entries. If none exists no attempt is made
to resolve merge conflict > return silently */
for (int i = 0; i < changeList.size(); i++) {
PropEntry propEntry = changeList.get(i);
// conflicts are resolved with 'cancel'
if (propEntry instanceof DavPropertyName && AUTO_MERGE_SET.equals(propEntry)) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
vMgr.cancelMerge(path, (Version) getRepositorySession().getNodeByIdentifier(value.getString()));
}
// remove this entry from the changeList
changeList.remove(propEntry);
} else if (propEntry instanceof DavProperty) {
if (AUTO_MERGE_SET.equals(((DavProperty<?>) propEntry).getName())) {
autoMergeSet = (DavProperty<?>) propEntry;
} else if (PREDECESSOR_SET.equals(((DavProperty<?>) propEntry).getName())) {
predecessorSet = (DavProperty<?>) propEntry;
}
}
}
// resolved individually according to the DAV:predecessor-set property.
if (autoMergeSet != null) {
// retrieve the current jcr:mergeFailed property values
if (!n.hasProperty(JcrConstants.JCR_MERGEFAILED)) {
throw new DavException(DavServletResponse.SC_CONFLICT, "Attempt to resolve non-existing merge conflicts.");
}
List<String> mergeset = new HrefProperty(autoMergeSet).getHrefs();
List<String> predecL;
if (predecessorSet == null) {
predecL = Collections.emptyList();
} else {
predecL = new HrefProperty(predecessorSet).getHrefs();
}
Session session = getRepositorySession();
// loop over the mergeFailed values (versions) and test whether they are
// removed from the DAV:auto-merge-set thus indicating resolution.
Value[] mergeFailed = n.getProperty(JcrConstants.JCR_MERGEFAILED).getValues();
for (Value value : mergeFailed) {
// build version-href from each entry in the jcr:mergeFailed property
// in order to be able to compare to the entries in the HrefProperty.
Version version = (Version) session.getNodeByIdentifier(value.getString());
String href = getLocatorFromItem(version).getHref(true);
// thus indicating that this merge conflict needs to be resolved.
if (!mergeset.contains(href)) {
// must be called.
if (predecL.contains(href)) {
vMgr.doneMerge(path, version);
} else {
vMgr.cancelMerge(path, version);
}
}
}
// after successful resolution of merge-conflicts according to
// DAV:auto-merge-set and DAV:predecessor-set remove these entries
// from the changeList.
changeList.remove(autoMergeSet);
if (predecessorSet != null) {
changeList.remove(predecessorSet);
}
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations