Package org.jahia.services.content

Examples of org.jahia.services.content.JCRPublicationService


                LanguageCodeConverters.languageCodeToLocale(defaultLanguage));
    }

    @Test
    public void testCPagesWithSubPages() throws Exception {
        JCRPublicationService jcrService = ServicesRegistry.getInstance().getJCRPublicationService();

        getCleanSession();
        JCRNodeWrapper englishEditSiteRootNode = englishEditSession.getNode(SITECONTENT_ROOT_NODE);
        JCRNodeWrapper englishEditSiteHomeNode = (JCRNodeWrapper) englishEditSiteRootNode.getNode("home");
        String englishEditSiteHomeNodeIdentifier = englishEditSiteHomeNode.getIdentifier();

        // now let's setup the pages we will use.

        JCRNodeWrapper englishEditPage1Node = englishEditSiteHomeNode.addNode("page1", "jnt:page");
        String englishEditPage1NodeIdentifier = englishEditPage1Node.getIdentifier();
        englishEditPage1Node.setProperty("jcr:title", "Page1");
        TestHelper.createList(englishEditPage1Node, "contentList0", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        TestHelper.createList(englishEditPage1Node, "contentList1", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        JCRNodeWrapper englishEditPage2Node = englishEditSiteHomeNode.addNode("page2", "jnt:page");
        englishEditPage2Node.setProperty("jcr:title", "Page2");
        TestHelper.createList(englishEditPage2Node, "contentList0", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        TestHelper.createList(englishEditPage2Node, "contentList1", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        JCRNodeWrapper englishEditPage3Node = englishEditSiteHomeNode.addNode("page3", "jnt:page");
        englishEditPage3Node.setProperty("jcr:title", "Page3");
        TestHelper.createList(englishEditPage3Node, "contentList0", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        TestHelper.createList(englishEditPage3Node, "contentList1", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);

        JCRNodeWrapper englishEditSubPage1Node = englishEditPage1Node.addNode("page1_subpage1", "jnt:page");
        englishEditSubPage1Node.setProperty("jcr:title", "SubPage1");
        TestHelper.createList(englishEditSubPage1Node, "contentList0", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        TestHelper.createList(englishEditSubPage1Node, "contentList1", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        JCRNodeWrapper englishEditSubPage2Node = englishEditPage1Node.addNode("page1_subpage2", "jnt:page");
        englishEditSubPage2Node.setProperty("jcr:title", "SubPage2");
        TestHelper.createList(englishEditSubPage2Node, "contentList0", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);
        TestHelper.createList(englishEditSubPage2Node, "contentList1", 5, INITIAL_ENGLISH_TEXT_NODE_PROPERTY_VALUE);

        englishEditSession.save();

        Set<String> languages = null;
        jcrService.publishByMainId(englishEditSiteHomeNodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        jcrService.publishByMainId(englishEditPage1NodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        jcrService.publishByMainId(englishEditPage2Node.getIdentifier(), Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        jcrService.publishByMainId(englishEditSubPage1Node.getIdentifier(), Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);

        getCleanSession();

        // Case 1 : let's check the existence of the node property value in the live workspace.
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have been published");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/contentList0",
                "ContentList0 on Page 1 should have been published");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/contentList0/contentList0_text0",
                "Text0 in ContentList0 on Page 1 should have been published");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1",
                "Sub Page 1 should have been published");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1/contentList1",
                "ContentList1 on Sub Page 1 should have been published");
        testNodeInWorkspace(englishLiveSession,
                SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1/contentList1/contentList1_text1",
                "Text1 in ContentList1 on Sub Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2",
                "Sub Page 2 should not have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2/contentList1",
                "ContentList1 on Sub Page 2 should not have been published");
        testNodeNotInWorkspace(englishLiveSession,
                SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2/contentList1/contentList1_text1",
                "Text1 in ContentList1 on Sub Page 2 should not have been published");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page2",
                "Page 2 should have been published");

        // Case 2 : now let's modify the node, republish and check.
        englishEditSession.checkout(englishEditSession.getNodeByIdentifier(englishEditPage1NodeIdentifier));
        englishEditSession.move(SITECONTENT_ROOT_NODE + "/home/page1/contentList0",
                SITECONTENT_ROOT_NODE + "/home/page1/contentList0_renamed");
        englishEditSession.save();

        jcrService.publishByMainId(englishEditPage1NodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);

        getCleanSession();

        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/contentList0",
                "ContentList0 on Page 1 not be present anymore since we renamed it.");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/contentList0_renamed",
                "ContentList0_renamed on Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2",
                "Sub Page 2 should not have been published");

        // Case 3 : now let's unpublish the node and test it's presence in the live workspace.
        getCleanSession();
        jcrService.unpublish(Collections.singletonList(englishEditPage1NodeIdentifier), languages);
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have been unpublished !");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1",
                "Sub Page 1 should not have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2",
                "Sub Page 2 should not have been published");
        getCleanSession();
        // Case 4 : now let's republish the node and test it's presence in the live workspace.
        jcrService.publishByMainId(englishEditPage1NodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have be published !");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1",
                "Sub Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2",
                "Sub Page 2 should not have been published");

        getCleanSession();
        // Case 5 : let's rename the page and check it's been properly renamed in the live workspace.
        englishEditSession.checkout(englishEditSession.getNodeByIdentifier(englishEditSiteHomeNodeIdentifier));
        englishEditSession.move(SITECONTENT_ROOT_NODE + "/home/page1", SITECONTENT_ROOT_NODE + "/home/page1_renamed");
        englishEditSession.save();
        jcrService.publishByMainId(englishEditPage1NodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1_renamed",
                "Page 1 should have be published !");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1_renamed/page1_subpage1",
                "Sub Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1_renamed/page1_subpage2",
                "Sub Page 2 should not have been published");
        // now let's move it back to continue the tests.
        englishEditSession.checkout(englishEditSession.getNodeByIdentifier(englishEditSiteHomeNodeIdentifier));
        englishEditSession.move(SITECONTENT_ROOT_NODE + "/home/page1_renamed", SITECONTENT_ROOT_NODE + "/home/page1");
        englishEditSession.save();
        jcrService.publishByMainId(englishEditPage1NodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, false, null);
        getCleanSession();
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have be published !");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage1",
                "Sub Page 1 should have been published");
        testNodeNotInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1/page1_subpage2",
                "Sub Page 2 should not have been published");

        // Case 6 : now we must move the page inside the list of the parent page, and check that the move is properly propagated in live mode
        englishEditSiteHomeNode = englishEditSession.getNodeByIdentifier(englishEditSiteHomeNodeIdentifier);
        englishEditSession.checkout(englishEditSiteHomeNode);
        englishEditSiteHomeNode.orderBefore("page1", null); // this should put it at the end of the list.
        englishEditSession.save();
        testChildOrdering(englishEditSiteHomeNode, Constants.EDIT_WORKSPACE, "page2", "page3", "page1");
        jcrService.publishByMainId(englishEditSiteHomeNodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, true, null);
        JCRNodeWrapper englishLiveSiteHomeNode = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home");
        testChildOrdering(englishLiveSiteHomeNode, Constants.LIVE_WORKSPACE, "page2", "page3", "page1");
        getCleanSession();
        // Case 7 : now let's move the page to another page
        JCRNodeWrapper editPage1 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page1");
        englishEditSession.checkout(englishEditSession.getNodeByIdentifier(englishEditSiteHomeNodeIdentifier));
        JCRNodeWrapper editPage2 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page2");
        englishEditSession.checkout(editPage2);
        englishEditSession.checkout(
                editPage1); // we have to check it out because of a property being changed during move !
        englishEditSession.move(editPage1.getPath(), SITECONTENT_ROOT_NODE + "/home/page2/page1");
        editPage2.orderBefore("page1", "contentList1");
        englishEditSession.save();
        jcrService.publishByMainId(englishEditSiteHomeNodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, true, null);
        JCRNodeWrapper liveSiteHomeNode = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home");
        JCRNodeWrapper livePage2 = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home/page2");
        testChildOrdering(liveSiteHomeNode, Constants.LIVE_WORKSPACE, "page2", "page3");
        testChildOrdering(livePage2, Constants.LIVE_WORKSPACE, "contentList0", "page1", "contentList1");
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page2/page1",
                "Page 1 was not properly moved below page 2 in the live workspace.");

        getCleanSession();

        // Case 8 : now let's move it to yet another list, modify it, then publish it.
        editPage2 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page2");
        englishEditSession.checkout(editPage2);
        JCRNodeWrapper editPage3 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page3");
        englishEditSession.checkout(editPage3);
        editPage1 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page2/page1");
        englishEditSession.checkout(editPage1);
        englishEditSession.move(editPage1.getPath(), SITECONTENT_ROOT_NODE + "/home/page3/page1");
        editPage3.orderBefore("page1", "contentList1");
        editPage1 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page3/page1");
        editPage1.addNode("anotherList", "jnt:contentList");
        englishEditSession.save();
        jcrService.publishByMainId(englishEditSiteHomeNodeIdentifier, Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, true, null);

        liveSiteHomeNode = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home");
        livePage2 = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home/page2");
        JCRNodeWrapper livePage3 = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home/page3");
