Package javax.jcr.version

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


        // add all versions to map of versions to restore
        final HashMap toRestore = new HashMap();
        for (int i = 0; i < versions.length; i++) {
            AbstractVersion v = (AbstractVersion) versions[i];
            VersionHistory vh = v.getContainingHistory();
            // check for collision
            if (toRestore.containsKey(vh.getUUID())) {
                throw new VersionException("Unable to restore. Two or more versions have same version history.");
            }
            toRestore.put(vh.getUUID(), v);
        }

        // create a version selector to the set of versions
        VersionSelector vsel = new VersionSelector() {
            public Version select(VersionHistory versionHistory) throws RepositoryException {
View Full Code Here

                     * copied properties declared by mix:versionable need to be
                     * adjusted accordingly.
                     */
                    // jcr:versionHistory
                    if (propName.equals(QName.JCR_VERSIONHISTORY)) {
                        VersionHistory vh = getOrCreateVersionHistory(newState);
                        newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getUUID()))});
                    }

                    // jcr:baseVersion
                    if (propName.equals(QName.JCR_BASEVERSION)) {
                        VersionHistory vh = getOrCreateVersionHistory(newState);
                        newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
                    }

                    // jcr:predecessors
                    if (propName.equals(QName.JCR_PREDECESSORS)) {
                        VersionHistory vh = getOrCreateVersionHistory(newState);
                        newChildState.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
                    }

                    // jcr:isCheckedOut
                    if (propName.equals(QName.JCR_ISCHECKEDOUT)) {
                        newChildState.setValues(new InternalValue[]{InternalValue.create(true)});
View Full Code Here

     * @throws RepositoryException if an error occurs
     */
    private VersionHistory getOrCreateVersionHistory(NodeState node)
            throws RepositoryException {
        VersionManager vMgr = session.getVersionManager();
        VersionHistory vh = vMgr.getVersionHistory(session, node);
        if (vh == null) {
            // create a new version history
            vh = vMgr.createVersionHistory(session, node);
        }
        return vh;
View Full Code Here

             * 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 vh = vMgr.getVersionHistory(session, node);
            if (vh == null) {
                vh = vMgr.createVersionHistory(session, node);
            }

            // jcr:versionHistory
            if (!node.hasPropertyName(QName.JCR_VERSIONHISTORY)) {
                def = itemOps.findApplicablePropertyDefinition(QName.JCR_VERSIONHISTORY,
                        PropertyType.REFERENCE, false, node);
                prop = itemOps.createPropertyState(node, QName.JCR_VERSIONHISTORY,
                        PropertyType.REFERENCE, def);
                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getUUID()))});
            }

            // jcr:baseVersion
            if (!node.hasPropertyName(QName.JCR_BASEVERSION)) {
                def = itemOps.findApplicablePropertyDefinition(QName.JCR_BASEVERSION,
                        PropertyType.REFERENCE, false, node);
                prop = itemOps.createPropertyState(node, QName.JCR_BASEVERSION,
                        PropertyType.REFERENCE, def);
                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
            }

            // jcr:predecessors
            if (!node.hasPropertyName(QName.JCR_PREDECESSORS)) {
                def = itemOps.findApplicablePropertyDefinition(QName.JCR_PREDECESSORS,
                        PropertyType.REFERENCE, true, node);
                prop = itemOps.createPropertyState(node, QName.JCR_PREDECESSORS,
                        PropertyType.REFERENCE, def);
                prop.setValues(new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
            }

            // jcr:isCheckedOut
            if (!node.hasPropertyName(QName.JCR_ISCHECKEDOUT)) {
                def = itemOps.findApplicablePropertyDefinition(QName.JCR_ISCHECKEDOUT,
View Full Code Here

                         * node 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 vh = vMgr.getVersionHistory(session, nodeState);
                        if (vh == null) {
                            vh = vMgr.createVersionHistory(session, nodeState);
                        }
                        node.internalSetProperty(QName.JCR_VERSIONHISTORY, InternalValue.create(new UUID(vh.getUUID())));
                        node.internalSetProperty(QName.JCR_BASEVERSION, InternalValue.create(new UUID(vh.getRootVersion().getUUID())));
                        node.internalSetProperty(QName.JCR_ISCHECKEDOUT, InternalValue.create(true));
                        node.internalSetProperty(QName.JCR_PREDECESSORS,
                                new InternalValue[]{InternalValue.create(new UUID(vh.getRootVersion().getUUID()))});
                        createdTransientState = true;
                    }
                }
            }
        }
View Full Code Here

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

            } else if (child instanceof InternalFrozenVersionHistory) {
                InternalFrozenVersionHistory f = (InternalFrozenVersionHistory) child;
                VersionHistory history = (VersionHistory) session.getNodeByUUID(f.getVersionHistoryId());
                String nodeId = history.getVersionableUUID();

                // check if representing versionable already exists somewhere
                if (itemMgr.itemExists(new NodeId(nodeId))) {
                    NodeImpl n = (NodeImpl) session.getNodeByUUID(nodeId);
                    if (n.getParent().isSame(this)) {
View Full Code Here

        assertTrue(versionable.isNodeType("nt:myversionable"));
        assertTrue(versionable.isNodeType("nt:unstructured"));
        assertTrue(versionable.isNodeType("mix:versionable"));
        assertFalse(versionable.isCheckedOut());

        VersionHistory history = versionable.getVersionHistory();
        Version versionB = versionable.getBaseVersion();
        String[] labels = history.getVersionLabels(versionB);
        assertEquals(1, labels.length);
        assertEquals("labelB", labels[0]);
        Version versionA = history.getVersionByLabel("labelA");
        versionable.restore(versionA, true);
        assertEquals("A", versionable.getProperty("foo").getString());
        versionable.restore(versionB, true);
        assertEquals("B", versionable.getProperty("foo").getString());
        return versionable;
View Full Code Here

        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));
    }
View Full Code Here

    /**
     * @see Version#getLinearSuccessor()
     */
    public Version getLinearSuccessor() throws RepositoryException {
        // TODO: improve.
        VersionHistory vh = getContainingHistory();
        for (VersionIterator it = vh.getAllLinearVersions(); it.hasNext();) {
            Version v = it.nextVersion();
            if (isSame(v.getLinearPredecessor())) {
                return v;
            }
        }
View Full Code Here

TOP

Related Classes of javax.jcr.version.VersionHistory

Copyright © 2018 www.massapicom. 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.