Search in sources :

Example 1 with JahiaSite

use of org.jahia.services.sites.JahiaSite in project jahia by Jahia.

the class NodesChoiceListInitializerImpl method getChoiceListValues.

public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param, List<ChoiceListValue> values, Locale locale, Map<String, Object> context) {
    final ArrayList<ChoiceListValue> listValues = new ArrayList<ChoiceListValue>();
    if (CollectionUtils.isNotEmpty(values))
        listValues.addAll(values);
    if (param != null) {
        for (String subParam : Patterns.PIPE.split(param)) {
            String[] s = Patterns.SEMICOLON.split(subParam);
            String nodetype = null;
            if (s.length > 1) {
                nodetype = s[1];
            }
            try {
                JCRSiteNode site;
                JCRNodeWrapper resolvedNode = (JCRNodeWrapper) context.get("contextParent");
                JCRNodeWrapper ctxNode = (JCRNodeWrapper) context.get("contextNode");
                if (resolvedNode == null) {
                    resolvedNode = ctxNode;
                }
                // Always try to resolve site based on passed context node if it is available
                if (ctxNode != null) {
                    site = ctxNode.getResolveSite();
                } else if (resolvedNode != null) {
                    site = resolvedNode.getResolveSite();
                } else {
                    final JahiaSite defaultSite = JahiaSitesService.getInstance().getDefaultSite();
                    if (defaultSite != null) {
                        site = (JCRSiteNode) sessionFactory.getCurrentUserSession().getNode("/sites/" + defaultSite.getSiteKey());
                    } else {
                        site = (JCRSiteNode) sessionFactory.getCurrentUserSession().getNode(JCRContentUtils.getSystemSitePath());
                    }
                    resolvedNode = site;
                }
                String path = s[0];
                String returnType = "";
                if (s.length > 2) {
                    returnType = s[2];
                }
                path = StringUtils.replace(path, "$currentSiteTemplatesSet", "/modules/" + site.getTemplatePackage().getIdWithVersion());
                if (StringUtils.contains(path, "$currentSite/templates/")) {
                    path = StringUtils.replace(path, "$currentSite", "/modules/" + site.getTemplatePackage().getIdWithVersion());
                } else {
                    path = StringUtils.replace(path, "$currentSite", site.getPath());
                }
                boolean subTree = false;
                if (path.endsWith("//*")) {
                    path = StringUtils.substringBeforeLast(path, "//*");
                    subTree = true;
                }
                JCRSessionWrapper jcrSessionWrapper = resolvedNode.getSession();
                JCRNodeWrapper node;
                if (path.equals(".")) {
                    node = resolvedNode;
                } else if (path.startsWith("./")) {
                    node = resolvedNode.getNode(path.substring(2));
                } else {
                    node = jcrSessionWrapper.getNode(path);
                }
                addSubnodes(listValues, nodetype, node, subTree, returnType, jcrSessionWrapper);
            } catch (PathNotFoundException e) {
                logger.debug("Cannot find node " + e.getMessage(), e);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    return listValues;
}
Also used : JCRNodeWrapper(org.jahia.services.content.JCRNodeWrapper) JCRSiteNode(org.jahia.services.content.decorator.JCRSiteNode) JCRSessionWrapper(org.jahia.services.content.JCRSessionWrapper) ArrayList(java.util.ArrayList) PathNotFoundException(javax.jcr.PathNotFoundException) JahiaSite(org.jahia.services.sites.JahiaSite) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException)

Example 2 with JahiaSite

use of org.jahia.services.sites.JahiaSite in project jahia by Jahia.

the class ServerNameToSiteMapper method analyzeLink.

public void analyzeLink(HttpServletRequest request, String ctx, String language, String siteKey, String path) {
    String currentSiteKey = getSiteKeyByServerName(request);
    boolean matches = currentSiteKey.equals(siteKey);
    request.setAttribute(ATTR_NAME_SITE_KEY_MATCHES, Boolean.valueOf(matches));
    try {
        boolean languageMatches = JahiaSitesService.getInstance().getSiteDefaultLanguage(siteKey).equals(language);
        request.setAttribute(ATTR_NAME_DEFAULT_LANG_MATCHES, languageMatches);
        request.setAttribute(ATTR_NAME_LANG_TOKEN, languageMatches ? "" : "/" + language);
    } catch (JahiaException e) {
        logger.error("Error resolving language " + language + " for siteKey '" + siteKey + "'", e);
    }
    if (!matches && currentSiteKey.length() > 0 && SettingsBean.getInstance().isUrlRewriteUseAbsoluteUrls()) {
        JahiaSite siteByKey = null;
        try {
            siteByKey = JahiaSitesService.getInstance().getSiteByKey(siteKey);
        } catch (JahiaException e) {
            logger.error("Error resolving site for site key " + siteKey, e);
        }
        String serverName = siteByKey != null && !Url.isLocalhost(siteByKey.getServerName()) ? siteByKey.getServerName() : null;
        if (StringUtils.isNotEmpty(serverName)) {
            int port = SettingsBean.getInstance().getSiteURLPortOverride();
            if (port == 0) {
                port = request.getServerPort();
            }
            if (!(port == 80 && "http".equals(request.getScheme()) || port == 443 && "https".equals(request.getScheme()))) {
                serverName = new StringBuilder().append(serverName).append(":").append(port).toString();
            }
        }
        request.setAttribute(ATTR_NAME_SITE_KEY_FOR_LINK, serverName);
        request.setAttribute(ATTR_NAME_SERVERNAME_FOR_LINK, serverName != null ? (request.getScheme() + "://" + serverName) : null);
    }
    checkCmsPrefix(request, ctx, path);
    if (logger.isDebugEnabled()) {
        logger.debug("analyzeLink({}, {}, {}, {}) | currentSiteKey={} targetSiteKey={} matches={}", new Object[] { ctx, language, siteKey, path, currentSiteKey, siteKey, matches });
    }
}
Also used : JahiaException(org.jahia.exceptions.JahiaException) JahiaSite(org.jahia.services.sites.JahiaSite)

Example 3 with JahiaSite

use of org.jahia.services.sites.JahiaSite in project jahia by Jahia.

the class WipIT method testWIPAutoPublish.

@Test
public void testWIPAutoPublish() throws Exception {
    Set<String> languages = Stream.of("en", "fr", "de").collect(Collectors.toSet());
    String siteName = "multipleLanguageSite";
    String testContentName = "i18nContent";
    JahiaSite site = TestHelper.createSite(siteName, languages, languages, false);
    String testContentPath = site.getJCRLocalPath() + "/" + testContentName;
    Map<String, Map<String, JCRSessionWrapper>> sessions = getCleanSessionForLanguages("en", "fr");
    JCRSessionWrapper enEditSession = sessions.get("en").get(Constants.EDIT_WORKSPACE);
    JCRSessionWrapper enLiveSession = sessions.get("en").get(Constants.LIVE_WORKSPACE);
    JCRSessionWrapper frEditSession = sessions.get("fr").get(Constants.EDIT_WORKSPACE);
    JCRSessionWrapper frLiveSession = sessions.get("fr").get(Constants.LIVE_WORKSPACE);
    // add autopublish mixin
    JCRNodeWrapper i18nContent = enEditSession.getNode(site.getJCRLocalPath()).addNode(testContentName, "jnt:text");
    i18nContent.addMixin("jmix:autoPublish");
    // used to have at least one non i18n prop: j:titleKey
    i18nContent.addMixin("jmix:rbTitle");
    enEditSession.save();
    // test auto publish is working
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, null, "titleKey", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, null, "en", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, null, "fr", true, true);
    // set WIP for all content, alongs with props modification, content should not be published
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    final WIPInfo wipInfo = buildWipProperties(Constants.WORKINPROGRESS_STATUS_ALLCONTENT, Collections.emptySet());
    wipService.saveWipPropertiesIfNeeded(i18nContent, wipInfo);
    Assert.assertTrue(isSameWipInfo(i18nContent, wipInfo));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey", "titleKey updated", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en", "en updated", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr", "fr updated", true, false);
    // set WIP only for EN, check that FR and non 18n props are updated directly
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    final WIPInfo WipInfoEn = buildWipProperties(Constants.WORKINPROGRESS_STATUS_LANG, Collections.singleton("en"));
    wipService.saveWipPropertiesIfNeeded(i18nContent, WipInfoEn);
    Assert.assertTrue(isSameWipInfo(i18nContent, WipInfoEn));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey", "titleKey updated", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en", "en updated", false, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr", "fr updated", false, true);
    // test that auto publish is now only working for FR and non i18n props
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated", "titleKey updated 2", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en", "en updated 2", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated", "fr updated 2", true, true);
    // now disable WIP completely, en should be published directly
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    final WIPInfo wipInfoDisabled = buildWipProperties(Constants.WORKINPROGRESS_STATUS_DISABLED, Collections.emptySet());
    wipService.saveWipPropertiesIfNeeded(i18nContent, wipInfoDisabled);
    Assert.assertTrue(isSameWipInfo(i18nContent, wipInfoDisabled));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated", "titleKey updated 2", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en", "en updated 2", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated", "fr updated 2", false, true);
    // test that now auto publish is back for the complete node for all languages and non i18n props
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 2", "titleKey updated 3", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 2", "en updated 3", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 2", "fr updated 3", true, true);
    // test that adding WIP on languages directly is working
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    final WIPInfo wipInfoFr = buildWipProperties(Constants.WORKINPROGRESS_STATUS_LANG, Collections.singleton("fr"));
    wipService.saveWipPropertiesIfNeeded(i18nContent, wipInfoFr);
    Assert.assertTrue(isSameWipInfo(i18nContent, wipInfoFr));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 3", "titleKey updated 4", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 3", "en updated 4", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 3", "fr updated 4", true, false);
    // test to switch WIP to EN only from WIP FR
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    wipService.saveWipPropertiesIfNeeded(i18nContent, WipInfoEn);
    Assert.assertTrue(isSameWipInfo(i18nContent, WipInfoEn));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 3", "titleKey updated 4", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 3", "en updated 4", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 3", "fr updated 4", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 4", "titleKey updated 5", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 4", "en updated 5", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 4", "fr updated 5", true, true);
    // test swich to WIP to all content
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    wipService.saveWipPropertiesIfNeeded(i18nContent, wipInfo);
    Assert.assertTrue(isSameWipInfo(i18nContent, wipInfo));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 5", "titleKey updated 6", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 4", "en updated 6", true, false);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 5", "fr updated 6", true, false);
    // finally disable WIP and test autopublished
    enEditSession.refresh(false);
    i18nContent = enEditSession.getNode(testContentPath);
    wipService.saveWipPropertiesIfNeeded(i18nContent, wipInfoDisabled);
    Assert.assertTrue(isSameWipInfo(i18nContent, wipInfoDisabled));
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 5", "titleKey updated 6", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 4", "en updated 6", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 5", "fr updated 6", false, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "j:titleKey", enEditSession, enLiveSession, "titleKey updated 6", "titleKey updated 7", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", enEditSession, enLiveSession, "en updated 6", "en updated 7", true, true);
    setPropertyAndAssertItsAutoPublished(testContentPath, "text", frEditSession, frLiveSession, "fr updated 6", "fr updated 7", true, true);
}
Also used : WIPInfo(org.jahia.services.wip.WIPInfo) JahiaSite(org.jahia.services.sites.JahiaSite) Test(org.junit.Test) AbstractJUnitTest(org.jahia.test.framework.AbstractJUnitTest)

