use of com.ableneo.liferay.portal.setup.domain.UserAsMember in project liferay-db-setup-core by ableneo.
the class SetupSites method assignMemberUsers.
private static void assignMemberUsers(List<UserAsMember> memberUsers, long companyId, long groupId) {
if (Objects.isNull(memberUsers) || memberUsers.isEmpty()) {
return;
}
for (UserAsMember memberUser : memberUsers) {
User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, memberUser.getScreenName());
if (Objects.isNull(user)) {
LOG.error(String.format("User with screenName %1$s does not exists. Won't be assigned as site member.", memberUser.getScreenName()));
continue;
}
try {
Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
GroupLocalServiceUtil.addUserGroup(user.getUserId(), liferayGroup.getGroupId());
LOG.info(String.format("User %1$s was assigned as member of site %2$s", user.getScreenName(), liferayGroup.getDescriptiveName()));
assignUserMemberRoles(memberUser.getRole(), companyId, liferayGroup, user);
} catch (PortalException e) {
LOG.error(e);
}
}
}
use of com.ableneo.liferay.portal.setup.domain.UserAsMember in project liferay-db-setup-core by ableneo.
the class SetupUserGroups method addUsersToUserGroup.
private static void addUsersToUserGroup(List<UserAsMember> usersAsMember, com.liferay.portal.kernel.model.UserGroup liferayUserGroup) {
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
for (UserAsMember member : usersAsMember) {
User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, member.getScreenName());
if (Objects.isNull(user)) {
LOG.error(String.format("Can not set user %1$s as member of UserGroup. User does not exists...", member.getScreenName()));
continue;
}
UserGroupLocalServiceUtil.addUserUserGroup(user.getUserId(), liferayUserGroup.getUserGroupId());
LOG.info(String.format("User %1$s successfully added as a member to UserGroup %2$s", user.getScreenName(), liferayUserGroup.getName()));
}
}
Aggregations