001    /**
002     * Copyright (c) 2000-2013 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 TYPE = "record";
034    
035            public AssetRenderer getAssetRenderer(long classPK, int type)
036                    throws PortalException, SystemException {
037    
038                    DDLRecord record = null;
039                    DDLRecordVersion recordVersion = null;
040    
041                    if (type == TYPE_LATEST) {
042                            recordVersion = DDLRecordLocalServiceUtil.getRecordVersion(classPK);
043    
044                            record = recordVersion.getRecord();
045                    }
046                    else {
047                            record = DDLRecordLocalServiceUtil.getRecord(classPK);
048    
049                            recordVersion = record.getRecordVersion();
050                    }
051    
052                    DDLRecordAssetRenderer ddlRecordAssetRenderer =
053                            new DDLRecordAssetRenderer(record, recordVersion);
054    
055                    ddlRecordAssetRenderer.setAssetRendererType(type);
056    
057                    return ddlRecordAssetRenderer;
058            }
059    
060            public String getClassName() {
061                    return DDLRecord.class.getName();
062            }
063    
064            public String getType() {
065                    return TYPE;
066            }
067    
068            @Override
069            public boolean hasPermission(
070                            PermissionChecker permissionChecker, long classPK, String actionId)
071                    throws Exception {
072    
073                    DDLRecord record = DDLRecordLocalServiceUtil.getRecord(classPK);
074    
075                    return DDLRecordSetPermission.contains(
076                            permissionChecker, record.getRecordSet(), actionId);
077            }
078    
079            @Override
080            public boolean isCategorizable() {
081                    return _CATEGORIZABLE;
082            }
083    
084            @Override
085            public boolean isSelectable() {
086                    return _SELECTABLE;
087            }
088    
089            @Override
090            protected String getIconPath(ThemeDisplay themeDisplay) {
091                    return themeDisplay.getPathThemeImages() + "/common/history.png";
092            }
093    
094            private static final boolean _CATEGORIZABLE = false;
095    
096            private static final boolean _SELECTABLE = false;
097    
098    }