Search in sources :

Example 11 with Privilege

use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.

the class RoleManageServiceImpl method save.

/**
 * {@inheritDoc}
 *
 * @see RoleManageServiceCommonImpl#save(Role)
 */
@Override
public Role save(Role role) {
    Set<Privilege> oldPrivileges = new HashSet<>();
    Set<Account> oldAccounts = new HashSet<>();
    if (!StringUtils.isBlank(role.getId())) {
        Role checked = accessor.getById(role.getId(), Role.class);
        oldPrivileges.addAll(checked.getPrivileges());
        oldAccounts.addAll(checked.getAccounts());
    }
    accessor.save(role, false);
    Set<Privilege> privileges = role.getPrivileges();
    Set<Account> accounts = role.getAccounts();
    for (Privilege privilege : privileges) {
        if (oldPrivileges.contains(privilege)) {
            oldPrivileges.remove(privilege);
            continue;
        } else {
            privilege.getRoles().add(role);
            accessor.save(privilege, false);
        }
    }
    for (Privilege privilege : oldPrivileges) {
        privilege.getRoles().remove(role);
        accessor.save(privilege, false);
    }
    for (Account account : accounts) {
        if (oldAccounts.contains(account)) {
            oldAccounts.remove(account);
            continue;
        } else {
            account.getRoles().add(role);
            accessor.save(account, false);
        }
    }
    for (Account account : oldAccounts) {
        account.getRoles().remove(role);
        accessor.save(account, false);
    }
    return role;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Account(org.mx.comps.rbac.dal.entity.Account) Privilege(org.mx.comps.rbac.dal.entity.Privilege) HashSet(java.util.HashSet)

Aggregations

Privilege (org.mx.comps.rbac.dal.entity.Privilege)11 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)5 Role (org.mx.comps.rbac.dal.entity.Role)4 PrivilegeVO (org.mx.comps.rbac.rest.vo.PrivilegeVO)4 UserInterfaceException (org.mx.error.UserInterfaceException)4 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)4 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)3 DataVO (org.mx.service.rest.vo.DataVO)3 Test (org.junit.Test)2 Account (org.mx.comps.rbac.dal.entity.Account)2 RoleManageService (org.mx.comps.rbac.service.RoleManageService)2 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)2 HashSet (java.util.HashSet)1 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)1 Pagination (org.mx.dal.Pagination)1