001
014
015 package com.liferay.portal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.model.RoleConstants;
023 import com.liferay.portal.model.Team;
024 import com.liferay.portal.service.TeamLocalServiceUtil;
025 import com.liferay.portal.util.PortalUtil;
026
027
031 public class RoleImpl extends RoleBaseImpl {
032
033 public RoleImpl() {
034 }
035
036 public String getDescriptiveName() throws PortalException, SystemException {
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 public String getTypeLabel() {
081 return RoleConstants.getTypeLabel(getType());
082 }
083
084 public boolean isTeam() {
085 return hasClassName(Team.class);
086 }
087
088 protected boolean hasClassName(Class<?> clazz) {
089 long classNameId = getClassNameId();
090
091 if (classNameId == PortalUtil.getClassNameId(clazz)) {
092 return true;
093 }
094 else {
095 return false;
096 }
097 }
098
099 private static Log _log = LogFactoryUtil.getLog(RoleImpl.class);
100
101 }