001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }