use of com.ableneo.liferay.portal.setup.domain.Role in project liferay-db-setup-core by ableneo.
the class SetupSites method assignUserMemberRoles.
private static void assignUserMemberRoles(List<Role> membershipRoles, long companyId, Group liferayGroup, User liferayUser) {
if (Objects.isNull(membershipRoles) || membershipRoles.isEmpty()) {
return;
}
for (Role membershipRole : membershipRoles) {
try {
com.liferay.portal.kernel.model.Role liferayRole = RoleLocalServiceUtil.getRole(companyId, membershipRole.getName());
UserGroupRoleLocalServiceUtil.addUserGroupRoles(liferayUser.getUserId(), liferayGroup.getGroupId(), new long[] { liferayRole.getRoleId() });
StringBuilder sb = new StringBuilder("Role ").append(liferayRole.getDescriptiveName()).append(" assigned to User ").append(liferayUser.getScreenName()).append(" for site ").append(liferayGroup.getDescriptiveName());
LOG.info(sb.toString());
} catch (PortalException e) {
LOG.error(String.format("Can not add role with name%1$s does not exists. Will not be assigned.", membershipRole.getName()));
}
}
}
use of com.ableneo.liferay.portal.setup.domain.Role in project liferay-db-setup-core by ableneo.
the class SetupSites method assignMemberRoles.
private static void assignMemberRoles(List<Role> membershipRoles, long companyId, long groupId) {
if (Objects.isNull(membershipRoles) || membershipRoles.isEmpty()) {
return;
}
Set<String> roles = new HashSet<String>();
for (Role membershipRole : membershipRoles) {
try {
com.liferay.portal.kernel.model.Role liferayRole = RoleLocalServiceUtil.getRole(companyId, membershipRole.getName());
roles.add(String.valueOf(liferayRole.getRoleId()));
} catch (PortalException e) {
LOG.error(String.format("Can not get role with name%1$s does not exists. Will not be assigned.", membershipRole.getName()));
}
}
if (roles.isEmpty()) {
LOG.info("NO new roles to be assigned to site " + groupId);
return;
}
try {
Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
UnicodeProperties siteGroupProps = liferayGroup.getTypeSettingsProperties();
if (siteGroupProps == null) {
siteGroupProps = new UnicodeProperties();
}
String roleIds = siteGroupProps.getProperty(UNIPARAM_DEFAULT_SITE_ROLE_IDS);
if (roleIds != null && roleIds.length() > 1) {
String[] roleIdArr = roleIds.split("[,;]+");
roles.addAll(Arrays.asList(roleIdArr));
}
roleIds = StringUtil.merge(roles, ",");
siteGroupProps.setProperty(UNIPARAM_DEFAULT_SITE_ROLE_IDS, roleIds);
liferayGroup.setTypeSettingsProperties(siteGroupProps);
GroupLocalServiceUtil.updateGroup(liferayGroup);
StringBuilder sb = new StringBuilder("Roles ").append(roleIds).append(" assigned to site-group ").append(liferayGroup.getDescriptiveName());
LOG.info(sb.toString());
} catch (Exception e) {
LOG.error("Can not set roles to site-group (" + roles + ")=>" + groupId, e);
}
}
use of com.ableneo.liferay.portal.setup.domain.Role in project liferay-db-setup-core by ableneo.
the class SetupUserGroups method addRolesToUserGroup.
private static void addRolesToUserGroup(final UserGroup userGroup, final com.liferay.portal.kernel.model.UserGroup liferayUserGroup) {
try {
for (Role role : userGroup.getRole()) {
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
com.liferay.portal.kernel.model.Role liferayRole = RoleLocalServiceUtil.getRole(companyId, role.getName());
String roleType = role.getType();
switch(roleType) {
case RoleConstants.TYPE_REGULAR_LABEL:
case "portal":
GroupLocalServiceUtil.addRoleGroup(liferayRole.getRoleId(), liferayUserGroup.getGroupId());
LOG.info(String.format("Adding role %1$s to userGroup %2$s", liferayRole.getDescriptiveName(), liferayUserGroup.getName()));
break;
case "site":
case "organization":
LOG.error("Adding site or organization roles to UserGroup is not supported. Bind userGroups to Site Roles within the Site elemennt.");
break;
default:
LOG.error(String.format("unknown role type %1$s", roleType));
break;
}
}
} catch (PortalException | SystemException e) {
LOG.error(String.format("Error in adding roles to userGroup %1$s", userGroup.getName()), e);
}
}
use of com.ableneo.liferay.portal.setup.domain.Role in project liferay-db-setup-core by ableneo.
the class SetupSites method assignGroupMemberRoles.
private static void assignGroupMemberRoles(List<Role> membershipRoles, long companyId, Group liferayGroup, UserGroup liferayUserGroup) {
if (Objects.isNull(membershipRoles) || membershipRoles.isEmpty()) {
return;
}
for (Role membershipRole : membershipRoles) {
try {
com.liferay.portal.kernel.model.Role liferayRole = RoleLocalServiceUtil.getRole(companyId, membershipRole.getName());
UserGroupGroupRoleLocalServiceUtil.addUserGroupGroupRoles(liferayUserGroup.getUserGroupId(), liferayGroup.getGroupId(), new long[] { liferayRole.getRoleId() });
StringBuilder sb = new StringBuilder("Role[").append(liferayRole.getTypeLabel()).append(//
"] ").append(//
liferayRole.getDescriptiveName()).append(" assigned to UserGroup ").append(//
liferayUserGroup.getName()).append(" for site ").append(//
liferayGroup.getDescriptiveName());
LOG.info(sb.toString());
} catch (PortalException e) {
LOG.error(String.format("Can not add role with name%1$s does not exists. Will not be assigned.", membershipRole.getName()));
}
}
}
use of com.ableneo.liferay.portal.setup.domain.Role in project liferay-db-setup-core by ableneo.
the class SetupPermissions method getActionsPerRole.
/**
* @param resource
* @return mapping of role name to action ids for the resource
*/
private static Map<String, Set<String>> getActionsPerRole(ResourcePermissions.Resource resource) {
Map<String, Set<String>> result = new HashMap<>();
for (ResourcePermissions.Resource.ActionId actionId : resource.getActionId()) {
for (Role role : actionId.getRole()) {
final String roleName = role.getName();
result.computeIfAbsent(roleName, s -> new HashSet<>()).add(actionId.getName());
}
}
return result;
}
Aggregations