View Full Code Here


        }
    */
    @Test
    public void testAddMixinAndPublish() throws RepositoryException {
        JCRPublicationService jcrService = ServicesRegistry.getInstance().getJCRPublicationService();

        String defaultLanguage = site.getDefaultLanguage();

        JCRSessionWrapper englishEditSession = jcrService.getSessionFactory().getCurrentUserSession(
                Constants.EDIT_WORKSPACE, Locale.ENGLISH, LanguageCodeConverters.languageCodeToLocale(defaultLanguage));
        JCRSessionWrapper englishLiveSession = jcrService.getSessionFactory().getCurrentUserSession(
                Constants.LIVE_WORKSPACE, Locale.ENGLISH, LanguageCodeConverters.languageCodeToLocale(defaultLanguage));
        JCRNodeWrapper englishEditSiteRootNode = englishEditSession.getNode(SITECONTENT_ROOT_NODE);
        JCRNodeWrapper englishEditSiteHomeNode = (JCRNodeWrapper) englishEditSiteRootNode.getNode("home");

        Set<String> languages = null;

        JCRNodeWrapper englishEditPage1 = englishEditSiteHomeNode.addNode("page1", "jnt:page");
        englishEditPage1.setProperty("jcr:title", "Page1");

        englishEditSession.save();

        jcrService.publishByMainId(englishEditSiteHomeNode.getIdentifier(), Constants.EDIT_WORKSPACE,
                Constants.LIVE_WORKSPACE, languages, true, null);
        testNodeInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1",
                "Page 1 should have been published to live workspace !");

        //  Add mixin to a node already published once, publish it, and verify that the new mixin was properly added.
        englishEditSession.checkout(englishEditPage1);
        englishEditPage1.addMixin("jmix:sitemap");
        englishEditSession.save();
        assertTrue("Page 1 should now have the sitemap mixin type in edit workspace", englishEditPage1.isNodeType(
                "jmix:sitemap"));
        testPropertyInWorkspace(englishEditSession, SITECONTENT_ROOT_NODE + "/home/page1", "changefreq", "monthly",
                "Propery changefreq should have default value of 'monthly'");
        jcrService.publishByMainId(englishEditPage1.getIdentifier(), Constants.EDIT_WORKSPACE, Constants.LIVE_WORKSPACE,
                languages, false, null);
        JCRNodeWrapper englishLivePage1 = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home/page1");
        assertTrue("Page 1 should now have the sitemap mixin type in live workspace", englishLivePage1.isNodeType(
                "jmix:sitemap"));
        testPropertyInWorkspace(englishLiveSession, SITECONTENT_ROOT_NODE + "/home/page1", "changefreq", "monthly",
                "Propery changefreq should have default value of 'monthly'");

        englishEditPage1 = englishEditSession.getNode(SITECONTENT_ROOT_NODE + "/home/page1");
        englishEditSession.checkout(englishEditPage1);
        englishEditPage1.removeMixin("jmix:sitemap");
        englishEditSession.save();
        assertFalse("Page 1 should now no longer have the sitemap mixin in the edit workspace!",
                englishEditPage1.isNodeType("jmix:sitemap"));
        jcrService.publishByMainId(englishEditPage1.getIdentifier(), Constants.EDIT_WORKSPACE, Constants.LIVE_WORKSPACE,
                languages, false, null);
        englishLivePage1 = englishLiveSession.getNode(SITECONTENT_ROOT_NODE + "/home/page1");
        assertFalse("Page 1 should now no longer have the sitemap mixin in the live workspace!",
                englishLivePage1.isNodeType("jmix:sitemap"));
    }
