本文整理汇总了Java中com.liferay.portal.kernel.model.Role类的典型用法代码示例。如果您正苦于以下问题:Java Role类的具体用法?Java Role怎么用?Java Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Role类属于com.liferay.portal.kernel.model包,在下文中一共展示了Role类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFolderPermissions
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
public static void setFolderPermissions(Folder folder) throws Exception{
ResourcePermission resourcePermission = null;
final Role guestMemberRole = RoleLocalServiceUtil.getRole(folder.getCompanyId(), RoleConstants.GUEST);
final Role siteMemberRole = RoleLocalServiceUtil.getRole(folder.getCompanyId(), RoleConstants.SITE_MEMBER);
ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(DLFolder.class.getName(), ActionKeys.VIEW);
String[] actionIdsGuest = new String[] { ActionKeys.VIEW, ActionKeys.ACCESS };
String[] actionIds = new String[] { ActionKeys.VIEW, ActionKeys.ACCESS, ActionKeys.SUBSCRIBE, ActionKeys.ADD_DOCUMENT, ActionKeys.UPDATE, ActionKeys.ADD_SHORTCUT, ActionKeys.ADD_SUBFOLDER, ActionKeys.PERMISSIONS, ActionKeys.DELETE };
try{
ResourcePermissionLocalServiceUtil.setResourcePermissions(folder.getCompanyId(),
DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(folder.getPrimaryKey()), guestMemberRole.getRoleId(), actionIdsGuest);
ResourcePermissionLocalServiceUtil.setResourcePermissions(folder.getCompanyId(),
DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(folder.getPrimaryKey()), siteMemberRole.getRoleId(), actionIds);
} catch (NoSuchResourcePermissionException e){
resourcePermission = ResourcePermissionLocalServiceUtil
.createResourcePermission(CounterLocalServiceUtil.increment());
resourcePermission.setCompanyId(folder.getCompanyId());
resourcePermission.setName(DLFolder.class.getName());
resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
resourcePermission.setPrimKey(String.valueOf(folder.getPrimaryKey()));
resourcePermission.setRoleId(guestMemberRole.getRoleId());
resourcePermission.setActionIds(resourceAction.getBitwiseValue());// (ActionKeys.VIEW);
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
}
}
示例2: getRegularRoleIds
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
/**
* Fetch regular roles
*
* @param roleIds
* @return
* @throws PortalException
*/
public long[] getRegularRoleIds(long[] roleIds) throws PortalException {
Map<Integer, List<Role>> roles = _commonUtil.filterRoles(roleIds);
List<Role> regularRoles = roles.get(RoleConstants.TYPE_REGULAR);
if (Validator.isNull(regularRoles) || regularRoles.size() == 0) {
return null;
}
if (_log.isDebugEnabled()) {
String regularids = regularRoles.stream().map(r -> String.valueOf(r.getRoleId()))
.collect(Collectors.joining(","));
_log.debug("Regular ids : " + regularids);
}
return regularRoles.stream().mapToLong(Role::getRoleId).toArray();
}
示例3: addRoleMultiSelect
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
public void addRoleMultiSelect(String name) throws SystemException {
List<Role> roles = RoleLocalServiceUtil.getRoles(
QueryUtil.ALL_POS, QueryUtil.ALL_POS);
List<KeyValuePair> values = new ArrayList<KeyValuePair>(roles.size());
for (Role role : roles) {
if (role.getType() == RoleConstants.TYPE_REGULAR) {
long roleId = role.getRoleId();
String roleName = role.getName();
if (Validator.isNull(roleId) || Validator.isNull(roleName)) {
continue;
}
values.add(new KeyValuePair(roleName, String.valueOf(roleId)));
}
}
addMultiSelectList(name, values);
}
示例4: getAdminUser
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
/**
* Returns Liferay user, that has Administrator role assigned.
*
* @param companyId company ID
* @return Liferay {@link com.mimacom.liferay.portal.setup.domain.User}
* instance, if no user is found, returns null
* @throws Exception if cannot obtain permission checker
*/
private static User getAdminUser(final long companyId) throws Exception {
try {
Role adminRole = RoleLocalServiceUtil.getRole(companyId, ADMIN_ROLE_NAME);
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
if (adminUsers == null || adminUsers.isEmpty()) {
return null;
}
return adminUsers.get(0);
} catch (PortalException | SystemException e) {
throw new Exception("Cannot obtain Liferay role for role name: " + ADMIN_ROLE_NAME, e);
}
}
示例5: addRole
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
private static void addRole(final com.mimacom.liferay.portal.setup.domain.Role role) {
Map<Locale, String> localeTitleMap = new HashMap<>();
localeTitleMap.put(Locale.ENGLISH, role.getName());
try {
int roleType = RoleConstants.TYPE_REGULAR;
if (role.getType() != null) {
if (role.getType().equals("site")) {
roleType = RoleConstants.TYPE_SITE;
} else if (role.getType().equals("organization")) {
roleType = RoleConstants.TYPE_ORGANIZATION;
}
}
long defaultUserId = UserLocalServiceUtil.getDefaultUserId(COMPANY_ID);
RoleLocalServiceUtil.addRole(defaultUserId, null, 0, role.getName(), localeTitleMap,
null, roleType, null, null);
LOG.info("Setup: Role " + role.getName() + " does not exist, adding...");
} catch (PortalException | SystemException e) {
LOG.error("error while adding up roles", e);
}
}
示例6: _getRoleName
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
private static String _getRoleName(long roleId) {
String roleName = StringPool.BLANK;
try {
Role role = RoleLocalServiceUtil.getRole(roleId);
roleName = role.getName();
} catch (Exception e) {
}
return roleName;
}
示例7: getRoleApplicant
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
public static Role getRoleApplicant(long companyId, String roleName) {
Role roleDefault = null;
try {
roleDefault = RoleLocalServiceUtil.getRole(companyId, ServiceProps.APPLICANT_ROLE_NAME);
} catch (Exception e) {
roleDefault = RoleLocalServiceUtil.createRole(CounterLocalServiceUtil.increment(Role.class.getName()));
roleDefault.setName(ServiceProps.APPLICANT_ROLE_NAME);
}
return roleDefault;
}
示例8: doGetDocument
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
@Override
protected Document doGetDocument(ResourceRole resourceRole) throws Exception {
Document document = getBaseModelDocument(CLASS_NAME, resourceRole);
document.addKeywordSortable(Field.COMPANY_ID, String.valueOf(resourceRole.getCompanyId()));
document.addDateSortable(Field.MODIFIED_DATE, resourceRole.getModifiedDate());
document.addKeywordSortable(Field.USER_ID, String.valueOf(resourceRole.getUserId()));
document.addKeywordSortable(Field.USER_NAME, String.valueOf(resourceRole.getUserName()));
document.addNumberSortable(ResourceRoleTerm.GROUP_ID, resourceRole.getGroupId());
document.addNumberSortable(ResourceRoleTerm.RESOURCEROLE_ID, resourceRole.getResourceRoleId());
document.addTextSortable(ResourceRoleTerm.CLASS_NAME, resourceRole.getClassName());
document.addTextSortable(ResourceRoleTerm.CLASS_PK, resourceRole.getClassPK());
document.addNumberSortable(ResourceRoleTerm.ROLE_ID, resourceRole.getRoleId());
document.addTextSortable("selected", Boolean.TRUE.toString());
Role role = RoleLocalServiceUtil.fetchRole(resourceRole.getRoleId());
String roleName = StringPool.BLANK;
if (Validator.isNotNull(role)) {
roleName = role.getName();
}
document.addTextSortable(ResourceRoleTerm.ROLE_NAME, roleName);
return document;
}
示例9: setFilePermissions
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
public static void setFilePermissions(FileEntry fileEntry) throws Exception{
ResourcePermission resourcePermission = null;
final Role guestMemberRole = RoleLocalServiceUtil.getRole(fileEntry.getCompanyId(), RoleConstants.GUEST);
ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(DLFileEntry.class.getName(), ActionKeys.VIEW);
String[] actionIdsGuest = new String[] { ActionKeys.VIEW, ActionKeys.ACCESS };
try{
resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission(fileEntry.getCompanyId(),
DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry
.getPrimaryKey()), guestMemberRole.getRoleId());
ResourcePermissionLocalServiceUtil.setResourcePermissions(fileEntry.getCompanyId(),
DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry.getPrimaryKey()), guestMemberRole.getRoleId(), actionIdsGuest);
// if (Validator.isNotNull(resourcePermission)){
// resourcePermission.setActionIds(resourceAction.getBitwiseValue());
// ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
// }
} catch (NoSuchResourcePermissionException e){
resourcePermission = ResourcePermissionLocalServiceUtil
.createResourcePermission(CounterLocalServiceUtil.increment());
resourcePermission.setCompanyId(fileEntry.getCompanyId());
resourcePermission.setName(DLFileEntry.class.getName());
resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
resourcePermission.setPrimKey(String.valueOf(fileEntry.getPrimaryKey()));
resourcePermission.setRoleId(guestMemberRole.getRoleId());
resourcePermission.setActionIds(resourceAction.getBitwiseValue());// (ActionKeys.VIEW);
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
}
}
示例10: hasResource
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
@Override
public boolean hasResource(ServiceContext context, String name, String actionId) {
boolean hasPermission = false;
List<Role> roles = RoleLocalServiceUtil.getUserRoles(context.getUserId());
try {
for (Role role : roles) {
if (role.getName().equals("Administrator")) {
hasPermission = true;
break;
}
hasPermission = ResourcePermissionLocalServiceUtil.hasResourcePermission(context.getCompanyId(), name,
ResourceConstants.SCOPE_INDIVIDUAL, Long.toString(role.getRoleId()), role.getRoleId(),
actionId);
if (hasPermission) {
break;
}
}
} catch (Exception e) {
_log.error(e);
}
return hasPermission;
}
示例11: userHasResource
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
@Override
public boolean userHasResource(
ServiceContext context, String name, String actionId) {
boolean hasPermission = false;
List<Role> roles =
RoleLocalServiceUtil.getUserRoles(context.getUserId());
try {
for (Role role : roles) {
hasPermission =
ResourcePermissionLocalServiceUtil.hasResourcePermission(
context.getCompanyId(), name,
ResourceConstants.SCOPE_INDIVIDUAL,
Long.toString(role.getRoleId()), role.getRoleId(),
actionId);
if (hasPermission) {
break;
}
}
}
catch (Exception e) {
_log.error(e);
}
return hasPermission;
}
示例12: setOrgRoles
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
/**
* Set org roles
*
* Filtering only organization roles out from role ids and asign
* organization roles to a user.
*
* @param userId
* @param organizationIds
* @param roleIds
* @throws PortalException
*/
public void setOrgRoles(long userId, long[] organizationIds, long[] roleIds) throws PortalException {
Map<Integer, List<Role>> roles = _commonUtil.filterRoles(roleIds);
List<Role> orgRoles = roles.get(RoleConstants.TYPE_ORGANIZATION);
if (Validator.isNull(orgRoles) || orgRoles.size() == 0) {
return;
}
long[] orgIds = orgRoles.stream().mapToLong(Role::getRoleId).toArray();
if (_log.isDebugEnabled()) {
String orgids = orgRoles.stream().map(o -> String.valueOf(o.getPrimaryKey()))
.collect(Collectors.joining(","));
_log.debug("Organization ids : " + orgids);
}
if (0 == orgIds.length) {
_log.debug("Organization didn't exist in the ids. exit");
return;
}
List<Organization> orgs = _organizationLocalService.getOrganizations(organizationIds);
long[] orgGroupdIds = orgs.stream().mapToLong(Organization::getGroupId).toArray();
for (long orgGroupdId : orgGroupdIds) {
_userGroupRoleLocalService.addUserGroupRoles(userId, orgGroupdId, orgIds);
}
}
示例13: setSiteRoles
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
/**
* Set site roles
*
* Filtering only site roles out from role ids and asign site roles to a
* user.
*
* @param userId
* @param groupIds
* @param roleIds
* @throws PortalException
*/
public void setSiteRoles(long userId, long[] groupIds, long[] roleIds) throws PortalException {
Map<Integer, List<Role>> roles = _commonUtil.filterRoles(roleIds);
List<Role> siteRoles = roles.get(RoleConstants.TYPE_SITE);
if (Validator.isNull(siteRoles) || siteRoles.size() == 0) {
return;
}
long[] siteIds = siteRoles.stream().mapToLong(Role::getRoleId).toArray();
if (_log.isDebugEnabled()) {
String siteids = siteRoles.stream().map(s -> String.valueOf(s.getRoleId()))
.collect(Collectors.joining(","));
_log.debug("Site ids : " + siteids);
}
if (0 == siteIds.length) {
_log.debug("Site roles didn't exist in the ids. exit");
return;
}
for (long groupId : groupIds) {
_userGroupRoleLocalService.addUserGroupRoles(userId, groupId, siteIds);
}
}
示例14: deleteObjects
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
private static void deleteObjects(final List<ObjectsToBeDeleted> objectsToBeDeleted) {
for (ObjectsToBeDeleted otbd : objectsToBeDeleted) {
if (otbd.getRoles() != null) {
List<com.mimacom.liferay.portal.setup.domain.Role> roles = otbd.getRoles()
.getRole();
SetupRoles.deleteRoles(roles, otbd.getDeleteMethod());
}
if (otbd.getUsers() != null) {
List<com.mimacom.liferay.portal.setup.domain.User> users = otbd.getUsers()
.getUser();
SetupUsers.deleteUsers(users, otbd.getDeleteMethod());
}
if (otbd.getOrganizations() != null) {
List<Organization> organizations = otbd
.getOrganizations().getOrganization();
SetupOrganizations.deleteOrganization(organizations, otbd.getDeleteMethod());
}
if (otbd.getCustomFields() != null) {
List<CustomFields.Field> customFields = otbd.getCustomFields().getField();
SetupCustomFields.deleteCustomFields(customFields, otbd.getDeleteMethod());
}
}
}
示例15: convertRoleListToHashMap
import com.liferay.portal.kernel.model.Role; //导入依赖的package包/类
private static Map<String, com.mimacom.liferay.portal.setup.domain.Role> convertRoleListToHashMap(
final List<com.mimacom.liferay.portal.setup.domain.Role> objects) {
HashMap<String, com.mimacom.liferay.portal.setup.domain.Role> map = new HashMap<>();
for (com.mimacom.liferay.portal.setup.domain.Role role : objects) {
map.put(role.getName(), role);
}
return map;
}