Search in sources :

Example 81 with Workspace

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

the class ShareableNodeTest method testImportDocumentViewCollision.

/**
     * Verify document view import via workspace (6.13.14). Export a document
     * 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 testImportDocumentViewCollision() 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.exportDocumentView(b1.getPath(), out, false, false);
    } finally {
        out.close();
    }
    // and import again underneath /a3
    InputStream in = new FileInputStream(tmpFile);
    try {
        workspace.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
    } 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 82 with Workspace

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

the class ShareableNodeTest method testGetNode.

/**
     * Verify that the shareable node returned by Node.getNode() has the right
     * name.
     */
public void testGetNode() 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
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // a1.getNode("b1") should return b1
    b1 = a1.getNode("b1");
    assertEquals("b1", b1.getName());
    // a2.getNode("b2") should return b2
    Node b2 = a2.getNode("b2");
    assertEquals("b2", b2.getName());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 83 with Workspace

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

the class ShareableNodeTest method testGetNodes.

/**
     * Verify that the shareable nodes returned by Node.getNodes() have
     * the right name.
     */
public void testGetNodes() 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
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // a1.getNodes() should return b1
    Node[] children = toArray(a1.getNodes());
    assertEquals(1, children.length);
    assertEquals("b1", children[0].getName());
    // a2.getNodes() should return b2
    children = toArray(a2.getNodes());
    assertEquals(1, children.length);
    assertEquals("b2", children[0].getName());
}
Also used : Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 84 with Workspace

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

the class CopyTest method testCopy.

public void testCopy() throws RepositoryException {
    Workspace wsp = superuser.getWorkspace();
    VersionManager vMgr = wsp.getVersionManager();
    String srcPath = versionableNode.getPath();
    String dstPath = getProperty("destination");
    wsp.copy(srcPath, dstPath);
    // check versionable
    Node v = superuser.getNode(dstPath);
    assertTrue("Copied Node.isNodeType(mix:cersionable) must return true.", v.isNodeType(mixVersionable));
    // check different version history
    VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
    VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
    assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
    // check if 1 version
    assertEquals("Copied node must have 1 version.", 1, getNumberOfVersions(vh2));
    // check if jcr:copiedFrom is set correctly
    assertTrue("Version history of desination must have a jcr:copiedFrom property", vh2.hasProperty(jcrCopiedFrom));
    Node ref = vh2.getProperty(jcrCopiedFrom).getNode();
    Version base = vMgr.getBaseVersion(srcPath);
    assertTrue("jcr:copiedFrom must point to the base version of the original.", ref.isSame(base));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Workspace(javax.jcr.Workspace)

Example 85 with Workspace

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

the class CreateWorkspace method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String name = (String) ctx.get(this.nameKey);
    if (log.isDebugEnabled()) {
        log.debug("creating workspace for name " + name);
    }
    Workspace w = CommandHelper.getSession(ctx).getWorkspace();
    if (!(w instanceof WorkspaceImpl)) {
        throw new IllegalStateException(bundle.getString("phrase.jackrabbit.command"));
    }
    WorkspaceImpl jrw = (WorkspaceImpl) w;
    jrw.createWorkspace(name);
    return false;
}
Also used : WorkspaceImpl(org.apache.jackrabbit.core.WorkspaceImpl) 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