use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.
the class AccountManageResource method changePersonal.
@Path("accounts/{id}/personal/change")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> changePersonal(@PathParam("id") String id, @QueryParam("userCode") String userCode, ChangePersonalVO vo) {
sessionDataStore.setCurrentUserCode(userCode);
if (vo == null) {
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM));
}
try {
Account account = accountManageService.changePersonal(vo.getAccountPersonalInfo());
AccountVO accountVO = AccountVO.transform(account, true);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(accountVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
}
}
use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.
the class UserManageResource method allocateAccount.
@Path("users/{userId}/allocate")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccountVO> allocateAccount(@QueryParam("userCode") String userCode, @PathParam("userId") String userId, AccountInfoVO accountInfoVO) {
sessionDataStore.setCurrentUserCode(userCode);
try {
accountInfoVO.setOwnerId(userId);
Account account = userManageService.allocateAccount(accountInfoVO.getAccountInfo());
AccountVO accountVO = AccountVO.transform(account, true);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(accountVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Allocate account fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.
the class TestAccount method testAccountRoles.
@Test
public void testAccountRoles() {
GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
assertNotNull(service);
AccountManageService accountService = context.getBean(AccountManageService.class);
assertNotNull(service);
UserManageService userManageService = context.getBean(UserManageService.class);
assertNotNull(userManageService);
RoleManageService roleManageService = context.getBean(RoleManageService.class);
assertNotNull(roleManageService);
try {
TestUser.testInsertUser(service, userManageService);
TestUser.testEditUser(service, userManageService);
assertEquals(3, service.count(User.class));
TestRole.testInsertRole(service, roleManageService);
TestRole.testEditRole(service, roleManageService);
testInsertAccount(service, accountService);
testEditAccount(service, accountService);
assertEquals(3, service.count(Role.class));
assertEquals(3, service.count(Account.class));
Account account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertTrue(account1.getRoles().isEmpty());
Role role1 = service.getById(TestRole.role1Id, Role.class);
Role role2 = service.getById(TestRole.role2Id, Role.class);
Role role3 = service.getById(TestRole.role3Id, Role.class);
assertNotNull(role1);
assertNotNull(role2);
assertNotNull(role3);
AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(role1.getId(), role2.getId(), role3.getId()), account1.isValid());
accountService.saveAccount(accountInfo);
assertEquals(3, service.count(Account.class));
account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertEquals(3, account1.getRoles().size());
assertEquals(new HashSet<>(Arrays.asList(role1, role2, role3)), account1.getRoles());
accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(role1.getId(), role3.getId()), account1.isValid());
accountService.saveAccount(accountInfo);
assertEquals(3, service.count(Account.class));
account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertEquals(2, account1.getRoles().size());
assertEquals(new HashSet<>(Arrays.asList(role1, role3)), account1.getRoles());
accountInfo = AccountManageService.AccountInfo.valueOf(account1.getCode(), "", account1.getDesc(), account1.getId(), TestUser.johnId, Arrays.asList(), account1.isValid());
accountService.saveAccount(accountInfo);
account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertTrue(account1.getRoles().isEmpty());
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.
the class TestAccount method testDeleteAccount.
private void testDeleteAccount(GeneralDictAccessor service) {
List<Account> accounts = service.list(Account.class);
int accountNum = accounts.size();
for (Account account : accounts) {
service.remove(account);
assertEquals(--accountNum, service.count(Account.class, true));
assertEquals(accounts.size(), service.count(Account.class, false));
}
accountNum = accounts.size();
for (Account account : accounts) {
service.remove(account, false);
assertEquals(0, service.count(Account.class, true));
assertEquals(--accountNum, service.count(Account.class, false));
}
}
use of org.mx.comps.rbac.dal.entity.Account in project main by JohnPeng739.
the class TestAccount method testInsertAccount.
public static void testInsertAccount(GeneralDictAccessor service, AccountManageService accountService) throws NoSuchAlgorithmException {
User john = service.getById(TestUser.johnId, User.class);
assertNotNull(john);
AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf("account1", "password", "description account.", "", TestUser.johnId, Arrays.asList(), true);
Account account1 = accountService.saveAccount(accountInfo);
assertEquals(1, service.count(Account.class));
assertNotNull(account1);
assertNotNull(account1.getId());
account1Id = account1.getId();
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
assertTrue(account1.isValid());
assertTrue(account1.getCreatedTime() > 0);
assertTrue(account1.getUpdatedTime() > 0);
account1 = service.getById(account1Id, Account.class);
assertNotNull(account1);
assertNotNull(account1.getId());
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
account1 = service.getByCode(account1.getCode(), Account.class);
assertNotNull(account1);
assertNotNull(account1.getId());
assertEquals("description account.", account1.getDesc());
assertEquals("account1", account1.getCode());
assertEquals(john.getFullName(), account1.getName());
assertEquals(DigestUtils.md5("password"), account1.getPassword());
assertEquals("admin", account1.getOperator());
assertEquals(john, account1.getOwner());
assertTrue(account1.isValid());
accountInfo = AccountManageService.AccountInfo.valueOf("account2", "", "description account.", "", TestUser.johnId, Arrays.asList(), true);
Account account2 = accountService.saveAccount(accountInfo);
assertEquals(2, service.count(Account.class));
assertNotNull(account2);
assertNotNull(account2.getId());
account2Id = account2.getId();
assertEquals("account2", account2.getCode());
assertEquals(DigestUtils.md5("ds110119"), account2.getPassword());
assertEquals(john.getFullName(), account2.getName());
assertEquals(john, account2.getOwner());
assertTrue(account2.isValid());
}
Aggregations