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 CLASS_NAME = DDLRecord.class.getName();
034    
035            public static final String TYPE = "record";
036    
037            @Override
038            public AssetRenderer getAssetRenderer(long classPK, int type)
039                    throws PortalException, SystemException {
040    
041                    DDLRecord record = null;
042                    DDLRecordVersion recordVersion = null;
043    
044                    if (type == TYPE_LATEST) {
045                            recordVersion = DDLRecordLocalServiceUtil.getRecordVersion(classPK);
046    
047                            record = recordVersion.getRecord();
048                    }
049                    else {
050                            record = DDLRecordLocalServiceUtil.getRecord(classPK);
051    
052                            recordVersion = record.getRecordVersion();
053                    }
054    
055                    return new DDLRecordAssetRenderer(record, recordVersion);
056            }
057    
058            @Override
059            public String getClassName() {
060                    return CLASS_NAME;
061            }
062    
063            @Override
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    }