Package javax.jcr.version

Examples of javax.jcr.version.VersionManager


        Node node = testRootNode.addNode(nodeName1, ntUnstructured);
        node.addMixin(mixVersionable);
        Node child = node.addNode(nodeName2, ntUnstructured);
        child.addMixin(mixReferenceable);
        superuser.save();
        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
        vMgr.checkin(node.getPath());
    }
View Full Code Here


* <code>RestoreTest</code>...
*/
public class RestoreTest extends AbstractJCRTest {

    public void testSimpleRestore() throws RepositoryException {
        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
        Node n = testRootNode.addNode(nodeName1, testNodeType);
        n.addMixin(mixVersionable);
        n.setProperty("prop", "a");
        superuser.save();
        String path = n.getPath();
        Version v = vMgr.checkpoint(path); // 1.0
        n.setProperty("prop", "b");
        superuser.save();
        vMgr.checkpoint(path); // 1.1
        n.remove();
        superuser.save();
        vMgr.restore(path, v, true);
        assertTrue(superuser.nodeExists(path));
        n = superuser.getNode(path);
        assertEquals("Property not restored", "a", n.getProperty("prop").getString());
    }
View Full Code Here

    public void testGetNodeByIdentifier() throws RepositoryException {
        Node n = testRootNode.addNode(nodeName1, testNodeType);
        n.addMixin(mixVersionable);
        superuser.save();
        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
        String id = vMgr.getBaseVersion(n.getPath()).getIdentifier();
        assertTrue("Session.getNodeByIdentifier() did not return Version object for a nt:version node.",
                superuser.getNodeByIdentifier(id) instanceof Version);
    }
View Full Code Here

    @SuppressWarnings("deprecation")
    public void testGetNodeByUUID() throws RepositoryException {
        Node n = testRootNode.addNode(nodeName1, testNodeType);
        n.addMixin(mixVersionable);
        superuser.save();
        VersionManager vMgr = superuser.getWorkspace().getVersionManager();
        String uuid = vMgr.getBaseVersion(n.getPath()).getUUID();
        assertTrue("Session.getNodeByUUID() did not return Version object for a nt:version node.",
                superuser.getNodeByUUID(uuid) instanceof Version);
    }
View Full Code Here

        // -> 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

        List<JCRNodeWrapper> toPublish = new ArrayList<JCRNodeWrapper>();
        for (String uuid : uuidsToPublish) {
            toPublish.add(sourceSession.getNodeByUUID(uuid));
        }
        VersionManager sourceVersionManager = sourceSession.getWorkspace().getVersionManager();
        VersionManager destinationVersionManager = destinationSession.getWorkspace().getVersionManager();
        if (destinationSession.getWorkspace().getName().equals(LIVE_WORKSPACE)) {
            for (JCRNodeWrapper jcrNodeWrapper : toPublish) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Publishing node {}", jcrNodeWrapper.getPath());
                }
                if (jcrNodeWrapper.isNodeType("jmix:lastPublished") && (!jcrNodeWrapper.hasProperty("j:published") ||
                        !jcrNodeWrapper.getProperty("j:published").getBoolean())) {
                    if (!sourceVersionManager.isCheckedOut(jcrNodeWrapper.getPath())) {
                        sourceVersionManager.checkout(jcrNodeWrapper.getPath());
                    }
                    jcrNodeWrapper.setProperty("j:published", Boolean.TRUE);
                    try {
                        JCRNodeWrapper destNode = destinationSession
                                .getNode(jcrNodeWrapper.getCorrespondingNodePath(destinationWorkspace));
                        if (!destinationVersionManager.isCheckedOut(destNode.getPath())) {
                            destinationVersionManager.checkout(destNode.getPath());
                        }
                        destNode.setProperty("j:published", Boolean.TRUE);
                    } catch (ItemNotFoundException e) {
                    }
                }
View Full Code Here

    private void mergeToDestinationWorkspace(final List<JCRNodeWrapper> toPublish, final List<String> uuids,
                                             final JCRSessionWrapper sourceSession,
                                             final JCRSessionWrapper destinationSession, Calendar calendar)
            throws RepositoryException {
        final VersionManager sourceVersionManager = sourceSession.getWorkspace().getVersionManager();
        final VersionManager destinationVersionManager = destinationSession.getWorkspace().getVersionManager();

        for (final JCRNodeWrapper node : toPublish) {
            if (node.hasProperty("jcr:mergeFailed")) {
                Value[] failed = node.getProperty("jcr:mergeFailed").getValues();

                for (Value value : failed) {
                    logger.warn("-- Failed merge waiting : " + node.getPath() + " / " + value.getString());
                }
                continue;
            }
        }

        if (toPublish.isEmpty()) {
            return;
        }

        for (JCRNodeWrapper node : toPublish) {
            if (node.isNodeType("jmix:lastPublished")) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Setting last published for {}", node.getPath());
                }
//            if (!sourceSession.getWorkspace().getName().equals(LIVE_WORKSPACE)) {
                VersionManager versionManager = node.getSession().getWorkspace().getVersionManager();
                if (!versionManager.isCheckedOut(node.getPath())) {
                    versionManager.checkout(node.getPath());
                }
                node.setProperty("j:lastPublished", calendar);

                String userID = destinationSession.getUserID();
                if ((userID != null) && (userID.startsWith(JahiaLoginModule.SYSTEM))) {
View Full Code Here

            destinationParent.checkout();
            destinationParent.getNode(sourceNode.getName()).remove();
            destinationSession.save();
        }

        final VersionManager destinationVersionManager = destinationSession.getWorkspace().getVersionManager();

        try {
            Set<String> denied = new HashSet<String>();
            NodeIterator it = sourceNode.getNodes();
            while (it.hasNext()) {
                JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) it.next();
                if (nodeWrapper.isVersioned()) {
                    denied.add(nodeWrapper.getPath());
                }
            }
            JahiaAccessManager.setDeniedPaths(denied);

            if (!destinationVersionManager.isCheckedOut(destinationParentPath)) {
                destinationVersionManager.checkout(destinationParentPath);
            }
            String destinationPath;
            if (destinationParentPath.equals("/")) {
                destinationPath = "/" + sourceNode.getName();
            } else {
                destinationPath = destinationParentPath + "/" + sourceNode.getName();
            }

            try {
                String correspondingNodePath = sourceNode.getCorrespondingNodePath(destinationWorkspaceName);
                logger.warn("Cloning existing node "+sourceNode.getPath());
                if (sourceNode.isNodeType("mix:shareable")) {
                    // Shareable node - todo : check if we need to move or clone

                    String oldPath = handleSharedMove(sourceSession, sourceNode, destinationPath);

                    // Clone the node node in live space
                    destinationSession.getWorkspace()
                            .clone(destinationWorkspaceName, correspondingNodePath, destinationPath, false);

                    if (oldPath != null) {
                        try {
                            JCRNodeWrapper node = destinationSession.getNode(oldPath);
                            recurseCheckout(node, null, destinationVersionManager);
                            JCRNodeWrapper oldParent = node.getParent();
                            if (!destinationVersionManager.isCheckedOut(oldParent.getPath())) {
                                destinationVersionManager.checkout(oldParent.getPath());
                            }
                            node.remove();
                            node.getSession().save();
                        } catch (RepositoryException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    // Non shareable node has been moved
                    destinationVersionManager
                            .checkout(StringUtils.substringBeforeLast(correspondingNodePath, "/")); // previous parent
                    destinationVersionManager.checkout(destinationParentPath); // new parent
                    recurseCheckout(destinationSession.getNode(correspondingNodePath), null,
                            destinationVersionManager); // node and sub nodes

                    destinationSession.move(correspondingNodePath, destinationPath);
                    destinationSession.save();
View Full Code Here

            public Object doInJCR(final JCRSessionWrapper sourceSession) throws RepositoryException {
                boolean first = true;
                for (String uuid : uuids) {
                    try {
                        JCRNodeWrapper node = sourceSession.getNodeByIdentifier(uuid);
                        VersionManager vm = sourceSession.getWorkspace().getVersionManager();
                        if (!vm.isCheckedOut(node.getPath())) {
                            vm.checkout(node.getPath());
                        }
                        if (first && !node.isNodeType("jmix:publication")) {
                            node.addMixin("jmix:publication");
                            first = false;
                        }
View Full Code Here

     */
    public void addNewVersionFile(JCRNodeWrapper node, String tmpName) throws GWTJahiaServiceException {
        try {
            if (node != null) {
                JCRSessionWrapper session = node.getSession();
                VersionManager versionManager = session.getWorkspace().getVersionManager();
                if (!node.isVersioned()) {
                    node.versionFile();
                    session.save();
                }
                VersionIterator allVersions = versionManager.getVersionHistory(node.getPath()).getAllVersions();
                if(allVersions.getSize()==1) {
                    // First version ever apart root version
                    versionManager.checkpoint(node.getPath());
                    String label = "uploaded_at_"+ new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(node.getProperty("jcr:created").getDate().getTime());
                    versionService.addVersionLabel(node,label);
                }
                versionManager.checkout(node.getPath());
                GWTFileManagerUploadServlet.Item item = GWTFileManagerUploadServlet.getItem(tmpName);
                InputStream is = null;
                try {
                    is = item.getStream();
                    node.getFileContent().uploadFile(is, item.getContentType());
                } catch (FileNotFoundException e) {
                    throw new GWTJahiaServiceException(e.getMessage());
                } finally {
                    IOUtils.closeQuietly(is);
                    item.dispose();
                }
               
                session.save();
                versionManager.checkpoint(node.getPath());
                String label = "uploaded_at_"+ new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(GregorianCalendar.getInstance().getTime());
                versionService.addVersionLabel(node,label);
                cacheManager.invalidate(session.getWorkspace().getName(), node.getPath());
                if (logger.isDebugEnabled()) {
                    logger.debug("Number of version: " + node.getVersions().size());
View Full Code Here

TOP

Related Classes of javax.jcr.version.VersionManager

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.