Example 4 with JahiaSite

use of org.jahia.services.sites.JahiaSite in project jahia by Jahia.

the class WipIT method testWIPChildrenAreNotPublishable.

@Test
public void testWIPChildrenAreNotPublishable() throws Exception {
    Map<String, Map<String, JCRSessionWrapper>> sessions = getCleanSessionForLanguages("en");
    JCRSessionWrapper englishEditSession = sessions.get("en").get(Constants.EDIT_WORKSPACE);
    Set<String> siteLanguages = Stream.of("en", "fr", "de").collect(Collectors.toSet());
    JahiaSite site = TestHelper.createSite("exampleSite", siteLanguages, siteLanguages, false);
    JCRNodeWrapper page = englishEditSession.getNode(site.getJCRLocalPath()).addNode("testPage", "jnt:page");
    page.setProperty("j:templateName", "home");
    page.setProperty(Constants.JCR_TITLE, "testPage");
    englishEditSession.getNode(site.getJCRLocalPath() + "/testPage").addNode("child1", "jnt:text");
    englishEditSession.getNode(site.getJCRLocalPath() + "/testPage").addNode("child2", "jnt:text");
    englishEditSession.save();
    JCRNodeWrapper siteNode = englishEditSession.getNode(site.getJCRLocalPath());
    Collection<ComplexPublicationService.FullPublicationInfo> infos = complexPublicationService.getFullPublicationInfos(Collections.singletonList(siteNode.getIdentifier()), Collections.singletonList("en"), true, englishEditSession);
    assertEquals(6, infos.size());
    assertTrue(infos.stream().anyMatch(e -> e.getNodePath().endsWith("/testPage/child1")));
    assertTrue(infos.stream().anyMatch(e -> e.getNodePath().endsWith("/testPage/child2")));
    wipService.createWipPropertiesOnNewNode(page, new WIPInfo(Constants.WORKINPROGRESS_STATUS_ALLCONTENT, siteLanguages));
    englishEditSession.save();
    Collection<ComplexPublicationService.FullPublicationInfo> infosAfterWIPStatusSet = complexPublicationService.getFullPublicationInfos(Collections.singletonList(siteNode.getIdentifier()), Collections.singletonList("en"), true, englishEditSession);
    // Make sure child nodes of WIP node are not getting published
    assertEquals(4, infosAfterWIPStatusSet.size());
    assertFalse(infosAfterWIPStatusSet.stream().anyMatch(e -> e.getNodePath().endsWith("/testPage/child1")));
    assertFalse(infosAfterWIPStatusSet.stream().anyMatch(e -> e.getNodePath().endsWith("/testPage/child2")));
    // check that child node is publishable, if checked separately
    Collection<ComplexPublicationService.FullPublicationInfo> childNodeInfos = complexPublicationService.getFullPublicationInfos(Collections.singletonList(englishEditSession.getNode("/sites/exampleSite/testPage/child1").getIdentifier()), Collections.singletonList("en"), true, englishEditSession);
    assertEquals(1, childNodeInfos.size());
    TestHelper.deleteSite("exampleSite");
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) JahiaSite(org.jahia.services.sites.JahiaSite) java.util(java.util) Logger(org.slf4j.Logger) ServicesRegistry(org.jahia.registries.ServicesRegistry) org.jahia.services.content(org.jahia.services.content) WIPInfo(org.jahia.services.wip.WIPInfo) Test(org.junit.Test) WIPService(org.jahia.services.wip.WIPService) Collectors(java.util.stream.Collectors) TestHelper(org.jahia.test.utils.TestHelper) Stream(java.util.stream.Stream) Constants(org.jahia.api.Constants) AbstractJUnitTest(org.jahia.test.framework.AbstractJUnitTest) RepositoryException(javax.jcr.RepositoryException) After(org.junit.After) SpringContextSingleton(org.jahia.services.SpringContextSingleton) Assert(org.junit.Assert) LocaleUtils(org.apache.commons.lang.LocaleUtils) WIPInfo(org.jahia.services.wip.WIPInfo) JahiaSite(org.jahia.services.sites.JahiaSite) Test(org.junit.Test) AbstractJUnitTest(org.jahia.test.framework.AbstractJUnitTest)

