Search in sources :

Example 1 with Workspace

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

the class JcrProducerDifferentWorkspaceTest method testJcrProducer.

@Test
public void testJcrProducer() throws Exception {
    Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    String uuid = out.getOut().getBody(String.class);
    Session session = openSession(CUSTOM_WORKSPACE_NAME);
    try {
        Node node = session.getNodeByIdentifier(uuid);
        Workspace workspace = session.getWorkspace();
        assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName());
        assertNotNull(node);
        assertEquals("/home/test/node", node.getPath());
        assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) Node(javax.jcr.Node) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 2 with Workspace

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

the class WorkspaceTest method testCreateWorkspace.

public void testCreateWorkspace() throws Exception {
    Session s = null;
    try {
        Workspace wsp = superuser.getWorkspace();
        String name = getNewWorkspaceName(wsp);
        wsp.createWorkspace(name);
        List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertTrue(wsps.contains(name));
        s = getHelper().getSuperuserSession(name);
        Workspace newW = s.getWorkspace();
        assertEquals(name, newW.getName());
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } catch (UnsupportedOperationException e) {
        throw new NotExecutableException();
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 3 with Workspace

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

the class WorkspaceTest method testCreateWorkspaceFromSource.

public void testCreateWorkspaceFromSource() throws Exception {
    Session s = null;
    try {
        Workspace wsp = superuser.getWorkspace();
        String name = getNewWorkspaceName(wsp);
        wsp.createWorkspace(name, wsp.getName());
        List<String> wsps = Arrays.asList(wsp.getAccessibleWorkspaceNames());
        assertTrue(wsps.contains(name));
        s = getHelper().getSuperuserSession(name);
        Workspace newW = s.getWorkspace();
        assertEquals(name, newW.getName());
    } catch (UnsupportedRepositoryOperationException e) {
        throw new NotExecutableException();
    } catch (UnsupportedOperationException e) {
        throw new NotExecutableException();
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace)

Example 4 with Workspace

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

the class Clone method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String srcWorkspace = (String) ctx.get(this.srcWorkspaceKey);
    String srcAbsPath = (String) ctx.get(this.srcAbsPathKey);
    String destAbsPath = (String) ctx.get(this.destAbsPathKey);
    Boolean removeExisting = Boolean.valueOf((String) ctx.get(this.removeExistingKey));
    Workspace w = CommandHelper.getSession(ctx).getWorkspace();
    if (log.isDebugEnabled()) {
        log.debug("cloning node. from [" + srcWorkspace + ":" + srcAbsPath + "] to [" + w.getName() + ":" + destAbsPath + "]");
    }
    w.clone(srcWorkspace, srcAbsPath, destAbsPath, removeExisting.booleanValue());
    return false;
}
Also used : Workspace(javax.jcr.Workspace)

Example 5 with Workspace

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

the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.

/**
     * Test orphan version history cleaning in multiple workspace.
     * @throws RepositoryException if an error occurs.
     */
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    testRootNode.save();
    Session session = n.getSession();
    VersionHistory vh = n.getVersionHistory();
    String vhUuid = vh.getUUID();
    assertExists(session, vhUuid);
    // First version
    Version v10 = n.checkin();
    n.checkout();
    Workspace defaultWorkspace = n.getSession().getWorkspace();
    Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
    // Clone the node in another workspace
    otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
    Node otherWsRootNode = otherWsSession.getRootNode();
    Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
    // Ensure that version histories are the same
    assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
    Version v11 = clonedNode.checkin();
    clonedNode.checkout();
    // Remove node
    n.remove();
    testRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the first version
    vh.removeVersion(v10.getName());
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove cloned node
    clonedNode.remove();
    otherWsRootNode.save();
    assertExists(session, vhUuid);
    assertExists(otherWsSession, vhUuid);
    // Remove the last version
    vh.removeVersion(v11.getName());
    try {
        session.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the default workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
    try {
        otherWsSession.getNodeByUUID(vhUuid);
        fail("Orphan version history must have been removed from the other workspace");
    } catch (ItemNotFoundException e) {
    // Expected
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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