
com.liferay.journal.web.internal.display.context.JournalEditArticleDisplayContext Maven / Gradle / Ivy
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.journal.web.internal.display.context;
import com.liferay.asset.display.page.constants.AssetDisplayPageConstants;
import com.liferay.asset.display.page.item.selector.AssetDisplayPageItemSelectorCriterion;
import com.liferay.asset.display.page.model.AssetDisplayPageEntry;
import com.liferay.asset.display.page.service.AssetDisplayPageEntryLocalServiceUtil;
import com.liferay.depot.model.DepotEntryGroupRel;
import com.liferay.depot.service.DepotEntryGroupRelLocalService;
import com.liferay.depot.service.DepotEntryLocalService;
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.dynamic.data.mapping.form.renderer.constants.DDMFormRendererConstants;
import com.liferay.dynamic.data.mapping.form.values.factory.DDMFormValuesFactory;
import com.liferay.dynamic.data.mapping.item.selector.DDMTemplateItemSelectorCriterion;
import com.liferay.dynamic.data.mapping.item.selector.DDMTemplateItemSelectorReturnType;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.model.DDMTemplate;
import com.liferay.dynamic.data.mapping.service.DDMStructureLocalServiceUtil;
import com.liferay.dynamic.data.mapping.service.DDMTemplateLocalServiceUtil;
import com.liferay.dynamic.data.mapping.service.DDMTemplateServiceUtil;
import com.liferay.dynamic.data.mapping.storage.DDMFormValues;
import com.liferay.dynamic.data.mapping.util.DDMFormValuesToMapConverter;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItemList;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItemListBuilder;
import com.liferay.item.selector.ItemSelector;
import com.liferay.item.selector.ItemSelectorCriterion;
import com.liferay.item.selector.criteria.FileEntryItemSelectorReturnType;
import com.liferay.item.selector.criteria.URLItemSelectorReturnType;
import com.liferay.item.selector.criteria.UUIDItemSelectorReturnType;
import com.liferay.item.selector.criteria.image.criterion.ImageItemSelectorCriterion;
import com.liferay.journal.constants.JournalArticleConstants;
import com.liferay.journal.constants.JournalFolderConstants;
import com.liferay.journal.constants.JournalPortletKeys;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.model.JournalFolder;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.journal.service.JournalArticleServiceUtil;
import com.liferay.journal.service.JournalFolderLocalServiceUtil;
import com.liferay.journal.web.internal.configuration.JournalWebConfiguration;
import com.liferay.journal.web.internal.security.permission.resource.JournalArticlePermission;
import com.liferay.journal.web.internal.security.permission.resource.JournalFolderPermission;
import com.liferay.journal.web.internal.util.RecentGroupManagerUtil;
import com.liferay.layout.item.selector.LayoutItemSelectorCriterion;
import com.liferay.layout.page.template.model.LayoutPageTemplateEntry;
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryLocalServiceUtil;
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryServiceUtil;
import com.liferay.petra.function.transform.TransformUtil;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.bean.BeanParamUtil;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.feature.flag.FeatureFlagManagerUtil;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.GroupConstants;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.portlet.LiferayWindowState;
import com.liferay.portal.kernel.portlet.RequestBackedPortletURLFactory;
import com.liferay.portal.kernel.portlet.RequestBackedPortletURLFactoryUtil;
import com.liferay.portal.kernel.portlet.url.builder.PortletURLBuilder;
import com.liferay.portal.kernel.portlet.url.builder.ResourceURLBuilder;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.GroupServiceUtil;
import com.liferay.portal.kernel.service.LayoutLocalServiceUtil;
import com.liferay.portal.kernel.service.WorkflowDefinitionLinkLocalServiceUtil;
import com.liferay.portal.kernel.service.permission.GroupPermissionUtil;
import com.liferay.portal.kernel.theme.PortletDisplay;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.HttpComponentsUtil;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.site.item.selector.SiteItemSelectorCriterion;
import com.liferay.site.manager.RecentGroupManager;
import jakarta.portlet.MimeResponse;
import jakarta.portlet.PortletRequest;
import jakarta.portlet.RenderResponse;
import jakarta.servlet.http.HttpServletRequest;
import java.text.Format;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
/**
* @author Eudaldo Alonso
*/
public class JournalEditArticleDisplayContext {
public JournalEditArticleDisplayContext(
HttpServletRequest httpServletRequest,
LiferayPortletResponse liferayPortletResponse, JournalArticle article,
DepotEntryGroupRelLocalService depotEntryGroupRelLocalService,
DepotEntryLocalService depotEntryLocalService,
GroupLocalService groupLocalService) {
_httpServletRequest = httpServletRequest;
_liferayPortletResponse = liferayPortletResponse;
_article = article;
_depotEntryGroupRelLocalService = depotEntryGroupRelLocalService;
_depotEntryLocalService = depotEntryLocalService;
_groupLocalService = groupLocalService;
_itemSelector = (ItemSelector)httpServletRequest.getAttribute(
ItemSelector.class.getName());
_journalWebConfiguration =
(JournalWebConfiguration)httpServletRequest.getAttribute(
JournalWebConfiguration.class.getName());
_themeDisplay = (ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
setViewAttributes();
}
public String getArticleId() {
if (_article == null) {
return null;
}
return _article.getArticleId();
}
public Map getAssetDisplayPagePreviewContext() {
String selectAssetDisplayPageEventName =
_liferayPortletResponse.getNamespace() + "selectAssetDisplayPage";
String selectSiteEventName =
_liferayPortletResponse.getNamespace() + "selectSite";
return HashMapBuilder.put(
"newArticle",
(_article == null) || Validator.isNull(_article.getArticleId())
).put(
"previewURL",
() -> {
String getPagePreviewURL = HttpComponentsUtil.addParameters(
_themeDisplay.getPortalURL() + _themeDisplay.getPathMain() +
"/portal/get_page_preview",
"p_l_mode", Constants.PREVIEW, "className",
JournalArticle.class.getName());
if (_article != null) {
getPagePreviewURL = HttpComponentsUtil.addParameters(
getPagePreviewURL, "classPK",
_article.getResourcePrimKey(), "version",
_article.getVersion());
}
if (Validator.isNotNull(_themeDisplay.getDoAsUserId())) {
getPagePreviewURL = PortalUtil.addPreservedParameters(
_themeDisplay, getPagePreviewURL, false, true);
}
return getPagePreviewURL;
}
).put(
"saveAsDraftURL",
PortletURLBuilder.createActionURL(
_liferayPortletResponse
).setActionName(
"/journal/save_as_draft_article"
).buildString()
).put(
"selectAssetDisplayPageEventName", selectAssetDisplayPageEventName
).put(
"selectAssetDisplayPageURL",
() -> {
AssetDisplayPageItemSelectorCriterion
assetDisplayPageItemSelectorCriterion =
new AssetDisplayPageItemSelectorCriterion();
assetDisplayPageItemSelectorCriterion.setClassNameId(
PortalUtil.getClassNameId(JournalArticle.class));
assetDisplayPageItemSelectorCriterion.setClassTypeId(
getDDMStructureId());
assetDisplayPageItemSelectorCriterion.
setDesiredItemSelectorReturnTypes(
new UUIDItemSelectorReturnType());
return PortletURLBuilder.create(
_itemSelector.getItemSelectorURL(
RequestBackedPortletURLFactoryUtil.create(
_httpServletRequest),
selectAssetDisplayPageEventName,
assetDisplayPageItemSelectorCriterion)
).buildString();
}
).put(
"selectSiteEventName", selectSiteEventName
).put(
"siteItemSelectorURL",
() -> {
SiteItemSelectorCriterion siteItemSelectorCriterion =
new SiteItemSelectorCriterion();
siteItemSelectorCriterion.setDesiredItemSelectorReturnTypes(
new URLItemSelectorReturnType());
Group scopeGroup = _groupLocalService.getGroup(getGroupId());
if (scopeGroup.isDepot()) {
List connectedGroupIds = TransformUtil.transform(
_depotEntryGroupRelLocalService.getDepotEntryGroupRels(
_depotEntryLocalService.getDepotEntry(
scopeGroup.getClassPK())),
DepotEntryGroupRel::getGroupId);
long[] excludedGroupsIds = null;
if (ListUtil.isNotEmpty(connectedGroupIds)) {
excludedGroupsIds = TransformUtil.transformToLongArray(
_groupLocalService.getGroups(
_themeDisplay.getCompanyId(),
GroupConstants.ANY_PARENT_GROUP_ID, true,
QueryUtil.ALL_POS, QueryUtil.ALL_POS),
group -> {
if (!connectedGroupIds.contains(
group.getGroupId())) {
return group.getGroupId();
}
return null;
});
}
else {
excludedGroupsIds = TransformUtil.transformToLongArray(
_groupLocalService.getGroups(
_themeDisplay.getCompanyId(),
GroupConstants.ANY_PARENT_GROUP_ID, true,
QueryUtil.ALL_POS, QueryUtil.ALL_POS),
Group::getGroupId);
}
siteItemSelectorCriterion.setExcludedGroupIds(
excludedGroupsIds);
}
return String.valueOf(
_itemSelector.getItemSelectorURL(
RequestBackedPortletURLFactoryUtil.create(
_httpServletRequest),
selectSiteEventName, siteItemSelectorCriterion));
}
).put(
"sites",
() -> {
List groups = null;
int max = _MAX_SITES;
Group scopeGroup = _groupLocalService.getGroup(getGroupId());
if (scopeGroup.isDepot()) {
groups = _groupLocalService.getGroups(
TransformUtil.transformToLongArray(
_depotEntryGroupRelLocalService.
getDepotEntryGroupRels(
_depotEntryLocalService.getDepotEntry(
scopeGroup.getClassPK())),
DepotEntryGroupRel::getGroupId));
}
else {
RecentGroupManager recentGroupManager =
RecentGroupManagerUtil.getRecentGroupManager();
List recentGroups = ListUtil.subList(
recentGroupManager.getRecentGroups(_httpServletRequest),
0, _MAX_SITES);
JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
for (Group group : recentGroups) {
if (group.isCompany()) {
continue;
}
jsonArray.put(
JSONUtil.put(
"groupId", group.getGroupId()
).put(
"name",
group.getDescriptiveName(
_themeDisplay.getLocale())
));
}
if (recentGroups.size() == _MAX_SITES) {
return jsonArray;
}
max = _MAX_SITES - recentGroups.size();
groups = GroupServiceUtil.getGroups(
_themeDisplay.getCompanyId(),
GroupConstants.DEFAULT_PARENT_GROUP_ID, true);
}
JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
for (Group group : groups) {
if (max < 0) {
break;
}
if (group.isCompany()) {
continue;
}
max -= 1;
jsonArray.put(
JSONUtil.put(
"groupId", group.getGroupId()
).put(
"name",
group.getDescriptiveName(_themeDisplay.getLocale())
));
}
return jsonArray;
}
).put(
"sitesCount",
() -> {
if (!GroupPermissionUtil.contains(
_themeDisplay.getPermissionChecker(),
ActionKeys.VIEW)) {
return 0;
}
Group scopeGroup = _groupLocalService.getGroup(getGroupId());
if (scopeGroup.isDepot()) {
return _depotEntryGroupRelLocalService.
getDepotEntryGroupRelsCount(
_depotEntryLocalService.getDepotEntry(
scopeGroup.getClassPK()));
}
int groupsCount = GroupServiceUtil.getGroupsCount(
_themeDisplay.getCompanyId(), 0, Boolean.TRUE);
return Math.max(groupsCount - 1, 0);
}
).build();
}
public Set getAvailableLocales() {
if (_availableLocales != null) {
return _availableLocales;
}
_availableLocales = LanguageUtil.getAvailableLocales(getGroupId());
return _availableLocales;
}
public String getBackURL() {
if (_backURL != null) {
return _backURL;
}
_backURL = ParamUtil.getString(
_httpServletRequest, "backURL", getRedirect());
return _backURL;
}
public Map getChangeDefaultLanguageData() {
return HashMapBuilder.put(
"defaultLanguage", getDefaultArticleLanguageId()
).put(
"languages",
() -> {
Set uniqueLanguageIds = new LinkedHashSet<>();
uniqueLanguageIds.add(getSelectedLanguageId());
for (Locale availableLocale : getAvailableLocales()) {
uniqueLanguageIds.add(
LocaleUtil.toLanguageId(availableLocale));
}
return TransformUtil.transform(
uniqueLanguageIds,
languageId -> HashMapBuilder.put(
"icon",
StringUtil.toLowerCase(
StringUtil.replace(languageId, '_', '-'))
).put(
"label", languageId
).build());
}
).put(
"strings",
() -> {
Map strings = new HashMap<>();
Set locales = new HashSet<>(getAvailableLocales());
locales.add(
LocaleUtil.fromLanguageId(getDefaultArticleLanguageId()));
for (Locale locale : locales) {
strings.put(
LocaleUtil.toLanguageId(locale),
StringBundler.concat(
locale.getDisplayLanguage(), StringPool.SPACE,
StringPool.OPEN_PARENTHESIS, locale.getCountry(),
StringPool.CLOSE_PARENTHESIS));
}
return strings;
}
).build();
}
public long getClassNameId() {
if (_classNameId != null) {
return _classNameId;
}
_classNameId = BeanParamUtil.getLong(
_article, _httpServletRequest, "classNameId");
return _classNameId;
}
public long getClassPK() {
if (_classPK != null) {
return _classPK;
}
_classPK = BeanParamUtil.getLong(
_article, _httpServletRequest, "classPK");
return _classPK;
}
public Map getComponentContext() throws PortalException {
return HashMapBuilder.put(
"articleId", getArticleId()
).put(
"autoSaveDraftEnabled",
FeatureFlagManagerUtil.isEnabled("LPD-11228")
).put(
"autoSaveDraftURL",
ResourceURLBuilder.createResourceURL(
_liferayPortletResponse.createLiferayPortletURL(
JournalPortletKeys.JOURNAL, PortletRequest.RESOURCE_PHASE,
MimeResponse.Copy.PUBLIC)
).setResourceID(
"/journal/auto_save_article"
).buildString()
).put(
"availableLocales", _getAvailableLanguageIds()
).put(
"classNameId", String.valueOf(getClassNameId())
).put(
"contentTitle", "titleMapAsXML"
).put(
"defaultLanguageId", getDefaultArticleLanguageId()
).put(
"hasSavePermission", hasSavePermission()
).build();
}
public Map getDataEngineLayoutRendererComponentContext() {
return HashMapBuilder.put(
"currentLanguageId", getSelectedLanguageId()
).build();
}
public DDMFormValues getDDMFormValues() throws PortalException {
if (_ddmFormValues != null) {
return _ddmFormValues;
}
DDMStructure ddmStructure = getDDMStructure();
if (_isDDMFormValuesEdited() || (_article == null)) {
DDMFormValuesFactory ddmFormValuesFactory =
(DDMFormValuesFactory)_httpServletRequest.getAttribute(
DDMFormValuesFactory.class.getName());
return ddmFormValuesFactory.create(
_httpServletRequest, ddmStructure.getDDMForm());
}
DDMFormValues ddmFormValues = _article.getDDMFormValues();
if ((ddmFormValues == null) && _article.isNew() &&
(getClassNameId() ==
JournalArticleConstants.CLASS_NAME_ID_DEFAULT)) {
JournalArticle ddmStructureArticle =
JournalArticleLocalServiceUtil.getArticle(
ddmStructure.getGroupId(), DDMStructure.class.getName(),
ddmStructure.getStructureId());
ddmFormValues = ddmStructureArticle.getDDMFormValues();
}
if (ddmFormValues != null) {
_ddmFormValues = ddmFormValues;
}
return _ddmFormValues;
}
public DDMStructure getDDMStructure() {
if (_ddmStructure != null) {
return _ddmStructure;
}
long ddmStructureId = ParamUtil.getLong(
_httpServletRequest, "ddmStructureId");
if (ddmStructureId > 0) {
_ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(
ddmStructureId);
}
else if (_article != null) {
_ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(
_article.getDDMStructureId());
}
return _ddmStructure;
}
public long getDDMStructureId() {
DDMStructure ddmStructure = getDDMStructure();
return ddmStructure.getStructureId();
}
public DDMTemplate getDDMTemplate() throws PortalException {
if (_ddmTemplate != null) {
return _ddmTemplate;
}
long ddmTemplateId = ParamUtil.getLong(
_httpServletRequest, "ddmTemplateId");
if (ddmTemplateId == -1) {
return null;
}
if (ddmTemplateId > 0) {
_ddmTemplate = DDMTemplateLocalServiceUtil.fetchDDMTemplate(
ddmTemplateId);
return _ddmTemplate;
}
if (Validator.isNotNull(getDDMTemplateKey())) {
long groupId = ParamUtil.getLong(
_httpServletRequest, "groupId", _themeDisplay.getSiteGroupId());
if (_article != null) {
groupId = _article.getGroupId();
}
_ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(
groupId, PortalUtil.getClassNameId(DDMStructure.class),
getDDMTemplateKey(), true);
return _ddmTemplate;
}
if ((_article != null) || (_ddmTemplate != null)) {
return null;
}
DDMStructure ddmStructure = getDDMStructure();
List ddmTemplates = DDMTemplateServiceUtil.getTemplates(
_themeDisplay.getCompanyId(), ddmStructure.getGroupId(),
PortalUtil.getClassNameId(DDMStructure.class),
ddmStructure.getStructureId(),
PortalUtil.getClassNameId(JournalArticle.class), true,
WorkflowConstants.STATUS_APPROVED);
if (ddmTemplates.isEmpty()) {
return null;
}
_ddmTemplate = ddmTemplates.get(0);
return _ddmTemplate;
}
public String getDDMTemplateKey() {
if (_ddmTemplateKey != null) {
return _ddmTemplateKey;
}
String ddmTemplateKey = ParamUtil.getString(
_httpServletRequest, "ddmTemplateKey");
if (Validator.isNull(ddmTemplateKey) && (_article != null) &&
Objects.equals(_article.getDDMStructureId(), getDDMStructureId())) {
ddmTemplateKey = _article.getDDMTemplateKey();
}
_ddmTemplateKey = ddmTemplateKey;
return _ddmTemplateKey;
}
public String getDefaultArticleLanguageId() {
if (_defaultArticleLanguageId != null) {
return _defaultArticleLanguageId;
}
String defaultArticleLanguageId = ParamUtil.getString(
_httpServletRequest, "defaultLanguageId");
if (Validator.isNotNull(getArticleId())) {
DDMFormValues ddmFormValues = _article.getDDMFormValues();
defaultArticleLanguageId = LocaleUtil.toLanguageId(
ddmFormValues.getDefaultLocale());
}
else if (Validator.isNull(defaultArticleLanguageId) &&
(getClassNameId() ==
JournalArticleConstants.CLASS_NAME_ID_DEFAULT)) {
defaultArticleLanguageId = _getDDMStructureDefaultLanguageId();
}
if ((defaultArticleLanguageId == null) ||
!LanguageUtil.isAvailableLocale(
getGroupId(), defaultArticleLanguageId)) {
Locale siteDefaultLocale = null;
try {
siteDefaultLocale = PortalUtil.getSiteDefaultLocale(
getGroupId());
}
catch (PortalException portalException) {
_log.error(portalException);
siteDefaultLocale = LocaleUtil.getSiteDefault();
}
defaultArticleLanguageId = LocaleUtil.toLanguageId(
siteDefaultLocale);
}
_defaultArticleLanguageId = defaultArticleLanguageId;
return _defaultArticleLanguageId;
}
public Map getFieldMap() throws PortalException {
return HashMapBuilder.put(
"descriptionMapAsXML",
() -> {
if (_article != null) {
return _article.getDescriptionMap();
}
return Collections.emptyMap();
}
).put(
"friendlyURL",
() -> {
if (_article != null) {
return _article.getFriendlyURLMap();
}
return Collections.emptyMap();
}
).put(
"titleMapAsXML",
() -> {
if (_article != null) {
return _article.getTitleMap();
}
return Collections.emptyMap();
}
).build();
}
public long getFolderId() {
if (_folderId != null) {
return _folderId;
}
_folderId = BeanParamUtil.getLong(
_article, _httpServletRequest, "folderId",
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);
return _folderId;
}
public String getFolderName() {
if (_folderName != null) {
return _folderName;
}
if (JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID != getFolderId()) {
JournalFolder folder =
JournalFolderLocalServiceUtil.fetchJournalFolder(getFolderId());
if (folder != null) {
_folderName = folder.getName();
return _folderName;
}
}
_folderName = LanguageUtil.get(_httpServletRequest, "home");
return _folderName;
}
public String getFriendlyURLBase() {
StringBundler sb = new StringBundler(4);
sb.append(_themeDisplay.getPortalURL());
Group group = _themeDisplay.getScopeGroup();
boolean privateLayout = false;
if (_article != null) {
Layout layout = _article.getLayout();
if (layout != null) {
privateLayout = layout.isPrivateLayout();
}
}
if (privateLayout) {
sb.append(PortalUtil.getPathFriendlyURLPrivateGroup());
}
else {
sb.append(PortalUtil.getPathFriendlyURLPublic());
}
sb.append(group.getFriendlyURL());
sb.append(JournalArticleConstants.CANONICAL_URL_SEPARATOR);
return sb.toString();
}
public String getFriendlyURLDuplicatedWarningMessage()
throws PortalException {
if (_friendlyURLDuplicatedWarningMessage != null) {
return _friendlyURLDuplicatedWarningMessage;
}
if (_article == null) {
_friendlyURLDuplicatedWarningMessage = StringPool.BLANK;
return _friendlyURLDuplicatedWarningMessage;
}
List excludedGroupIds = new ArrayList<>();
Group group = _themeDisplay.getScopeGroup();
excludedGroupIds.add(group.getGroupId());
if (group.isStagingGroup()) {
excludedGroupIds.add(group.getLiveGroupId());
}
else if (group.hasStagingGroup()) {
Group stagingGroup = group.getStagingGroup();
excludedGroupIds.add(stagingGroup.getGroupId());
}
List friendlyURLDuplicatedLocales = new ArrayList<>();
Map> friendlyURLGroupIdsMap = new HashMap<>();
Map friendlyURLMap = _article.getFriendlyURLMap();
for (Map.Entry entry : friendlyURLMap.entrySet()) {
if (Validator.isNull(entry.getValue())) {
continue;
}
List groupIds = friendlyURLGroupIdsMap.computeIfAbsent(
entry.getValue(),
key -> ListUtil.remove(
JournalArticleLocalServiceUtil.getGroupIdsByUrlTitle(
_themeDisplay.getCompanyId(), key),
excludedGroupIds));
if (!groupIds.isEmpty() &&
((groupIds.size() > 1) ||
!Objects.equals(
groupIds.get(0), _themeDisplay.getScopeGroupId()))) {
friendlyURLDuplicatedLocales.add(entry.getKey());
}
}
if (friendlyURLDuplicatedLocales.isEmpty()) {
_friendlyURLDuplicatedWarningMessage = StringPool.BLANK;
return _friendlyURLDuplicatedWarningMessage;
}
Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(group);
if ((friendlyURLDuplicatedLocales.size() > 1) &&
friendlyURLDuplicatedLocales.remove(siteDefaultLocale)) {
friendlyURLDuplicatedLocales.add(0, siteDefaultLocale);
}
String friendlyURLDuplicatedWarningMessage = null;
if (friendlyURLDuplicatedLocales.size() > 3) {
friendlyURLDuplicatedWarningMessage = LanguageUtil.format(
_themeDisplay.getLocale(),
"the-url-used-in-x-and-x-more-translations-already-exists-in-" +
"other-sites-or-asset-libraries",
new String[] {
_getLocaleDisplayNames(
_themeDisplay.getLocale(),
friendlyURLDuplicatedLocales.get(0),
friendlyURLDuplicatedLocales.get(1),
friendlyURLDuplicatedLocales.get(2)),
String.valueOf(friendlyURLDuplicatedLocales.size() - 3)
},
false);
}
else if (friendlyURLDuplicatedLocales.size() > 1) {
int lastElementIndex = friendlyURLDuplicatedLocales.size() - 1;
List locales = ListUtil.subList(
friendlyURLDuplicatedLocales, 0, lastElementIndex);
friendlyURLDuplicatedWarningMessage = LanguageUtil.format(
_themeDisplay.getLocale(),
"the-url-used-in-x-and-x-already-exists-in-other-sites-or-" +
"asset-libraries",
new String[] {
_getLocaleDisplayNames(
_themeDisplay.getLocale(),
locales.toArray(new Locale[0])),
_getLocaleDisplayNames(
_themeDisplay.getLocale(),
friendlyURLDuplicatedLocales.get(lastElementIndex))
},
false);
}
else {
friendlyURLDuplicatedWarningMessage = LanguageUtil.format(
_themeDisplay.getLocale(),
"the-url-used-in-x-already-exists-in-other-sites-or-asset-" +
"libraries",
new String[] {
_getLocaleDisplayNames(
_themeDisplay.getLocale(),
friendlyURLDuplicatedLocales.get(0))
},
false);
}
_friendlyURLDuplicatedWarningMessage =
friendlyURLDuplicatedWarningMessage;
return _friendlyURLDuplicatedWarningMessage;
}
public long getGroupId() {
if (_groupId != null) {
return _groupId;
}
_groupId = BeanParamUtil.getLong(
_article, _httpServletRequest, "groupId",
_themeDisplay.getScopeGroupId());
return _groupId;
}
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy