001
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
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 }