View Full Code Here

        JCRSessionFactory.getInstance().closeAllSessions();
    }

    @Test
    public void testNodeReorder() throws Exception {
        JCRPublicationService jcrService = ServicesRegistry.getInstance().getJCRPublicationService();

        getCleanSession();
        JCRNodeWrapper home = englishEditSession.getNode(SITECONTENT_ROOT_NODE);
       
        JCRNodeWrapper source = home.addNode("source", "jnt:page");
        source.setProperty("jcr:title", "Source");
        JCRNodeWrapper page1 = source.addNode("page1", "jnt:page");
        page1.setProperty("jcr:title", "Page1");
        JCRNodeWrapper page2 = source.addNode("page2", "jnt:page");
        page2.setProperty("jcr:title", "Page2");
        JCRNodeWrapper page3 = source.addNode("page3", "jnt:page");
        page3.setProperty("jcr:title", "Page3");
        JCRNodeWrapper page4 = source.addNode("page4", "jnt:page");
        page4.setProperty("jcr:title", "Page4");
        JCRNodeWrapper page5 = source.addNode("page5", "jnt:page");
        page5.setProperty("jcr:title", "Page5");
        JCRNodeWrapper page6 = source.addNode("page6", "jnt:page");
        page6.setProperty("jcr:title", "Page6");
        englishEditSession.save();

        jcrService.publishByMainId(home.getIdentifier());

        JCRNodeWrapper liveSource = englishLiveSession.getNodeByIdentifier(source.getIdentifier());

        List<String> pageNames = Arrays.asList("page1", "page2", "page3", "page4", "page5", "page6");
        List<String> pageFound = new ArrayList<String>();
        NodeIterator nodeIterator = liveSource.getNodes();
        int i = 0;
        while (nodeIterator.hasNext()) {
            JCRNodeWrapper nodeWrapper = (JCRNodeWrapper) nodeIterator.next();
            String s = pageNames.get(i);
            logger.info("testNodeReorder: [" + i + "] " + nodeWrapper.getName());
            assertEquals("Order of published nodes is wrong."
                    + " Node name should be: " + s, pageNames.get(i),
                    nodeWrapper.getName());
            pageFound.add(s);
            i++;
        }
        assertTrue("Number of pages should be " + pageNames.size() + " but found " + pageFound.size(),
                pageNames.size() == pageFound.size());

        englishEditSession.checkout(source);
        englishEditSession.checkout(page1);
        englishEditSession.checkout(page2);
        englishEditSession.checkout(page3);
        englishEditSession.checkout(page4);
        englishEditSession.checkout(page5);
        englishEditSession.checkout(page6);
        source.orderBefore("page4", "page2");
        source.orderBefore("page6", "page5");
        englishEditSession.save();

        jcrService.publishByMainId(home.getIdentifier());
       
        pageNames = Arrays.asList("page1", "page4", "page2", "page3", "page6", "page5");
        pageFound = new ArrayList<String>();
        i = 0;
        nodeIterator = englishLiveSession.getNodeByIdentifier(source.getIdentifier()).getNodes();
View Full Code Here

TOP

Related Classes of org.jahia.services.content.JCRPublicationService

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.