Search in sources :

Example 1 with UserGroupAsMember

use of com.ableneo.liferay.portal.setup.domain.UserGroupAsMember in project liferay-db-setup-core by ableneo.

the class SetupSites method assignMemberGroups.

private static void assignMemberGroups(List<UserGroupAsMember> memberGroups, long companyId, long groupId) {
    if (Objects.isNull(memberGroups) || memberGroups.isEmpty()) {
        return;
    }
    for (UserGroupAsMember memberGroup : memberGroups) {
        try {
            UserGroup liferayUserGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, memberGroup.getUserGroupName());
            Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
            GroupLocalServiceUtil.addUserGroupGroup(liferayUserGroup.getUserGroupId(), liferayGroup);
            LOG.info(String.format("UserGroup %1$s was assigned as site member to %2$s", liferayUserGroup.getName(), liferayGroup.getDescriptiveName()));
            assignGroupMemberRoles(memberGroup.getRole(), companyId, liferayGroup, liferayUserGroup);
        } catch (PortalException e) {
            LOG.error(String.format("Cannot find UserGroup with name: %1$s. Group won't be assigned to site.", memberGroup.getUserGroupName()), e);
        }
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) UserGroup(com.liferay.portal.kernel.model.UserGroup) PortalException(com.liferay.portal.kernel.exception.PortalException) UserGroupAsMember(com.ableneo.liferay.portal.setup.domain.UserGroupAsMember) UserGroup(com.liferay.portal.kernel.model.UserGroup)

Aggregations

UserGroupAsMember (com.ableneo.liferay.portal.setup.domain.UserGroupAsMember)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 Group (com.liferay.portal.kernel.model.Group)1 UserGroup (com.liferay.portal.kernel.model.UserGroup)1