Search in sources :

Example 61 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class AbstractNodeTypeManagementTest method testWorkspaceMove.

public void testWorkspaceMove() throws RepositoryException, NotExecutableException {
    Workspace wsp = getTestSession().getWorkspace();
    String parentPath = childNode.getParent().getPath();
    String srcPath = childNode.getPath();
    String destPath = parentPath + "/" + nodeName3;
    checkReadOnly(parentPath);
    try {
        wsp.move(srcPath, destPath);
        fail("Missing write privilege.");
    } catch (AccessDeniedException e) {
    // success
    }
    // with simple write privilege moving a node is not allowed.
    modifyPrivileges(parentPath, Privilege.JCR_WRITE, true);
    try {
        wsp.move(srcPath, destPath);
        fail("Missing privilege jcr:nodeTypeManagement.");
    } catch (AccessDeniedException e) {
    // success
    }
    // adding jcr:nodeTypeManagement privilege will grant permission to move.
    modifyPrivileges(parentPath, PrivilegeRegistry.REP_WRITE, true);
    wsp.move(srcPath, destPath);
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Workspace(javax.jcr.Workspace)

Example 62 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class DavResourceImpl method bind.

/**
     * @see BindableResource#rebind(DavResource, DavResource)
     */
public void bind(DavResource collection, DavResource newBinding) throws DavException {
    if (!exists()) {
        //DAV:bind-source-exists
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    }
    if (isLocked(collection)) {
        //DAV:locked-update-allowed?
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    if (isFilteredResource(newBinding)) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    checkSameWorkspace(collection.getLocator());
    try {
        if (!node.isNodeType(MIX_SHAREABLE)) {
            if (!node.canAddMixin(MIX_SHAREABLE)) {
                //DAV:binding-allowed
                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
            }
            node.addMixin(MIX_SHAREABLE);
            node.save();
        }
        Workspace workspace = session.getRepositorySession().getWorkspace();
        workspace.clone(workspace.getName(), node.getPath(), newBinding.getLocator().getRepositoryPath(), false);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) RepositoryException(javax.jcr.RepositoryException) Workspace(javax.jcr.Workspace)

Example 63 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class ShareableNodeTest method testDetectShareCycleOnTransientMove.

/**
     * Verify that a share cycle is detected (6.13.13) when a node is
     * transiently moved.
     */
public void testDetectShareCycleOnTransientMove() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Session session = b1.getSession();
    Workspace workspace = session.getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // add child node
    Node c = b1.addNode("c");
    b1.save();
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    // move node
    try {
        session.move(testRootNode.getPath() + "/a2", c.getPath());
        fail("Share cycle not detected on transient move.");
    } catch (RepositoryException e) {
    // expected
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 64 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class ShareableNodeTest method testSessionImportSystemViewCollision.

/**
     * Verify system view import via session (6.13.14). Export a system view
     * containing a shareable node and verify, that reimporting underneath
     * a different parent adds another member to the shared set and does not
     * duplicate children nodes.
     */
public void testSessionImportSystemViewCollision() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node a3 = testRootNode.addNode("a3");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Session session = b1.getSession();
    Workspace workspace = session.getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // add child c to shareable nodes b1 & b2
    b1.addNode("c");
    b1.save();
    // create temp file
    File tmpFile = File.createTempFile("test", null);
    tmpFile.deleteOnExit();
    // export system view of /a1/b1
    OutputStream out = new FileOutputStream(tmpFile);
    try {
        session.exportSystemView(b1.getPath(), out, false, false);
    } finally {
        out.close();
    }
    // and import again underneath /a3
    InputStream in = new FileInputStream(tmpFile);
    try {
        session.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
        session.save();
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
    // verify there's another element in the shared set
    Node[] shared = getSharedSet(b1);
    assertEquals(3, shared.length);
    // verify child c has not been duplicated
    Node[] children = toArray(b1.getNodes());
    assertEquals(1, children.length);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 65 with Workspace

use of javax.jcr.Workspace in project jackrabbit by apache.

the class ShareableNodeTest method testCloneMultipleTimes.

/**
     * Clone a mix:shareable node to the same workspace multiple times, remove
     * all parents and save. Exposes an error that occurred when having more
     * than two members in a shared set and parents were removed in the same
     * order they were created.
     */
public void testCloneMultipleTimes() throws Exception {
    final int count = 10;
    Node[] parents = new Node[count];
    // setup parent nodes and first child
    for (int i = 0; i < parents.length; i++) {
        parents[i] = testRootNode.addNode("a" + (i + 1));
    }
    Node b = parents[0].addNode("b");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b, mixShareable);
    b.save();
    Workspace workspace = b.getSession().getWorkspace();
    // clone to all other nodes
    for (int i = 1; i < parents.length; i++) {
        workspace.clone(workspace.getName(), b.getPath(), parents[i].getPath() + "/b", false);
    }
    // remove all parents and save
    for (int i = 0; i < parents.length; i++) {
        parents[i].remove();
    }
    testRootNode.getSession().save();
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Aggregations

Workspace (javax.jcr.Workspace)105 Node (javax.jcr.Node)51 Session (javax.jcr.Session)25 AccessDeniedException (javax.jcr.AccessDeniedException)18 Test (org.junit.Test)18 RepositoryException (javax.jcr.RepositoryException)16 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)16 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)10 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)8 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)7 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ObservationManager (javax.jcr.observation.ObservationManager)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 FileOutputStream (java.io.FileOutputStream)5 NodeIterator (javax.jcr.NodeIterator)4 Version (javax.jcr.version.Version)4