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.Role;
023 import com.liferay.portal.model.RoleConstants;
024 import com.liferay.portal.model.Team;
025 import com.liferay.portal.service.TeamLocalServiceUtil;
026 import com.liferay.portal.util.PortalUtil;
027
028
032 public class RoleImpl extends RoleModelImpl implements Role {
033
034 public RoleImpl() {
035 }
036
037 public String getDescriptiveName() throws PortalException, SystemException {
038 String name = getName();
039
040 if (isTeam()) {
041 Team team = TeamLocalServiceUtil.getTeam(getClassPK());
042
043 name = team.getName();
044 }
045
046 return name;
047 }
048
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 public String getTitle(String languageId, boolean useDefault) {
065 String value = super.getTitle(languageId, useDefault);
066
067 if (Validator.isNull(value)) {
068 try {
069 value = getDescriptiveName();
070 }
071 catch (Exception e) {
072 _log.error(e, e);
073 }
074 }
075
076 return value;
077 }
078
079 public String getTypeLabel() {
080 return RoleConstants.getTypeLabel(getType());
081 }
082
083 public boolean isTeam() {
084 return hasClassName(Team.class);
085 }
086
087 protected boolean hasClassName(Class<?> classObj) {
088 long classNameId = getClassNameId();
089
090 if (classNameId == PortalUtil.getClassNameId(classObj)) {
091 return true;
092 }
093 else {
094 return false;
095 }
096 }
097
098 private static Log _log = LogFactoryUtil.getLog(RoleImpl.class);
099
100 }