
com.liferay.commerce.product.internal.trash.CPDefinitionTrashHandler Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.commerce.product.internal.trash;
import com.liferay.commerce.product.model.CPDefinition;
import com.liferay.commerce.product.service.CPDefinitionLocalService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.model.LayoutConstants;
import com.liferay.portal.kernel.portlet.PortletProvider;
import com.liferay.portal.kernel.portlet.PortletProviderUtil;
import com.liferay.portal.kernel.portlet.PortletURLFactoryUtil;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import com.liferay.portal.kernel.trash.BaseTrashHandler;
import com.liferay.portal.kernel.trash.TrashHandler;
import com.liferay.portal.kernel.util.Portal;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
import javax.servlet.http.HttpServletRequest;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* Implements trash handling for the commerce product definition entity.
*
* @author Alessio Antonio Rendina
*/
@Component(
property = "model.class.name=com.liferay.commerce.product.model.CPDefinition",
service = TrashHandler.class
)
public class CPDefinitionTrashHandler extends BaseTrashHandler {
@Override
public void deleteTrashEntry(long cpDefinitionId) throws PortalException {
_cpDefinitionLocalService.deleteCPDefinition(cpDefinitionId);
}
@Override
public String getClassName() {
return CPDefinition.class.getName();
}
@Override
public String getRestoreContainedModelLink(
PortletRequest portletRequest, long cpDefinitionId)
throws PortalException {
PortletURL portletURL = getRestoreURL(
portletRequest, cpDefinitionId, false);
CPDefinition cpDefinition = _cpDefinitionLocalService.getCPDefinition(
cpDefinitionId);
portletURL.setParameter(
"cpDefinitionId", String.valueOf(cpDefinition.getCPDefinitionId()));
return portletURL.toString();
}
@Override
public String getRestoreContainerModelLink(
PortletRequest portletRequest, long cpDefinitionId)
throws PortalException {
PortletURL portletURL = getRestoreURL(
portletRequest, cpDefinitionId, true);
return portletURL.toString();
}
@Override
public String getRestoreMessage(
PortletRequest portletRequest, long cpDefinitionId) {
HttpServletRequest httpServletRequest = _portal.getHttpServletRequest(
portletRequest);
return LanguageUtil.get(httpServletRequest, "catalog");
}
@Override
public boolean isInTrash(long cpDefinitionId) throws PortalException {
CPDefinition cpDefinition = _cpDefinitionLocalService.getCPDefinition(
cpDefinitionId);
return cpDefinition.isInTrash();
}
@Override
public void restoreTrashEntry(long userId, long cpDefinitionId)
throws PortalException {
_cpDefinitionLocalService.restoreCPDefinitionFromTrash(
userId, cpDefinitionId);
}
protected PortletURL getRestoreURL(
PortletRequest portletRequest, long cpDefinitionId,
boolean containerModel)
throws PortalException {
PortletURL portletURL = null;
CPDefinition cpDefinition = _cpDefinitionLocalService.getCPDefinition(
cpDefinitionId);
String portletId = PortletProviderUtil.getPortletId(
CPDefinition.class.getName(), PortletProvider.Action.VIEW);
long plid = _portal.getPlidFromPortletId(
cpDefinition.getGroupId(), portletId);
if (plid == LayoutConstants.DEFAULT_PLID) {
portletId = PortletProviderUtil.getPortletId(
CPDefinition.class.getName(), PortletProvider.Action.MANAGE);
portletURL = _portal.getControlPanelPortletURL(
portletRequest, portletId, PortletRequest.RENDER_PHASE);
}
else {
portletURL = PortletURLFactoryUtil.create(
portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);
}
if (!containerModel) {
portletURL.setParameter("mvcPath", "/view.jsp");
}
return portletURL;
}
@Override
protected boolean hasPermission(
PermissionChecker permissionChecker, long cpDefinitionId,
String actionId)
throws PortalException {
return _cpDefinitionModelResourcePermission.contains(
permissionChecker, cpDefinitionId, actionId);
}
@Reference
private CPDefinitionLocalService _cpDefinitionLocalService;
@Reference(
target = "(model.class.name=com.liferay.commerce.product.model.CPDefinition)"
)
private ModelResourcePermission
_cpDefinitionModelResourcePermission;
@Reference
private Portal _portal;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy