Skip to content

Commit

Permalink
Fix compilation problems after updating from 7.4 U54 to U75 caused by…
Browse files Browse the repository at this point in the history
… LPS-160434. Solved copying BasePanelApp code to IndexCheckerControlPanelEntry
  • Loading branch information
jorgediaz-lr committed May 8, 2023
1 parent 2d7f262 commit b03d226
Showing 1 changed file with 112 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package jorgediazest.indexchecker.portlet;

import com.liferay.application.list.BasePanelApp;
import com.liferay.application.list.GroupProvider;
import com.liferay.application.list.PanelApp;
import com.liferay.application.list.constants.PanelCategoryKeys;
import com.liferay.petra.string.StringPool;
Expand All @@ -24,14 +24,29 @@
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Portlet;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.ControlPanelEntry;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.JavaConstants;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.PortletCategoryKeys;
import com.liferay.portal.kernel.util.ResourceBundleUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;

import java.io.IOException;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jorgediazest.indexchecker.portlet.constants.IndexCheckerKeys;

import org.osgi.service.component.annotations.Component;
Expand All @@ -47,7 +62,14 @@
property = "panel.category.key=" + PanelCategoryKeys.CONTROL_PANEL_APPS,
service = PanelApp.class
)
public class IndexCheckerControlPanelEntry extends BasePanelApp {
public class IndexCheckerControlPanelEntry implements PanelApp {

@Override
public String getKey() {
Class<?> clazz = getClass();

return clazz.getName();
}

@Override
public String getLabel(Locale locale) {
Expand All @@ -62,7 +84,7 @@ public String getLabel(Locale locale) {
}
catch (MissingResourceException missingResourceException) {
if (_log.isDebugEnabled()) {
_log.debug(missingResourceException, missingResourceException);
_log.debug(missingResourceException);
}
}

Expand All @@ -72,11 +94,50 @@ public String getLabel(Locale locale) {
getPortletId());
}

@Override
public int getNotificationsCount(User user) {
return 0;
}

@Override
public Portlet getPortlet() {
return _portlet;
}

@Override
public String getPortletId() {
return IndexCheckerKeys.INDEXCHECKER;
}

@Override
public PortletURL getPortletURL(HttpServletRequest httpServletRequest)
throws PortalException {

PortletURL portletURL = PortalUtil.getControlPanelPortletURL(
httpServletRequest, getGroup(httpServletRequest), getPortletId(), 0,
0, PortletRequest.RENDER_PHASE);

Group group = groupProvider.getGroup(httpServletRequest);

if (group == null) {
return portletURL;
}

portletURL.setParameter(
"p_v_l_s_g_id", String.valueOf(group.getGroupId()));

return portletURL;
}

@Override
public boolean include(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
throws IOException {

return false;
}

@Override
public boolean isShow(PermissionChecker permissionChecker, Group group)
throws PortalException {
Expand All @@ -91,15 +152,58 @@ public boolean isShow(PermissionChecker permissionChecker, Group group)
}

@Override
@Reference(
target = "(javax.portlet.name=" + IndexCheckerKeys.INDEXCHECKER + ")",
unbind = "-"
)
public void setGroupProvider(GroupProvider groupProvider) {
this.groupProvider = groupProvider;
}

public void setPortlet(Portlet portlet) {
super.setPortlet(portlet);
}

protected ControlPanelEntry getControlPanelEntry() {
Portlet portlet = getPortlet();

if (portlet == null) {
return null;
}

return portlet.getControlPanelEntryInstance();
}

protected Group getGroup(HttpServletRequest httpServletRequest) {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);

Group group = themeDisplay.getScopeGroup();

if (!group.isControlPanel()) {
return null;
}

Portlet portlet = getPortlet();

String controlPanelEntryCategory =
portlet.getControlPanelEntryCategory();

if (Validator.isNull(controlPanelEntryCategory) ||
!controlPanelEntryCategory.startsWith(
PortletCategoryKeys.SITE_ADMINISTRATION) ||
(groupProvider == null)) {

return null;
}

return groupProvider.getGroup(httpServletRequest);
}

protected GroupProvider groupProvider;

private static final Log _log = LogFactoryUtil.getLog(
IndexCheckerControlPanelEntry.class);

@Reference(
target = "(javax.portlet.name=" + IndexCheckerKeys.INDEXCHECKER + ")"
)
private Portlet _portlet;

}

0 comments on commit b03d226

Please sign in to comment.