use of com.liferay.portal.model.User 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();
}
}
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultUserGroups.
/**
* Adds the user to the default user groups, unless the user is already in
* these user groups. The default user groups can be specified in
* <code>portal.properties</code> with the property
* <code>admin.default.user.group.names</code>.
*
* @param userId the primary key of the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
@SuppressWarnings("deprecation")
public void addDefaultUserGroups(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> userGroupIdSet = new HashSet<Long>();
String[] defaultUserGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_USER_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_USER_GROUP_NAMES);
for (String defaultUserGroupName : defaultUserGroupNames) {
try {
UserGroup userGroup = userGroupPersistence.findByC_N(user.getCompanyId(), defaultUserGroupName);
if (!userPersistence.containsUserGroup(userId, userGroup.getUserGroupId())) {
userGroupIdSet.add(userGroup.getUserGroupId());
}
} catch (NoSuchUserGroupException nsuge) {
}
}
long[] userGroupIds = ArrayUtil.toArray(userGroupIdSet.toArray(new Long[userGroupIdSet.size()]));
if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
for (long userGroupId : userGroupIds) {
userGroupLocalService.copyUserGroupLayouts(userGroupId, userId);
}
}
userPersistence.addUserGroups(userId, userGroupIds);
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class UserLocalServiceImpl method addDefaultGroups.
/**
* Adds the user to the default groups, unless the user is already in these
* groups. The default groups can be specified in
* <code>portal.properties</code> with the key
* <code>admin.default.group.names</code>.
*
* @param userId the primary key of the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public void addDefaultGroups(long userId) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
Set<Long> groupIdsSet = new HashSet<Long>();
String[] defaultGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_GROUP_NAMES);
for (String defaultGroupName : defaultGroupNames) {
Company company = companyPersistence.findByPrimaryKey(user.getCompanyId());
Account account = company.getAccount();
if (StringUtil.equalsIgnoreCase(defaultGroupName, account.getName())) {
defaultGroupName = GroupConstants.GUEST;
}
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
String[] defaultOrganizationGroupNames = PrefsPropsUtil.getStringArray(user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ORGANIZATION_GROUP_NAMES);
for (String defaultOrganizationGroupName : defaultOrganizationGroupNames) {
defaultOrganizationGroupName += GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX;
Group group = groupPersistence.fetchByC_N(user.getCompanyId(), defaultOrganizationGroupName);
if ((group != null) && !userPersistence.containsGroup(userId, group.getGroupId())) {
groupIdsSet.add(group.getGroupId());
}
}
long[] groupIds = ArrayUtil.toArray(groupIdsSet.toArray(new Long[groupIdsSet.size()]));
groupLocalService.addUserGroups(userId, groupIds);
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class TasksEntryLocalServiceImpl method updateTasksEntry.
public TasksEntry updateTasksEntry(long tasksEntryId, String title, int priority, long assigneeUserId, long resolverUserId, int dueDateMonth, int dueDateDay, int dueDateYear, int dueDateHour, int dueDateMinute, boolean addDueDate, int status, ServiceContext serviceContext) throws PortalException, SystemException {
// Tasks entry
Date now = new Date();
TasksEntry tasksEntry = tasksEntryPersistence.findByPrimaryKey(tasksEntryId);
User user = UserLocalServiceUtil.getUserById(tasksEntry.getUserId());
validate(title);
Date dueDate = null;
if (addDueDate) {
dueDate = PortalUtil.getDate(dueDateMonth, dueDateDay, dueDateYear, dueDateHour, dueDateMinute, user.getTimeZone(), TasksEntryDueDateException.class);
}
long oldAssigneeUserId = tasksEntry.getAssigneeUserId();
int oldStatus = tasksEntry.getStatus();
tasksEntry.setModifiedDate(now);
tasksEntry.setTitle(title);
tasksEntry.setPriority(priority);
tasksEntry.setAssigneeUserId(assigneeUserId);
tasksEntry.setDueDate(dueDate);
if (status == TasksEntryConstants.STATUS_RESOLVED) {
tasksEntry.setResolverUserId(resolverUserId);
tasksEntry.setFinishDate(now);
} else {
tasksEntry.setResolverUserId(0);
tasksEntry.setFinishDate(null);
}
tasksEntry.setStatus(status);
tasksEntryPersistence.update(tasksEntry);
// Asset
updateAsset(tasksEntry.getUserId(), tasksEntry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());
// Social
addSocialActivity(status, tasksEntry, serviceContext);
// Notifications
sendNotificationEvent(tasksEntry, oldStatus, oldAssigneeUserId, serviceContext);
return tasksEntry;
}
use of com.liferay.portal.model.User in project liferay-ide by liferay.
the class TasksEntryLocalServiceImpl method addTasksEntry.
public TasksEntry addTasksEntry(long userId, String title, int priority, long assigneeUserId, int dueDateMonth, int dueDateDay, int dueDateYear, int dueDateHour, int dueDateMinute, boolean addDueDate, ServiceContext serviceContext) throws PortalException, SystemException {
// Tasks entry
User user = UserLocalServiceUtil.getUserById(userId);
long groupId = serviceContext.getScopeGroupId();
Date now = new Date();
validate(title);
Date dueDate = null;
if (addDueDate) {
dueDate = PortalUtil.getDate(dueDateMonth, dueDateDay, dueDateYear, dueDateHour, dueDateMinute, user.getTimeZone(), TasksEntryDueDateException.class);
}
long tasksEntryId = CounterLocalServiceUtil.increment();
TasksEntry tasksEntry = tasksEntryPersistence.create(tasksEntryId);
tasksEntry.setGroupId(groupId);
tasksEntry.setCompanyId(user.getCompanyId());
tasksEntry.setUserId(user.getUserId());
tasksEntry.setUserName(user.getFullName());
tasksEntry.setCreateDate(now);
tasksEntry.setModifiedDate(now);
tasksEntry.setTitle(title);
tasksEntry.setPriority(priority);
tasksEntry.setAssigneeUserId(assigneeUserId);
tasksEntry.setDueDate(dueDate);
tasksEntry.setStatus(TasksEntryConstants.STATUS_OPEN);
tasksEntryPersistence.update(tasksEntry);
// Resources
resourceLocalService.addModelResources(tasksEntry, serviceContext);
// Asset
updateAsset(userId, tasksEntry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());
// Social
JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
extraDataJSONObject.put("title", tasksEntry.getTitle());
SocialActivityLocalServiceUtil.addActivity(userId, groupId, TasksEntry.class.getName(), tasksEntryId, TasksActivityKeys.ADD_ENTRY, extraDataJSONObject.toString(), assigneeUserId);
// Notifications
sendNotificationEvent(tasksEntry, TasksEntryConstants.STATUS_ALL, assigneeUserId, serviceContext);
return tasksEntry;
}
Aggregations