Examples of VersionHistory


Examples of javax.jcr.version.VersionHistory

             * had been exported, removed and re-imported with either
             * IMPORT_UUID_COLLISION_REMOVE_EXISTING or
             * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
             * otherwise create a new version history
             */
            VersionHistory history = versionManager.getVersionHistory(session, node);
            if (history == null) {
                history = versionManager.createVersionHistory(session, node);
            }
            Version rootVersion = history.getRootVersion();

            // jcr:versionHistory
            conditionalAddProperty(
                    node, QName.JCR_VERSIONHISTORY, PropertyType.REFERENCE, false,
                    InternalValue.create(new UUID(history.getUUID())));

            // jcr:baseVersion
            conditionalAddProperty(
                    node, QName.JCR_BASEVERSION, PropertyType.REFERENCE, false,
                    InternalValue.create(new UUID(rootVersion.getUUID())));
View Full Code Here

Examples of javax.jcr.version.VersionHistory

                restoredChild = addNode(f.getName(), f);
                restoredChild.restoreFrozenState(f, vsel, restored, removeExisting);

            } else if (child instanceof InternalFrozenVersionHistory) {
                InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
                VersionHistory history = (VersionHistory) session.getNodeById(f.getVersionHistoryId());
                NodeId nodeId = NodeId.valueOf(history.getVersionableUUID());
                String oldVersion = "jcr:dummy";

                // check if representing versionable already exists somewhere
                if (itemMgr.itemExists(nodeId)) {
                    NodeImpl n = session.getNodeById(nodeId);
                    if (removeExisting) {
                        String dstPath = getPath() + "/" + n.getName();
                        if (!n.getPath().equals(dstPath)) {
                            session.move(n.getPath(), dstPath);
                        }
                        oldVersion = n.getBaseVersion().getName();
                    } else if (n.getParent().isSame(this)) {
                        n.internalRemove(true);
                    } else {
                        // since we delete the OPV=Copy children beforehand, all
                        // found nodes must be outside of this tree
                        throw new ItemExistsException("Unable to restore node, item already exists outside of restored tree: "
                                + n.safeGetJCRPath());
                    }
                }
                // get desired version from version selector
                VersionImpl v = (VersionImpl) vsel.select(history);

                // check existing version of item exists
                if (!itemMgr.itemExists(nodeId)) {
                    if (v == null) {
                        // if version selector was unable to select version,
                        // choose the initial one
                        Version[] vs = history.getRootVersion().getSuccessors();
                        if (vs.length == 0) {
                            String msg = "Unable to select appropariate version for " +
                                    child.getName() + " using " + vsel;
                            log.error(msg);
                            throw new VersionException(msg);
                        }
                        v = (VersionImpl) vs[0];
                    }
                    restoredChild = addNode(child.getName(), v.getFrozenNode());
                } else {
                    restoredChild = session.getNodeById(nodeId);
                    if (v == null || oldVersion == null || v.getName().equals(oldVersion)) {
                        v = null;
                    }
                }
                if (v != null) {
                    try {
                        restoredChild.internalRestore(v, vsel, removeExisting);
                    } catch (RepositoryException e) {
                        log.error("Error while restoring node: " + e.toString());
                        log.error("  child path: " + restoredChild.safeGetJCRPath());
                        log.error("  selected version: " + v.getName());
                        StringBuffer avail = new StringBuffer();
                        VersionIterator vi = history.getAllVersions();
                        while (vi.hasNext()) {
                            avail.append(vi.nextVersion().getName());
                            if (vi.hasNext()) {
                                avail.append(", ");
                            }
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        cal1.setTime(vDate1);
        final ResourceResolver resourceResolver = mock(ResourceResolver.class);
        final Session session = mock(Session.class);
        final Workspace wk =  mock(Workspace.class);
        final VersionManager vm =  mock(VersionManager.class);
        final VersionHistory vh =  mock(VersionHistory.class);
        final VersionIterator vi =  mock(VersionIterator.class);
        final Version v = mock(Version.class);
        final Version v1 = mock(Version.class);
        when(v.getCreated()).thenReturn(cal);
        when(v1.getCreated()).thenReturn(cal1);
        when(v.getName()).thenReturn("version1");
        when(vi.nextVersion()).thenReturn(v, v1);
        when(vi.hasNext()).thenReturn(true, true, false);
        when(session.getWorkspace()).thenReturn(wk);
        when(wk.getVersionManager()).thenReturn(vm);
        when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
        when(vm.getVersionHistory(rootPaths[0])).thenReturn(vh);
        when(vh.getAllVersions()).thenReturn(vi);


        final Resource res = mock(Resource.class);
        when(res.getPath()).thenReturn(rootPaths[0]);
        final Node node = mock(Node.class);
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        assertTrue(testNode.hasNode("target/copied"));

        Node copy = testNode.getNode("target/copied");

        assertTrue(copy.isNodeType(JcrConstants.MIX_VERSIONABLE));
        VersionHistory copiedVh = copy.getVersionHistory();
        assertFalse(copy.getVersionHistory().isSame(toCopy.getVersionHistory()));

        assertTrue(copiedVh.hasProperty(VersionConstants.JCR_COPIED_FROM));
        Node copiedFrom = copiedVh.getProperty(VersionConstants.JCR_COPIED_FROM).getNode();
        assertTrue(baseV.isSame(copiedFrom));
    }
View Full Code Here

Examples of javax.jcr.version.VersionHistory

     */
    @Test
    public void testAccessVersionContentWithoutStoreAccess() throws Exception {
        Node n = createVersionableNode(superuser.getNode(path));
        Version v = n.checkin();
        VersionHistory vh = n.getVersionHistory();
        n.checkout();
        Version v2 = n.checkin();
        n.checkout();

        testSession.refresh(false);
        assertFalse(testAcMgr.hasPrivileges(n.getPath(), versionPrivileges));
        AccessControlList acl = deny(SYSTEM, privilegesFromName(Privilege.JCR_READ));

        try {
            // version information must still be accessible
            assertTrue(testSession.nodeExists(v.getPath()));
            assertTrue(testSession.nodeExists(v2.getPath()));
            assertTrue(testSession.nodeExists(vh.getPath()));

        } finally {
            for (AccessControlEntry entry : acl.getAccessControlEntries()) {
                if (entry.getPrincipal().equals(testUser.getPrincipal())) {
                    acl.removeAccessControlEntry(entry);
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        testNode.checkin();
        testNode.checkout();

        // accessing the version history must be allowed if the versionable node
        // is readable to the editing test session.
        VersionHistory vh = testNode.getVersionHistory();
        String vhPath = vh.getPath();
        String vhUUID = vh.getIdentifier();
        assertTrue(vh.isSame(testNode.getSession().getNode(vhPath)));
        assertTrue(vh.isSame(testNode.getSession().getNodeByIdentifier(vhUUID)));
        assertTrue(vh.isSame(testNode.getSession().getNodeByUUID(vhUUID)));
    }
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        Node testNode = testSession.getNode(n.getPath());
        testNode.checkin();
        testNode.checkout();

        VersionHistory vh = testNode.getVersionHistory();
        String vhPath = vh.getPath();
        String vhUUID = vh.getIdentifier();

        // revert read permission on the versionable node
        modify(n.getPath(), Privilege.JCR_READ, false);

        // versionable node is not readable any more for test session.
        assertFalse(testSession.nodeExists(n.getPath()));

        // access version history directly => should fail
        try {
            VersionHistory history = (VersionHistory) testSession.getNode(vhPath);
            fail("Access to version history should be denied if versionable node is not accessible");
        } catch (PathNotFoundException e) {
            // success
        }

        try {
            VersionHistory history = (VersionHistory) testSession.getNodeByIdentifier(vhUUID);
            fail("Access to version history should be denied if versionable node is not accessible");
        } catch (ItemNotFoundException e) {
            // success
        }

        try {
            VersionHistory history = (VersionHistory) testSession.getNodeByUUID(vhUUID);
            fail("Access to version history should be denied if versionable node is not accessible");
        } catch (ItemNotFoundException e) {
            // success
        }
    }
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        n.checkin();
        n.checkout();

        String versionablePath = n.getPath();
        VersionHistory vh = n.getVersionHistory();
        String vhPath = vh.getPath();
        String vhUUID = vh.getIdentifier();

        // remove the versionable node
        n.remove();
        superuser.save();

        testSession.refresh(false);
        assertTrue(testSession.nodeExists(path));
        assertFalse(testSession.nodeExists(versionablePath));

        // accessing the version history directly should still succeed as
        // read permission is still granted on the tree defined by the parent.
        VersionHistory history = (VersionHistory) testSession.getNode(vhPath);
        history = (VersionHistory) testSession.getNodeByIdentifier(vhUUID);
        history = (VersionHistory) testSession.getNodeByUUID(vhUUID);

        // revoking read permission on the parent node -> version history
        // must no longer be accessible
View Full Code Here

Examples of javax.jcr.version.VersionHistory

        testNode.checkout();
        Version v2 = testNode.checkin();
        testNode.checkout();

        // -> VersionHistory.addVersionLabel must be allowed
        VersionHistory history = testNode.getVersionHistory();
        history.addVersionLabel(v.getName(), "testLabel", false);
        history.addVersionLabel(v2.getName(), "testLabel", true);

        VersionManager vMgr = testSession.getWorkspace().getVersionManager();
        history = vMgr.getVersionHistory(testNode.getPath());
        history.addVersionLabel(v.getName(), "testLabel", true);
    }
View Full Code Here

Examples of javax.jcr.version.VersionHistory

     */
    @Test
    public void testVersionablePath() throws Exception {
        Node n = createVersionableNode(superuser.getNode(path));

        VersionHistory vh = n.getVersionHistory();
        Property versionablePath = vh.getProperty(superuser.getWorkspace().getName());
        assertEquals(n.getPath(), versionablePath.getString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.