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