Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-157971 Use non ambiguous friendly urls for cross-group references #3256

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,6 +21,7 @@
import com.liferay.friendly.url.util.comparator.FriendlyURLEntryLocalizationComparator;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.util.GroupThreadLocal;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.Portal;

Expand All @@ -41,16 +42,24 @@ public class FileEntryInfoItemFriendlyURLProvider

@Override
public String getFriendlyURL(FileEntry fileEntry, String languageId) {
FriendlyURLEntry friendlyURLEntry =
FriendlyURLEntry mainFriendlyURLEntry =
_friendlyURLEntryLocalService.fetchMainFriendlyURLEntry(
_portal.getClassNameId(FileEntry.class),
fileEntry.getFileEntryId());

if (friendlyURLEntry != null) {
return friendlyURLEntry.getUrlTitle();
if (mainFriendlyURLEntry == null) {
return String.valueOf(fileEntry.getFileEntryId());
}

return null;
Long groupId = GroupThreadLocal.getGroupId();

if ((groupId != null) &&
(groupId != mainFriendlyURLEntry.getGroupId())) {

return String.valueOf(fileEntry.getFileEntryId());
}

return mainFriendlyURLEntry.getUrlTitle();
}

@Override
Expand Down
Expand Up @@ -20,11 +20,11 @@
import com.liferay.asset.kernel.model.AssetRendererFactory;
import com.liferay.document.library.kernel.model.DLFileEntry;
import com.liferay.document.library.kernel.model.DLFileEntryConstants;
import com.liferay.friendly.url.model.FriendlyURLEntry;
import com.liferay.friendly.url.service.FriendlyURLEntryLocalService;
import com.liferay.friendly.url.info.item.provider.InfoItemFriendlyURLProvider;
import com.liferay.layout.display.page.LayoutDisplayPageObjectProvider;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
Expand All @@ -40,10 +40,12 @@ public class FileEntryLayoutDisplayPageObjectProvider

public FileEntryLayoutDisplayPageObjectProvider(
FileEntry fileEntry,
FriendlyURLEntryLocalService friendlyURLEntryLocalService) {
InfoItemFriendlyURLProvider<FileEntry> infoItemFriendlyURLProvider,
Language language) {

_fileEntry = fileEntry;
_friendlyURLEntryLocalService = friendlyURLEntryLocalService;
_infoItemFriendlyURLProvider = infoItemFriendlyURLProvider;
_language = language;

_assetEntry = _getAssetEntry(fileEntry);
}
Expand Down Expand Up @@ -94,16 +96,8 @@ public String getTitle(Locale locale) {

@Override
public String getURLTitle(Locale locale) {
FriendlyURLEntry mainFriendlyURLEntry =
_friendlyURLEntryLocalService.fetchMainFriendlyURLEntry(
PortalUtil.getClassNameId(FileEntry.class),
_fileEntry.getFileEntryId());

if (mainFriendlyURLEntry == null) {
return String.valueOf(_fileEntry.getFileEntryId());
}

return mainFriendlyURLEntry.getUrlTitle();
return _infoItemFriendlyURLProvider.getFriendlyURL(
_fileEntry, _language.getLanguageId(locale));
}

private AssetEntry _getAssetEntry(FileEntry fileEntry) {
Expand Down Expand Up @@ -139,6 +133,8 @@ private AssetEntry _getAssetEntry(FileEntry fileEntry) {

private final AssetEntry _assetEntry;
private final FileEntry _fileEntry;
private final FriendlyURLEntryLocalService _friendlyURLEntryLocalService;
private final InfoItemFriendlyURLProvider<FileEntry>
_infoItemFriendlyURLProvider;
private final Language _language;

}
Expand Up @@ -14,12 +14,14 @@

package com.liferay.document.library.web.internal.layout.display.page;

import com.liferay.friendly.url.info.item.provider.InfoItemFriendlyURLProvider;
import com.liferay.friendly.url.model.FriendlyURLEntry;
import com.liferay.friendly.url.service.FriendlyURLEntryLocalService;
import com.liferay.info.item.InfoItemReference;
import com.liferay.layout.display.page.LayoutDisplayPageObjectProvider;
import com.liferay.layout.display.page.LayoutDisplayPageProvider;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.portlet.constants.FriendlyURLResolverConstants;
import com.liferay.portal.kernel.repository.LocalRepository;
import com.liferay.portal.kernel.repository.RepositoryProvider;
Expand Down Expand Up @@ -64,7 +66,7 @@ public String getClassName() {
}

return new FileEntryLayoutDisplayPageObjectProvider(
fileEntry, _friendlyURLEntryLocalService);
fileEntry, _infoItemFriendlyURLProvider, _language);
}
catch (PortalException portalException) {
throw new RuntimeException(portalException);
Expand Down Expand Up @@ -102,6 +104,14 @@ public String getURLSeparator() {
@Reference
private FriendlyURLEntryLocalService _friendlyURLEntryLocalService;

@Reference(
target = "(item.class.name=com.liferay.portal.kernel.repository.model.FileEntry)"
)
private InfoItemFriendlyURLProvider<FileEntry> _infoItemFriendlyURLProvider;

@Reference
private Language _language;

@Reference
private RepositoryProvider _repositoryProvider;

Expand Down