Skip to content

Commit

Permalink
LPS-27122 Create a TrashRenderer interface and implement it for all s…
Browse files Browse the repository at this point in the history
…upported models
  • Loading branch information
Zsolt Berentey authored and brianchandotcom committed May 14, 2012
1 parent 82a1980 commit 23d6500
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 78 deletions.
Expand Up @@ -16,13 +16,15 @@

import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.trash.TrashRenderer;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.security.permission.ActionKeys;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;
import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
import com.liferay.portlet.asset.model.BaseAssetRenderer;
import com.liferay.portlet.blogs.model.BlogsEntry;
import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
Expand All @@ -39,8 +41,10 @@
* @author Jorge Ferrer
* @author Juan Fernández
* @author Sergio González
* @author Zsolt Berentey
*/
public class BlogsEntryAssetRenderer extends BaseAssetRenderer {
public class BlogsEntryAssetRenderer extends BaseAssetRenderer
implements TrashRenderer {

public BlogsEntryAssetRenderer(BlogsEntry entry) {
_entry = entry;
Expand All @@ -64,6 +68,15 @@ public long getGroupId() {
return _entry.getGroupId();
}

@Override
public String getIconPath(ThemeDisplay themeDisplay) {
return getAssetRendererFactory().getIconPath(themeDisplay);
}

public String getPortletId() {
return getAssetRendererFactory().getPortletId();
}

public String getSummary(Locale locale) {
return HtmlUtil.stripHtml(_entry.getDescription());
}
Expand All @@ -72,6 +85,10 @@ public String getTitle(Locale locale) {
return _entry.getTitle();
}

public String getType() {
return BlogsEntryAssetRendererFactory.TYPE;
}

@Override
public PortletURL getURLEdit(
LiferayPortletRequest liferayPortletRequest,
Expand Down Expand Up @@ -129,6 +146,11 @@ public String getUuid() {
return _entry.getUuid();
}

public boolean hasDeletePermission(PermissionChecker permissionChecker) {
return BlogsEntryPermission.contains(
permissionChecker, _entry, ActionKeys.DELETE);
}

@Override
public boolean hasEditPermission(PermissionChecker permissionChecker) {
return BlogsEntryPermission.contains(
Expand Down Expand Up @@ -163,11 +185,18 @@ public String render(
}
}

@Override
protected String getIconPath(ThemeDisplay themeDisplay) {
return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
private BlogsEntryAssetRendererFactory getAssetRendererFactory() {
if (_factory == null) {
_factory = (BlogsEntryAssetRendererFactory)
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
BlogsEntryAssetRendererFactory.CLASS_NAME);
}

return _factory;
}

private BlogsEntry _entry;
private BlogsEntryAssetRendererFactory _factory;

}
Expand Up @@ -20,6 +20,7 @@
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.FileVersion;
import com.liferay.portal.kernel.trash.TrashRenderer;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.security.permission.ActionKeys;
Expand All @@ -28,6 +29,7 @@
import com.liferay.portal.util.PortletKeys;
import com.liferay.portal.util.PropsValues;
import com.liferay.portal.util.WebKeys;
import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
import com.liferay.portlet.asset.model.BaseAssetRenderer;
import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
Expand All @@ -44,8 +46,10 @@
* @author Julio Camarero
* @author Juan Fernández
* @author Sergio González
* @author Zsolt Berentey
*/
public class DLFileEntryAssetRenderer extends BaseAssetRenderer {
public class DLFileEntryAssetRenderer extends BaseAssetRenderer
implements TrashRenderer {

public DLFileEntryAssetRenderer(
FileEntry fileEntry, FileVersion fileVersion) {
Expand Down Expand Up @@ -80,6 +84,15 @@ public long getGroupId() {
return _fileEntry.getGroupId();
}

@Override
public String getIconPath(ThemeDisplay themeDisplay) {
return getAssetRendererFactory().getIconPath(themeDisplay);
}

public String getPortletId() {
return getAssetRendererFactory().getPortletId();
}

public String getSummary(Locale locale) {
return HtmlUtil.stripHtml(_fileEntry.getDescription());
}
Expand All @@ -88,6 +101,10 @@ public String getTitle(Locale locale) {
return _fileVersion.getTitle();
}

public String getType() {
return DLFileEntryAssetRendererFactory.TYPE;
}

@Override
public String getURLDownload(ThemeDisplay themeDisplay) {
return DLUtil.getPreviewURL(
Expand Down Expand Up @@ -149,6 +166,13 @@ public String getUuid() {
return _fileEntry.getUuid();
}

public boolean hasDeletePermission(PermissionChecker permissionChecker)
throws PortalException, SystemException {

return DLFileEntryPermission.contains(
permissionChecker, _fileEntry.getFileEntryId(), ActionKeys.DELETE);
}

@Override
public boolean hasEditPermission(PermissionChecker permissionChecker)
throws PortalException, SystemException {
Expand Down Expand Up @@ -195,12 +219,18 @@ public String render(
}
}

@Override
protected String getIconPath(ThemeDisplay themeDisplay) {
return themeDisplay.getPathThemeImages() + "/file_system/small/" +
_fileEntry.getIcon() + ".png";
private DLFileEntryAssetRendererFactory getAssetRendererFactory() {
if (_factory == null) {
_factory = (DLFileEntryAssetRendererFactory)
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(
DLFileEntryAssetRendererFactory.CLASS_NAME);
}

return _factory;
}

private DLFileEntryAssetRendererFactory _factory;
private FileEntry _fileEntry;
private FileVersion _fileVersion;

Expand Down
Expand Up @@ -18,13 +18,11 @@
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.trash.TrashHandler;
import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
import com.liferay.portal.kernel.trash.TrashRenderer;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.security.permission.ActionKeys;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.util.PropsValues;
import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
import com.liferay.portlet.asset.model.AssetRendererFactory;
import com.liferay.portlet.trash.model.TrashEntry;
import com.liferay.portlet.trash.service.base.TrashEntryServiceBaseImpl;

Expand Down Expand Up @@ -59,24 +57,20 @@ public void deleteEntries(long groupId)
String className = entry.getClassName();
long classPK = entry.getClassPK();

AssetRendererFactory assetRendererFactory =
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(className);

try {
if (assetRendererFactory.hasPermission(
permissionChecker, classPK, ActionKeys.DELETE)) {
TrashHandler trashHandler =
TrashHandlerRegistryUtil.getTrashHandler(className);

TrashHandler trashHandler =
TrashHandlerRegistryUtil.getTrashHandler(className);
TrashRenderer trashRenderer = trashHandler.getTrashRenderer(
classPK);

if (trashRenderer.hasDeletePermission(permissionChecker)) {
trashHandler.deleteTrashEntry(classPK);
}
}
catch (Exception e) {
}
}

}

/**
Expand Down Expand Up @@ -124,14 +118,14 @@ public Object[] getEntries(
String className = entry.getClassName();
long classPK = entry.getClassPK();

AssetRendererFactory assetRendererFactory =
AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(className);

try {
if (assetRendererFactory.hasPermission(
permissionChecker, classPK, ActionKeys.VIEW)) {
TrashHandler trashHandler =
TrashHandlerRegistryUtil.getTrashHandler(className);

TrashRenderer trashRenderer = trashHandler.getTrashRenderer(
classPK);

if (trashRenderer.hasViewPermission(permissionChecker)) {
filteredEntries.add(entry);
}
}
Expand Down
Expand Up @@ -37,6 +37,7 @@
* </ul>
*
* @author Alexander Chow
* @author Zsolt Berentey
*/
public abstract class BaseTrashHandler implements TrashHandler {

Expand All @@ -46,22 +47,21 @@ public void deleteTrashEntry(long classPK)
deleteTrashEntries(new long[] {classPK});
}

public AssetRenderer getAssetRenderer(long classPK)
public TrashRenderer getTrashRenderer(long classPK)
throws PortalException, SystemException {

AssetRendererFactory assetRendererFactory = getAssetRendererFactory();

if (assetRendererFactory != null) {
return assetRendererFactory.getAssetRenderer(classPK);
}
else {
return null;
AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(
classPK);

if (assetRenderer instanceof TrashRenderer) {
return (TrashRenderer)assetRenderer;
}
}
}

public AssetRendererFactory getAssetRendererFactory() {
return AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(getClassName());
return null;
}

public void restoreTrashEntry(long classPK)
Expand All @@ -70,4 +70,9 @@ public void restoreTrashEntry(long classPK)
restoreTrashEntries(new long[] {classPK});
}

private AssetRendererFactory getAssetRendererFactory() {
return AssetRendererFactoryRegistryUtil.
getAssetRendererFactoryByClassName(getClassName());
}

}
Expand Up @@ -16,8 +16,6 @@

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portlet.asset.model.AssetRenderer;
import com.liferay.portlet.asset.model.AssetRendererFactory;

/**
* Represents the interface to manage the basic operations of the Recycle Bin.
Expand Down Expand Up @@ -76,31 +74,24 @@ public void deleteTrashEntry(long classPK)
throws PortalException, SystemException;

/**
* Returns the asset renderer associated to the trash entry.
* Returns the class name of the entry.
*
* @return the class name of the entry
*/
public String getClassName();

/**
* Returns the trash renderer associated to the trash entry.
*
* @param classPK the primary key of the trash entry
* @return the asset renderer associated to the trash entry
* @return the trash renderer associated to the trash entry
* @throws PortalException if an entry with the primary key could not be
* found
* @throws SystemException if a system exception occurred
*/
public AssetRenderer getAssetRenderer(long classPK)
public TrashRenderer getTrashRenderer(long classPK)
throws PortalException, SystemException;

/**
* Returns the asset renderer factory for the entry entity
*
* @return the asset renderer factory for the entry entity
*/
public AssetRendererFactory getAssetRendererFactory();

/**
* Returns the class name of the entry.
*
* @return the class name of the entry
*/
public String getClassName();

/**
* Restores all entries with the primary keys.
*
Expand Down

0 comments on commit 23d6500

Please sign in to comment.