use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.
the class PrivilegeManageResource method getPrivilege.
@Path("privileges/{id}")
@GET
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<PrivilegeVO> getPrivilege(@PathParam("id") String id) {
try {
Privilege privilege = accessor.getById(id, Privilege.class);
PrivilegeVO vo = PrivilegeVO.transform(privilege, true);
return new DataVO<>(vo);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Get privilege fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.
the class TestPrivilege method testDeletePrivilege.
private void testDeletePrivilege(GeneralDictAccessor service) {
List<Privilege> ps = service.list(Privilege.class);
int pnum = ps.size();
for (Privilege p : ps) {
service.remove(p);
assertEquals(--pnum, service.count(Privilege.class));
assertEquals(ps.size(), service.count(Privilege.class, false));
}
pnum = ps.size();
for (Privilege p : ps) {
service.remove(p, false);
assertEquals(--pnum, service.count(Privilege.class, false));
}
}
use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.
the class TestPrivilege method testInsertPrivilege.
public static void testInsertPrivilege(GeneralDictAccessor service) {
Privilege p1 = EntityFactory.createEntity(Privilege.class);
p1.setCode("privilege1");
p1.setName("privilege1");
p1.setDesc("desc");
p1 = service.save(p1);
assertEquals(1, service.count(Privilege.class));
assertNotNull(p1);
assertNotNull(p1.getId());
p1Id = p1.getId();
p1 = service.getById(p1Id, Privilege.class);
assertNotNull(p1);
assertEquals("privilege1", p1.getCode());
assertEquals("privilege1", p1.getName());
assertEquals("desc", p1.getDesc());
assertTrue(p1.isValid());
Privilege p2 = EntityFactory.createEntity(Privilege.class);
p2.setCode("privilege2");
p2.setName("privilege2");
p2.setDesc("desc");
service.save(p2);
assertEquals(2, service.count(Privilege.class));
p2 = service.getById(p2.getId(), Privilege.class);
assertNotNull(p2);
p2Id = p2.getId();
assertEquals("privilege2", p2.getCode());
assertEquals("privilege2", p2.getName());
assertEquals("desc", p2.getDesc());
assertTrue(p2.isValid());
}
use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.
the class TestPrivilege method testEditPrivilege.
public static void testEditPrivilege(GeneralDictAccessor service) {
Privilege p3 = EntityFactory.createEntity(Privilege.class);
p3.setCode("privilege3");
p3.setName("privilege3");
service.save(p3);
assertEquals(3, service.count(Privilege.class));
p3 = service.getById(p3.getId(), Privilege.class);
assertNotNull(p3);
p3Id = p3.getId();
assertEquals("privilege3", p3.getCode());
assertEquals("privilege3", p3.getName());
p3.setName("new name");
p3.setValid(false);
service.save(p3);
assertEquals(2, service.count(Privilege.class));
assertEquals(3, service.count(Privilege.class, false));
p3.setName("privilege3");
p3.setValid(true);
service.save(p3);
assertEquals(3, service.count(Privilege.class));
}
use of org.mx.comps.rbac.dal.entity.Privilege in project main by JohnPeng739.
the class RoleManageServiceCommonImpl method saveRole.
/**
* {@inheritDoc}
*
* @see RoleManageService#saveRole(RoleInfo)
*/
@Override
public Role saveRole(RoleInfo roleInfo) {
if (roleInfo == null) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
String id = roleInfo.getRoleId();
Role role;
if (!StringUtils.isBlank(id)) {
role = accessor.getById(id, Role.class);
if (role == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
}
} else {
role = EntityFactory.createEntity(Role.class);
}
role.setCode(roleInfo.getCode());
role.setName(roleInfo.getName());
role.setDesc(roleInfo.getDesc());
if (role.getAccounts() != null && !role.getAccounts().isEmpty()) {
role.getAccounts().clear();
}
if (roleInfo.getAccountIds() != null && !roleInfo.getAccountIds().isEmpty()) {
for (String accountId : roleInfo.getAccountIds()) {
Account account = accessor.getById(accountId, Account.class);
if (account == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
}
role.getAccounts().add(account);
}
}
if (role.getPrivileges() != null && !role.getPrivileges().isEmpty()) {
role.getPrivileges().clear();
for (String privilegeId : roleInfo.getPrivilegeIds()) {
Privilege privilege = accessor.getById(privilegeId, Privilege.class);
if (privilege == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.PRIVILEGE_NOT_FOUND);
}
role.getPrivileges().add(privilege);
}
}
role.setValid(roleInfo.isValid());
role = this.save(role);
if (operateLogService != null) {
operateLogService.writeLog(String.format("保存角色[code=%s, name=%s]信息成功。", roleInfo.getCode(), roleInfo.getName()));
}
return role;
}
Aggregations