use of com.liferay.portal.ReservedUserScreenNameException in project liferay-ide by liferay.
the class UserLocalServiceImpl method validateScreenName.
protected void validateScreenName(long companyId, long userId, String screenName) throws PortalException, SystemException {
if (Validator.isNull(screenName)) {
throw new UserScreenNameException();
}
ScreenNameValidator screenNameValidator = ScreenNameValidatorFactory.getInstance();
if (!screenNameValidator.validate(companyId, screenName)) {
throw new UserScreenNameException();
}
if (Validator.isNumber(screenName)) {
if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
throw new UserScreenNameException();
}
if (!screenName.equals(String.valueOf(userId))) {
Group group = groupPersistence.fetchByPrimaryKey(GetterUtil.getLong(screenName));
if (group != null) {
throw new UserScreenNameException();
}
}
}
for (char c : screenName.toCharArray()) {
if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.PERIOD) && (c != CharPool.UNDERLINE)) {
throw new UserScreenNameException();
}
}
String[] anonymousNames = BaseServiceImpl.ANONYMOUS_NAMES;
for (String anonymousName : anonymousNames) {
if (StringUtil.equalsIgnoreCase(screenName, anonymousName)) {
throw new UserScreenNameException();
}
}
User user = userPersistence.fetchByC_SN(companyId, screenName);
if ((user != null) && (user.getUserId() != userId)) {
throw new DuplicateUserScreenNameException("{userId=" + userId + "}");
}
String friendlyURL = StringPool.SLASH + screenName;
Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);
if ((group != null) && (group.getClassPK() != userId)) {
throw new GroupFriendlyURLException(GroupFriendlyURLException.DUPLICATE);
}
int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
if (exceptionType != -1) {
throw new UserScreenNameException(new GroupFriendlyURLException(exceptionType));
}
String[] reservedScreenNames = PrefsPropsUtil.getStringArray(companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_SCREEN_NAMES);
for (String reservedScreenName : reservedScreenNames) {
if (StringUtil.equalsIgnoreCase(screenName, reservedScreenName)) {
throw new ReservedUserScreenNameException();
}
}
}
Aggregations