Package org.jahia.services.content

Examples of org.jahia.services.content.JCRSessionWrapper


    }

    @Test
    public void testDescendantNodeXPathQueries() throws Exception {

        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(
                Constants.EDIT_WORKSPACE,
                LanguageCodeConverters.languageCodeToLocale(DEFAULT_LANGUAGE));

        QueryResultWrapper res;
View Full Code Here


    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

        paramBean.getSession(true).setAttribute(ParamBean.SESSION_SITE, site);

        JahiaData jData = new JahiaData(paramBean, false);
        paramBean.setAttribute(JahiaData.JAHIA_DATA, jData);

        JCRSessionWrapper session = JCRSessionFactory.getInstance()
                .getCurrentUserSession(null, Locale.ENGLISH);
        JCRNodeWrapper siteNode = session.getNode(SITECONTENT_ROOT_NODE);

        if (!siteNode.isCheckedOut()) {
            session.checkout(siteNode);
        }

        if (siteNode.hasNode("testPage")) {
            siteNode.getNode("testPage").remove();
        }
        JCRNodeWrapper pageNode = siteNode.addNode("testPage", Constants.JAHIANT_PAGE);
        pageNode.setProperty("jcr:title", "English test page");
        pageNode.addNode("testContent", "jnt:mainContent");

        session.save();
       
        JCRSessionWrapper frenchSession = JCRSessionFactory.getInstance().getCurrentUserSession(
                null, Locale.FRENCH);
        pageNode = frenchSession.getNode(SITECONTENT_ROOT_NODE + "/testPage");
        pageNode.setProperty("jcr:title", "French test page");
        frenchSession.save();
    }
