Skip to content

Commit

Permalink
LPS-106397 Apply to LayoutFinderImpl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Preston-Crary authored and brianchandotcom committed Apr 4, 2020
1 parent 3806db3 commit 3d8d544
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@

package com.liferay.portal.service.persistence.impl;

import com.liferay.petra.sql.dsl.DSLFunctionFactoryUtil;
import com.liferay.petra.sql.dsl.DSLQueryFactoryUtil;
import com.liferay.petra.sql.dsl.expression.Predicate;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.dao.orm.Type;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.model.GroupTable;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutReference;
import com.liferay.portal.kernel.model.LayoutSoap;
import com.liferay.portal.kernel.model.LayoutTable;
import com.liferay.portal.kernel.model.PortletPreferencesTable;
import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
import com.liferay.portal.kernel.service.persistence.LayoutFinder;
import com.liferay.portal.kernel.service.persistence.LayoutUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.model.impl.LayoutImpl;
import com.liferay.util.dao.orm.CustomSQLUtil;

import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -40,25 +44,24 @@
public class LayoutFinderImpl
extends LayoutFinderBaseImpl implements LayoutFinder {

public static final String FIND_BY_NULL_FRIENDLY_URL =
LayoutFinder.class.getName() + ".findByNullFriendlyURL";

public static final String FIND_BY_SCOPE_GROUP =
LayoutFinder.class.getName() + ".findByScopeGroup";

public static final String FIND_BY_C_P_P =
LayoutFinder.class.getName() + ".findByC_P_P";

@Override
public List<Layout> findByNullFriendlyURL() {
Session session = null;

try {
session = openSession();

String sql = CustomSQLUtil.get(FIND_BY_NULL_FRIENDLY_URL);

SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);
SQLQuery sqlQuery = session.createSynchronizedSQLQuery(
DSLQueryFactoryUtil.select(
).from(
LayoutTable.INSTANCE
).where(
LayoutTable.INSTANCE.friendlyURL.eq(
""
).or(
LayoutTable.INSTANCE.friendlyURL.isNull()
)
));

sqlQuery.addEntity("Layout", LayoutImpl.class);

Expand All @@ -74,93 +77,70 @@ public List<Layout> findByNullFriendlyURL() {

@Override
public List<Layout> findByScopeGroup(long groupId) {
Session session = null;

try {
session = openSession();

String sql = CustomSQLUtil.get(FIND_BY_SCOPE_GROUP);

sql = StringUtil.removeSubstring(
sql, "AND (Layout.privateLayout = ?)");

sql = InlineSQLHelperUtil.replacePermissionCheck(
sql, Layout.class.getName(), "Layout.plid", groupId);

SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);

sqlQuery.addEntity("Layout", LayoutImpl.class);

QueryPos queryPos = QueryPos.getInstance(sqlQuery);

queryPos.add(groupId);

return sqlQuery.list(true);
}
catch (Exception exception) {
throw new SystemException(exception);
}
finally {
closeSession(session);
}
return _findByScopeGroup(
LayoutTable.INSTANCE.groupId.eq(
groupId
).and(
InlineSQLHelperUtil.getPermissionWherePredicate(
Layout.class, LayoutTable.INSTANCE.plid, groupId)
));
}

@Override
public List<Layout> findByScopeGroup(long groupId, boolean privateLayout) {
Session session = null;

try {
session = openSession();

String sql = CustomSQLUtil.get(FIND_BY_SCOPE_GROUP);

SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);

sqlQuery.addEntity("Layout", LayoutImpl.class);

QueryPos queryPos = QueryPos.getInstance(sqlQuery);

queryPos.add(groupId);
queryPos.add(privateLayout);

return sqlQuery.list(true);
}
catch (Exception exception) {
throw new SystemException(exception);
}
finally {
closeSession(session);
}
return _findByScopeGroup(
LayoutTable.INSTANCE.groupId.eq(
groupId
).and(
LayoutTable.INSTANCE.privateLayout.eq(privateLayout)
));
}

@Override
public List<LayoutReference> findByC_P_P(
long companyId, String portletId, String preferencesKey,
String preferencesValue) {

String preferences = StringBundler.concat(
"%<preference><name>", preferencesKey, "</name><value>",
preferencesValue, "</value>%");

Session session = null;

try {
session = openSession();

String sql = CustomSQLUtil.get(FIND_BY_C_P_P);

SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);
SQLQuery sqlQuery = session.createSynchronizedSQLQuery(
DSLQueryFactoryUtil.selectDistinct(
LayoutTable.INSTANCE.plid.as("layoutPlid"),
PortletPreferencesTable.INSTANCE.portletId.as(
"preferencesPortletId")
).from(
LayoutTable.INSTANCE
).innerJoinON(
PortletPreferencesTable.INSTANCE,
PortletPreferencesTable.INSTANCE.plid.eq(
LayoutTable.INSTANCE.plid)
).where(
LayoutTable.INSTANCE.companyId.eq(
companyId
).and(
PortletPreferencesTable.INSTANCE.portletId.eq(
portletId
).or(
PortletPreferencesTable.INSTANCE.portletId.like(
portletId.concat("_INSTANCE_%"))
).withParentheses()
).and(
DSLFunctionFactoryUtil.castClobText(
PortletPreferencesTable.INSTANCE.preferences
).like(
StringBundler.concat(
"%<preference><name>", preferencesKey,
"</name><value>", preferencesValue, "</value>%")
)
)
));

sqlQuery.addScalar("layoutPlid", Type.LONG);
sqlQuery.addScalar("preferencesPortletId", Type.STRING);

QueryPos queryPos = QueryPos.getInstance(sqlQuery);

queryPos.add(companyId);
queryPos.add(portletId);
queryPos.add(portletId.concat("_INSTANCE_%"));
queryPos.add(preferences);

List<LayoutReference> layoutReferences = new ArrayList<>();

Iterator<Object[]> itr = sqlQuery.iterate();
Expand Down Expand Up @@ -189,4 +169,41 @@ public List<LayoutReference> findByC_P_P(
}
}

private List<Layout> _findByScopeGroup(Predicate wherePredicate) {
Session session = null;

try {
session = openSession();

SQLQuery sqlQuery = session.createSynchronizedSQLQuery(
DSLQueryFactoryUtil.select(
).from(
LayoutTable.INSTANCE
).innerJoinON(
GroupTable.INSTANCE,
GroupTable.INSTANCE.companyId.eq(
LayoutTable.INSTANCE.companyId
).and(
GroupTable.INSTANCE.classNameId.eq(
PortalUtil.getClassNameId(Layout.class))
).and(
GroupTable.INSTANCE.classPK.eq(
LayoutTable.INSTANCE.plid)
)
).where(
wherePredicate
));

sqlQuery.addEntity("Layout", LayoutImpl.class);

return sqlQuery.list(true);
}
catch (Exception exception) {
throw new SystemException(exception);
}
finally {
closeSession(session);
}
}

}
45 changes: 0 additions & 45 deletions portal-impl/src/custom-sql/portal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,51 +333,6 @@
(Users_Groups.userId = ?)
]]>
</sql>
<sql id="com.liferay.portal.kernel.service.persistence.LayoutFinder.findByNullFriendlyURL">
<![CDATA[
SELECT
{Layout.*}
FROM
Layout
WHERE
(friendlyURL = '') OR
(friendlyURL IS NULL)
]]>
</sql>
<sql id="com.liferay.portal.kernel.service.persistence.LayoutFinder.findByScopeGroup">
<![CDATA[
SELECT
{Layout.*}
FROM
Layout
INNER JOIN
Group_ ON
(Group_.companyId = Layout.companyId) AND
(Group_.classNameId = [$CLASS_NAME_ID_COM.LIFERAY.PORTAL.MODEL.LAYOUT$]) AND
(Group_.classPK = Layout.plid)
WHERE
(Layout.groupId = ?) AND
(Layout.privateLayout = ?)
]]>
</sql>
<sql id="com.liferay.portal.kernel.service.persistence.LayoutFinder.findByC_P_P">
<![CDATA[
SELECT
DISTINCT Layout.plid AS layoutPlid, PortletPreferences.portletId AS preferencesPortletId
FROM
Layout
INNER JOIN
PortletPreferences ON
PortletPreferences.plid = Layout.plid
WHERE
(Layout.companyId = ?) AND
(
(PortletPreferences.portletId = ?) OR
(PortletPreferences.portletId LIKE ?)
) AND
(CAST_CLOB_TEXT(PortletPreferences.preferences) LIKE ?)
]]>
</sql>
<sql id="com.liferay.portal.kernel.service.persistence.OrganizationFinder.countO_ByGroupId">
<![CDATA[
SELECT
Expand Down

0 comments on commit 3d8d544

Please sign in to comment.