Search in sources :

Example 16 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty 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);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) PropEntry(org.apache.jackrabbit.webdav.property.PropEntry) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) Value(javax.jcr.Value) Session(javax.jcr.Session)

Example 17 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class VersionControlledItemCollection method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null && isVersionControlled()) {
        Node n = (Node) item;
        // workspace property already set in AbstractResource.initProperties()
        try {
            if (VERSION_HISTORY.equals(name)) {
                // DAV:version-history (computed)
                String vhHref = getLocatorFromItem(n.getVersionHistory()).getHref(true);
                prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
            } else if (CHECKED_OUT.equals(name) && n.isCheckedOut()) {
                // DAV:checked-out property (protected)
                String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
                prop = new HrefProperty(CHECKED_OUT, baseVHref, true);
            } else if (CHECKED_IN.equals(name) && !n.isCheckedOut()) {
                // DAV:checked-in property (protected)
                String baseVHref = getLocatorFromItem(n.getBaseVersion()).getHref(true);
                prop = new HrefProperty(CHECKED_IN, baseVHref, true);
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
    return prop;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) RepositoryException(javax.jcr.RepositoryException)

Example 18 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class RepositoryServiceImpl method obtain.

private SessionInfo obtain(CredentialsWrapper credentials, String workspaceName) throws RepositoryException {
    // check if the workspace with the given name is accessible
    HttpPropfind request = null;
    SessionInfoImpl sessionInfo = new SessionInfoImpl(credentials, workspaceName);
    try {
        DavPropertyNameSet nameSet = new DavPropertyNameSet();
        // for backwards compat. -> retrieve DAV:workspace if the newly
        // added property (workspaceName) is not supported by the server.
        nameSet.add(DeltaVConstants.WORKSPACE);
        nameSet.add(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
        request = new HttpPropfind(uriResolver.getWorkspaceUri(workspaceName), nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] responses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (responses.length != 1) {
            throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
        }
        DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
        DavProperty<?> prop = props.get(JcrRemotingConstants.JCR_WORKSPACE_NAME_LN, ItemResourceConstants.NAMESPACE);
        if (prop != null) {
            String wspName = prop.getValue().toString();
            if (workspaceName == null) {
                // login with 'null' workspace name -> retrieve the effective
                // workspace name from the property and recreate the SessionInfo.
                sessionInfo = new SessionInfoImpl(credentials, wspName);
            } else if (!wspName.equals(workspaceName)) {
                throw new LoginException("Login failed: Invalid workspace name '" + workspaceName + "'.");
            }
        } else if (props.contains(DeltaVConstants.WORKSPACE)) {
            String wspHref = new HrefProperty(props.get(DeltaVConstants.WORKSPACE)).getHrefs().get(0);
            String wspName = Text.unescape(Text.getName(wspHref, true));
            if (!wspName.equals(workspaceName)) {
                throw new LoginException("Login failed: Invalid workspace name " + workspaceName);
            }
        } else {
            throw new LoginException("Login failed: Unknown workspace '" + workspaceName + "'.");
        }
    } catch (IOException e) {
        throw new RepositoryException(e.getMessage(), e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
    // mappings.
    if (nsCache.prefixToURI.isEmpty()) {
        try {
            getRegisteredNamespaces(sessionInfo);
        } catch (RepositoryException e) {
        // ignore
        }
    }
    // return the sessionInfo
    return sessionInfo;
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) LoginException(javax.jcr.LoginException)

Example 19 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class RepositoryServiceImpl method getWorkspaceNames.

@Override
public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DeltaVConstants.WORKSPACE);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uriResolver.getRepositoryUri(), nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        Set<String> wspNames = new HashSet<String>();
        for (MultiStatusResponse mresponse : mresponses) {
            DavPropertySet props = mresponse.getProperties(DavServletResponse.SC_OK);
            if (props.contains(DeltaVConstants.WORKSPACE)) {
                HrefProperty hp = new HrefProperty(props.get(DeltaVConstants.WORKSPACE));
                String wspHref = hp.getHrefs().get(0);
                String name = Text.unescape(Text.getName(wspHref, true));
                wspNames.add(name);
            }
        }
        return wspNames.toArray(new String[wspNames.size()]);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) HashSet(java.util.HashSet)

Example 20 with HrefProperty

use of org.apache.jackrabbit.webdav.property.HrefProperty in project jackrabbit by apache.

the class RepositoryServiceImpl method getParentId.

private NodeId getParentId(String baseUri, DavPropertySet propSet, SessionInfo sessionInfo) throws RepositoryException {
    NodeId parentId = null;
    DavProperty<?> p = propSet.get(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    if (p != null) {
        HrefProperty parentProp = new HrefProperty(p);
        String parentHref = parentProp.getHrefs().get(0);
        if (parentHref != null && parentHref.length() > 0) {
            parentId = uriResolver.getNodeId(resolve(baseUri, parentHref), sessionInfo);
        }
    }
    return parentId;
}
Also used : HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) NodeId(org.apache.jackrabbit.spi.NodeId)

Aggregations

HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)20 RepositoryException (javax.jcr.RepositoryException)14 DavException (org.apache.jackrabbit.webdav.DavException)7 DefaultDavProperty (org.apache.jackrabbit.webdav.property.DefaultDavProperty)7 Node (javax.jcr.Node)6 DavProperty (org.apache.jackrabbit.webdav.property.DavProperty)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 Version (javax.jcr.version.Version)4 HttpResponse (org.apache.http.HttpResponse)4 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)4 Value (javax.jcr.Value)3 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)3 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Property (javax.jcr.Property)2 PropertyIterator (javax.jcr.PropertyIterator)2 VersionHistory (javax.jcr.version.VersionHistory)2 VersionIterator (javax.jcr.version.VersionIterator)2 NodeId (org.apache.jackrabbit.spi.NodeId)2