001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatalists.asset;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portlet.asset.model.AssetRenderer;
022    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
023    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
024    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
025    import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
026    import com.liferay.portlet.dynamicdatalists.service.permission.DDLRecordSetPermission;
027    
028    /**
029     * @author Marcellus Tavares
030     */
031    public class DDLRecordAssetRendererFactory extends BaseAssetRendererFactory {
032    
033            public static final String CLASS_NAME = DDLRecord.class.getName();
034    
035            public static final String TYPE = "record";
036    
037            public AssetRenderer getAssetRenderer(long classPK, int type)
038                    throws PortalException, SystemException {
039    
040                    DDLRecord record = null;
041                    DDLRecordVersion recordVersion = null;
042    
043                    if (type == TYPE_LATEST) {
044                            recordVersion = DDLRecordLocalServiceUtil.getRecordVersion(classPK);
045    
046                            record = recordVersion.getRecord();
047                    }
048                    else {
049                            record = DDLRecordLocalServiceUtil.getRecord(classPK);
050    
051                            recordVersion = record.getRecordVersion();
052                    }
053    
054                    return new DDLRecordAssetRenderer(record, recordVersion);
055            }
056    
057            public String getClassName() {
058                    return CLASS_NAME;
059            }
060    
061            public String getType() {
062                    return TYPE;
063            }
064    
065            @Override
066            public boolean hasPermission(
067                            PermissionChecker permissionChecker, long classPK, String actionId)
068                    throws Exception {
069    
070                    DDLRecord record = DDLRecordLocalServiceUtil.getRecord(classPK);
071    
072                    return DDLRecordSetPermission.contains(
073                            permissionChecker, record.getRecordSet(), actionId);
074            }
075    
076            @Override
077            public boolean isCategorizable() {
078                    return false;
079            }
080    
081            @Override
082            protected String getIconPath(ThemeDisplay themeDisplay) {
083                    return themeDisplay.getPathThemeImages() + "/common/history.png";
084            }
085    
086    }