Example 5 with JahiaSite

use of org.jahia.services.sites.JahiaSite in project jahia by Jahia.

the class WipIT method testWipSiteWithMultipleLanguage.

private void testWipSiteWithMultipleLanguage(Set<String> siteLanguages, String siteName) throws Exception {
    JahiaSite site = TestHelper.createSite(siteName, siteLanguages, siteLanguages, false);
    // Given contents in languages
    List<String> contentNodes = createContentNodes(site.getJCRLocalPath(), siteLanguages);
    for (String contentNodePath : contentNodes) {
        checkWipStatusOnNode(contentNodePath, siteLanguages);
    }
    // clean up
    TestHelper.deleteSite(siteName);
}
Also used : JahiaSite(org.jahia.services.sites.JahiaSite)

Aggregations

JahiaSite (org.jahia.services.sites.JahiaSite)63 JCRSessionWrapper (org.jahia.services.content.JCRSessionWrapper)32 RepositoryException (javax.jcr.RepositoryException)18 BeforeClass (org.junit.BeforeClass)15 JCRNodeWrapper (org.jahia.services.content.JCRNodeWrapper)14 JahiaSitesService (org.jahia.services.sites.JahiaSitesService)13 JCRSiteNode (org.jahia.services.content.decorator.JCRSiteNode)9 Properties (java.util.Properties)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 JahiaException (org.jahia.exceptions.JahiaException)5 JahiaGroupManagerService (org.jahia.services.usermanager.JahiaGroupManagerService)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 JCRPublicationService (org.jahia.services.content.JCRPublicationService)4 JCRGroupNode (org.jahia.services.content.decorator.JCRGroupNode)4 JCRUserNode (org.jahia.services.content.decorator.JCRUserNode)4 JahiaUserManagerService (org.jahia.services.usermanager.JahiaUserManagerService)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3