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;
}
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 });
}
}
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);
}
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");
}
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);
}
Aggregations