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            public RoleImpl() {
033            }
034    
035            @Override
036            public String getDescriptiveName() throws PortalException {
037                    String name = getName();
038    
039                    if (isTeam()) {
040                            Team team = TeamLocalServiceUtil.getTeam(getClassPK());
041    
042                            name = team.getName();
043                    }
044    
045                    return name;
046            }
047    
048            @Override
049            public String getTitle(String languageId) {
050                    String value = super.getTitle(languageId);
051    
052                    if (Validator.isNull(value)) {
053                            try {
054                                    value = getDescriptiveName();
055                            }
056                            catch (Exception e) {
057                                    _log.error(e, e);
058                            }
059                    }
060    
061                    return value;
062            }
063    
064            @Override
065            public String getTitle(String languageId, boolean useDefault) {
066                    String value = super.getTitle(languageId, useDefault);
067    
068                    if (Validator.isNull(value)) {
069                            try {
070                                    value = getDescriptiveName();
071                            }
072                            catch (Exception e) {
073                                    _log.error(e, e);
074                            }
075                    }
076    
077                    return value;
078            }
079    
080            @Override
081            public String getTypeLabel() {
082                    return RoleConstants.getTypeLabel(getType());
083            }
084    
085            @Override
086            public boolean isTeam() {
087                    return hasClassName(Team.class);
088            }
089    
090            protected boolean hasClassName(Class<?> clazz) {
091                    long classNameId = getClassNameId();
092    
093                    if (classNameId == PortalUtil.getClassNameId(clazz)) {
094                            return true;
095                    }
096                    else {
097                            return false;
098                    }
099            }
100    
101            private static final Log _log = LogFactoryUtil.getLog(RoleImpl.class);
102    
103    }