use of org.mx.comps.rbac.dal.entity.Role 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;
}
use of org.mx.comps.rbac.dal.entity.Role in project main by JohnPeng739.
the class AccreditManageServiceImpl method hasSameAccredit.
/**
* {@inheritDoc}
*
* @see AccreditManageServiceCommonImpl#hasSameAccredit(AccreditInfo)
*/
@Override
protected boolean hasSameAccredit(AccreditInfo accreditInfo) {
List<GeneralAccessor.ConditionTuple> conditions = new ArrayList<>();
conditions.add(new GeneralAccessor.ConditionTuple("src.id", accreditInfo.getSrcAccountId()));
conditions.add(new GeneralAccessor.ConditionTuple("tar.id", accreditInfo.getTarAccountId()));
conditions.add(new GeneralAccessor.ConditionTuple("valid", true));
List<Accredit> list = accessor.find(conditions, Accredit.class);
List<Accredit> accredits = new ArrayList<>();
if (list != null && !list.isEmpty()) {
list.forEach(accredit -> {
if (!accredit.isClosed()) {
accredits.add(accredit);
}
});
}
if (accredits.isEmpty()) {
return false;
}
for (Accredit accredit : accredits) {
if (!accredit.isClosed()) {
for (String roleId : accreditInfo.getRoleIds()) {
boolean found = false;
for (Role role : accredit.getRoles()) {
if (roleId.equals(role.getId())) {
found = true;
}
}
if (!found) {
return false;
}
}
}
}
return true;
}
Aggregations