Hierarchical long friendly urlHierarchical long friendly urlhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1207539992024-03-28T23:03:39Z2024-03-28T23:03:39ZRE: Hierarchical long friendly urlSergey Shishovhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1207856302021-05-17T09:19:24Z2021-05-17T06:37:43Z<span class="h5 text-default">
<div class="alert alert-info">
<p> Dear Sergey Shishov,<br />
<br /> Thank you for participating in the Liferay
Community. Your post is currently awaiting moderation
and will not be visible to other posters.<br />
<br /> Also please note you are limited to 3 posts
per hour and 50 posts per day. Exceeding the post
limit will temporarily disable posting.<br />
<br /> One of our moderators will review your post shortly.<br />
<br /> Sincerely,<br /> Webmaster<br />
webmaster@community.liferay.com<br /> http://liferay.dev <br /></p></div></span>
Original Post: <br />
<br />
<p>Finally there are:</p>
<p>1) service-builder component to store long friendly urls (FriendlyUrlLong)</p>
<p>2) ModelListener-hook to create long friendly urls (buiseness logic)</p>
<p>3) Override some LayoutLocalService methods:</p>
<ul>
<li>updateLayout (replace urls with cropped one)</li>
<li>deleteLayout (syncronious remove our urls)</li>
<li>getFriendlyURLLayout</li></ul>
<pre><code class="language-java"> @Override
public Layout getFriendlyURLLayout(long groupId, boolean privateLayout, String friendlyURL) throws PortalException {
Layout layout = null;
// Try find by our long friendly url.
String normalizedUrl = FriendlyURLNormalizerUtil.normalizeWithEncoding(friendlyURL);
FriendlyUrlLong friendlyUrlLong = FriendlyUrlLongLocalServiceUtil.fetchByFriendlyUrl(normalizedUrl);
if (friendlyUrlLong != null) {
long plid = friendlyUrlLong.getPlid();
layout = LayoutLocalServiceUtil.fetchLayout(plid);
}
// Try find by liferay.
if (layout == null) {
layout = LayoutLocalServiceUtil.getLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
}
return layout;
}</code></pre>
<p>4) Override some LayoutFriendlyURLLocalService methods:</p>
<ul>
<li>updateLayoutFriendlyURLs (replace urls with cropped one)</li>
<li>getLayoutFriendlyURL</li></ul>
<pre><code class="language-java"> @Override
public LayoutFriendlyURL getLayoutFriendlyURL(long plid, String languageId) throws PortalException {
LayoutFriendlyURL layoutFriendlyURL = getLayoutFriendlyURLInternal(plid);
if (layoutFriendlyURL != null) {
return layoutFriendlyURL;
}
return super.getLayoutFriendlyURL(plid, languageId);
}
@Override
public LayoutFriendlyURL getLayoutFriendlyURL(long plid, String languageId, boolean useDefault) throws PortalException {
LayoutFriendlyURL layoutFriendlyURL = getLayoutFriendlyURLInternal(plid);
if (layoutFriendlyURL != null) {
return layoutFriendlyURL;
}
return super.getLayoutFriendlyURL(plid, languageId, useDefault);
}
private LayoutFriendlyURL getLayoutFriendlyURLInternal(long plid) {
// Try to find our long friendly url.
FriendlyUrlLong friendlyUrlLong = FriendlyUrlLongLocalServiceUtil.fetchFriendlyUrlLong(plid);
if (friendlyUrlLong != null) {
String longFriendlyUrl = friendlyUrlLong.getFriendlyUrl();
// Compose fake LayoutFriendlyURL.
LayoutFriendlyURL fakeLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.createLayoutFriendlyURL(0);
fakeLayoutFriendlyURL.setFriendlyURL(longFriendlyUrl);
return fakeLayoutFriendlyURL;
}
return null;
}</code></pre>
<p> </p>Sergey Shishov2021-05-17T06:37:43ZHierarchical long friendly urlSergey Shishovhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1207539982021-05-04T16:36:05Z2021-05-04T12:20:24Z<p>
<span class="h5 text-default"></span></p>
<p>Hello!</p>
<p>We need to use friendly urls like <b>\xxx\yyy\zzz</b></p>
<p>Urls are localized (stores in DB with %-symbols) and may be long enough.</p>
<p>To make friendlyurl hierarchical I use ModelListener-hook with
onAfterUpdate() action, and it normally works.</p>
<p>But default friendlyurl length is only 255 characters.</p>
<p>With changed length at db-column all works, but fails at</p>
<pre><code class="language-java">FriendlyURLEntryLocalServiceImpl.updateFriendlyURLEntry()</code></pre>
<p>at validate() method</p>
<p>
<strong>Guess1</strong></p>
<p>How to correct modify length of friendlyurl column (at 'layout' and
'layoutfriendlyurl' tables)?</p>
<p>May be with EXT or model-hints?</p>
<p>
<strong>Guess2</strong></p>
<p>Not to modify DB, but create a new table with my own long friendly urls?</p>
<p>I will try to create this with service-builder.<br />1. Save urls
works fine<br />2. To find layout with url I override </p>
<pre><code class="language-java">LayoutLocalServiceWrapper.getFriendlyURLLayout()</code></pre>
<p>used in</p>
<pre><code class="language-java">PortalImpl.getPortletFriendlyURLMapperLayoutQueryStringComposite()</code></pre>
<p>Page successfully found, but url in address panel change to 'system' at</p>
<pre><code class="language-java">FriendlyUrlServlet with PortalImpl.getLocalizedFriendlyURL()</code></pre>
<p>And I dont want to override whole PortalImpl.</p>
<p>May be it is real to override FriendlyUrlServlet?</p>
<