View Full Code Here

    }

    @Test
    public void testAssigningUrlMappings() throws Exception {
        JCRSessionWrapper session = JCRSessionFactory.getInstance()
                .getCurrentUserSession(null, Locale.ENGLISH);
        JCRNodeWrapper pageNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage");
        JCRNodeWrapper contentNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage/testContent");

        VanityUrl vanityUrl = new VanityUrl("/testpage", TESTSITE_NAME, "en");
        vanityUrl.setDefaultMapping(true);
        vanityUrl.setActive(true);
        assertTrue("URL mapping should not exist yet", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        getVanityUrlService().saveVanityUrlMapping(pageNode, vanityUrl);
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        try {
            getVanityUrlService().saveVanityUrlMapping(contentNode, vanityUrl);
            assertTrue("Exception should have been thrown", false);
        } catch (ConstraintViolationException ex) {
            // expected
        }

        VanityUrl newVanityUrl = new VanityUrl("/testcontent", TESTSITE_NAME,
                "en");
        newVanityUrl.setDefaultMapping(true);
        newVanityUrl.setActive(true);
        getVanityUrlService().saveVanityUrlMapping(contentNode, newVanityUrl);
        assertFalse("New URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());

        VanityUrl savedVanityUrl = getVanityUrlService()
                .getVanityUrlForWorkspaceAndLocale(pageNode,
                        session.getWorkspace().getName(), session.getLocale());
        assertTrue("Wrong page vanity URL returned", vanityUrl.getUrl().equals(
                savedVanityUrl.getUrl()));

        VanityUrl savedNewVanityUrl = getVanityUrlService()
                .getVanityUrlsForCurrentLocale(contentNode, session).get(0);
        assertTrue("Wrong container vanity URL returned", newVanityUrl.getUrl()
                .equals(savedNewVanityUrl.getUrl()));

        getVanityUrlService().removeVanityUrlMapping(pageNode, vanityUrl);
        getVanityUrlService().removeVanityUrlMapping(contentNode, newVanityUrl);
        assertTrue("URL mapping should no longer exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        assertNull("No page vanity URL should exist", getVanityUrlService()
                .getVanityUrlForWorkspaceAndLocale(pageNode,
                        session.getWorkspace().getName(), session.getLocale()));
        assertTrue("No container vanity URL should exist",
                getVanityUrlService().getVanityUrlsForCurrentLocale(
                        contentNode, session).isEmpty());
    }
View Full Code Here

                        contentNode, session).isEmpty());
    }

    @Test
    public void testBulkDiffAssigningUrlMappings() throws Exception {
        JCRSessionWrapper session = JCRSessionFactory.getInstance()
                .getCurrentUserSession(null, Locale.ENGLISH);
        JCRNodeWrapper pageNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage");

        VanityUrl englishVanityUrl = new VanityUrl("/testpage", TESTSITE_NAME,
                "en");
        englishVanityUrl.setActive(true);
        VanityUrl englishVanityUrl2 = new VanityUrl("/testpage2",
                TESTSITE_NAME, "en");
        englishVanityUrl2.setActive(false);
        VanityUrl englishVanityUrl3 = new VanityUrl("/testpage/page3",
                TESTSITE_NAME, "en");
        englishVanityUrl3.setActive(true);

        VanityUrl frenchVanityUrl = new VanityUrl("/testpage/french",
                TESTSITE_NAME, "fr");
        frenchVanityUrl.setActive(true);
        VanityUrl frenchVanityUrl2 = new VanityUrl("/testpage/french2",
                TESTSITE_NAME, "fr");
        frenchVanityUrl2.setDefaultMapping(true);
        frenchVanityUrl2.setActive(true);

        List<VanityUrl> vanityUrls = new ArrayList<VanityUrl>();
        vanityUrls.add(englishVanityUrl);
        vanityUrls.add(englishVanityUrl2);
        vanityUrls.add(englishVanityUrl3);
        vanityUrls.add(frenchVanityUrl);
        vanityUrls.add(frenchVanityUrl2);
        Set<String> languages = new HashSet<String>();
        languages.add("en");
        languages.add("fr");

        getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
                languages);

        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(englishVanityUrl.getUrl(),
                        englishVanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(englishVanityUrl2.getUrl(),
                        englishVanityUrl2.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(englishVanityUrl3.getUrl(),
                        englishVanityUrl3.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(frenchVanityUrl.getUrl(),
                        frenchVanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(frenchVanityUrl2.getUrl(),
                        frenchVanityUrl2.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());

        englishVanityUrl.setDefaultMapping(true);
        englishVanityUrl2.setDefaultMapping(true);

        try {
            getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
                    languages);
            assertTrue("Exception should have been thrown", false);
        } catch (ConstraintViolationException ex) {
            // expected as two default mappings on same language - nothing should be saved
        }

        VanityUrl frenchVanityUrl3 = new VanityUrl("/testpage", TESTSITE_NAME,
                "fr");
        frenchVanityUrl3.setDefaultMapping(true);
        frenchVanityUrl3.setActive(true);

        try {
            getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
                    languages);
            assertTrue("Exception should have been thrown", false);
        } catch (ConstraintViolationException ex) {
            // expected as same mapping is used in English - nothing should be saved
        }

        List<VanityUrl> vanityUrls_en = getVanityUrlService()
                .getVanityUrlsForCurrentLocale(pageNode, session);

        String[] expectedUrls_en = new String[] { "/testpage", "/testpage2",
                "/testpage/page3" };
        assertTrue("Number of Urls is not expected " + expectedUrls_en.length
                + " vs. " + vanityUrls_en.size(),
                expectedUrls_en.length == vanityUrls_en.size());
        for (VanityUrl vanityUrl_en : vanityUrls_en) {
            boolean found = false;
            for (String expectedUrl_en : expectedUrls_en) {
                if (vanityUrl_en.getUrl().equals(expectedUrl_en)) {
                    found = true;
                    break;
                }
            }
            assertTrue("Expected vanity url not found: " + vanityUrl_en, found);
        }

        JCRSessionWrapper frenchSession = JCRSessionFactory.getInstance()
                .getCurrentUserSession(null, Locale.FRENCH);

        List<VanityUrl> vanityUrls_fr = getVanityUrlService()
                .getVanityUrlsForCurrentLocale(pageNode, frenchSession);
View Full Code Here

        }
    }

    @Test
    public void testVanityURLResolving() throws Exception {
        JCRSessionWrapper session = JCRSessionFactory.getInstance()
                .getCurrentUserSession(null, Locale.ENGLISH);
       
        JahiaSite site = ServicesRegistry.getInstance().getJahiaSitesService().getSiteByKey(TESTSITE_NAME);
       
        JCRNodeWrapper pageNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage");

        VanityUrl englishVanityUrl = new VanityUrl("/testpage", TESTSITE_NAME,
                "en");
        englishVanityUrl.setActive(true);
View Full Code Here

        JahiaUserManagerService userManagerService = ServicesRegistry.getInstance().getJahiaUserManagerService();
        JahiaGroupManagerService groupManagerService = ServicesRegistry.getInstance().getJahiaGroupManagerService();
        groupManagerService.deleteGroup(groupManagerService.lookupGroup(site.getID(), "taskUsersGroup"));
        userManagerService.deleteUser(userManagerService.lookupUser("johndoe"));
        userManagerService.deleteUser(userManagerService.lookupUser("johnsmoe"));
        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession();
        session.save();
        JCRSessionFactory.getInstance().closeAllSessions();
    }
View Full Code Here

        JCRSessionFactory.getInstance().closeAllSessions();
    }
   
    @Before
    public void setUp() throws Exception {
        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE, Locale.ENGLISH);
        JCRNodeWrapper root = session.getNode(SITECONTENT_ROOT_NODE);
        session.checkout(root);
        stageNode = root.addNode("child-" + ++nodeCounter, "jnt:text");
        session.save();
        emptyMap = new HashMap<String, Object>();
    }
View Full Code Here

        emptyMap = new HashMap<String, Object>();
    }

    private void getCleanStageNode() throws Exception {
        JCRSessionFactory.getInstance().closeAllSessions();
        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE, Locale.ENGLISH);
        stageNode = session.getNode(SITECONTENT_ROOT_NODE+"/child-" + nodeCounter);
    }
View Full Code Here

    @BeforeClass
    public static void oneTimeSetUp() throws Exception {
        JahiaSite site = TestHelper.createSite(TESTSITE_NAME);
        assertNotNull(site);

        JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(Constants.EDIT_WORKSPACE,
                LanguageCodeConverters.languageCodeToLocale(DEFAULT_LANGUAGE));

        initContent(session);
    }
View Full Code Here

TOP

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

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.