001    /**
002     * Copyright (c) 2000-present 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.portal.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.model.RoleConstants;
022    import com.liferay.portal.model.Team;
023    import com.liferay.portal.service.TeamLocalServiceUtil;
024    import com.liferay.portal.util.PortalUtil;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Jorge Ferrer
029     */
030    public class RoleImpl extends RoleBaseImpl {
031    
032            @Override
033            public String getDescriptiveName() throws PortalException {
034                    String name = getName();
035    
036                    if (isTeam()) {
037                            Team team = TeamLocalServiceUtil.getTeam(getClassPK());
038    
039                            name = team.getName();
040                    }
041    
042                    return name;
043            }
044    
045            @Override
046            public String getTitle(String languageId) {
047                    String value = super.getTitle(languageId);
048    
049                    if (Validator.isNull(value)) {
050                            try {
051                                    value = getDescriptiveName();
052                            }
053                            catch (Exception e) {
054                                    _log.error(e, e);
055                            }
056                    }
057    
058                    return value;
059            }
060    
061            @Override
062            public String getTitle(String languageId, boolean useDefault) {
063                    String value = super.getTitle(languageId, useDefault);
064    
065                    if (Validator.isNull(value)) {
066                            try {
067                                    value = getDescriptiveName();
068                            }
069                            catch (Exception e) {
070                                    _log.error(e, e);
071                            }
072                    }
073    
074                    return value;
075            }
076    
077            @Override
078            public String getTypeLabel() {
079                    return RoleConstants.getTypeLabel(getType());
080            }
081    
082            @Override
083            public boolean isSystem() {
084                    return PortalUtil.isSystemRole(getName());
085            }
086    
087            @Override
088            public boolean isTeam() {
089                    return hasClassName(Team.class);
090            }
091    
092            protected boolean hasClassName(Class<?> clazz) {
093                    long classNameId = getClassNameId();
094    
095                    if (classNameId == PortalUtil.getClassNameId(clazz)) {
096                            return true;
097                    }
098                    else {
099                            return false;
100                    }
101            }
102    
103            private static final Log _log = LogFactoryUtil.getLog(RoleImpl.class);
104    
105    }