use of org.mx.error.UserInterfaceException in project main by JohnPeng739.
the class RoleManageResource method roles.
@Path("roles")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<RoleVO>> roles(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<Role> roles = accessor.list(pagination, Role.class);
List<RoleVO> vos = RoleVO.transform(roles);
return new PaginationDataVO<>(pagination, vos);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List roles fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.error.UserInterfaceException in project main by JohnPeng739.
the class UserManageResource method listUsersPagination.
@Path("users")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<UserVO>> listUsersPagination(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<User> users = accessor.list(pagination, User.class);
List<UserVO> userVOs = UserVO.transform(users);
return new PaginationDataVO<>(pagination, userVOs);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List users fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.error.UserInterfaceException in project main by JohnPeng739.
the class TestDatabase method testUserInterface.
@Test
public void testUserInterface() {
GeneralDictAccessor accessor = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
assertNotNull(accessor);
try {
assertEquals(0, accessor.count(User.class));
User user = EntityFactory.createEntity(User.class);
user.setCode("john");
user.setName("John Peng");
user.setAddress("address");
user.setEmail("email");
user.setPostCode("zip");
user.setDesc("description");
User check = accessor.save(user);
assertNotNull(check);
assertNotNull(check.getId());
assertEquals(user.getCode(), check.getCode());
assertEquals(user.getName(), check.getName());
assertEquals(user.getAddress(), check.getAddress());
assertTrue(user.getCreatedTime() > 0);
assertEquals(1, accessor.count(User.class));
check = accessor.getById(user.getId(), User.class);
assertNotNull(check);
assertEquals(user.getCode(), check.getCode());
assertEquals(user.getName(), check.getName());
check = accessor.getByCode(user.getCode(), User.class);
assertNotNull(check);
assertEquals(user.getId(), check.getId());
assertEquals(user.getCode(), check.getCode());
assertEquals(user.getName(), check.getName());
user = accessor.getByCode("john", User.class);
user.setCode("john-1");
user.setName(user.getName() + "(editable)");
user.setDesc("I'm John Peng.");
check = accessor.save(user);
assertNotNull(check);
assertEquals(1, accessor.count(User.class));
assertEquals(user.getId(), check.getId());
assertEquals(user.getCode(), check.getCode());
assertEquals(user.getName(), check.getName());
assertEquals(user.getDesc(), check.getDesc());
check = accessor.getByCode("john", User.class);
assertNotNull(check);
check = accessor.getById(user.getId(), User.class);
assertNotNull(check);
assertEquals(user.getCode(), check.getCode());
check = accessor.getByCode("john-1", User.class);
// 证明修改代码无效
assertNull(check);
user = EntityFactory.createEntity(User.class);
user.setId(DigestUtils.uuid());
user.setCode("josh");
user.setName("Josh Peng");
check = accessor.save(user);
assertNotNull(check);
assertEquals(2, accessor.count(User.class));
check = accessor.getByCode("john", User.class);
assertNotNull(check);
assertTrue(check.isValid());
check = accessor.getByCode("josh", User.class);
assertNotNull(check);
assertTrue(check.isValid());
user = accessor.getByCode("john", User.class);
assertNotNull(user);
check = accessor.remove(user);
assertNotNull(check);
assertEquals(1, accessor.count(User.class));
assertEquals(2, accessor.count(User.class, false));
assertFalse(check.isValid());
List<User> list = ((GeneralAccessor) accessor).find(Arrays.asList(new GeneralAccessor.ConditionTuple("code", "john"), new GeneralAccessor.ConditionTuple("valid", true)), User.class);
assertEquals(0, list.size());
list = ((GeneralAccessor) accessor).find(Arrays.asList(new GeneralAccessor.ConditionTuple("code", "josh"), new GeneralAccessor.ConditionTuple("valid", true)), User.class);
assertEquals(1, list.size());
user = accessor.getByCode("john", User.class);
check = accessor.remove(user, false);
assertNotNull(check);
assertEquals(1, accessor.count(User.class));
check = accessor.getById(user.getId(), User.class);
assertNull(check);
check = accessor.getByCode(user.getCode(), User.class);
assertNull(check);
check = accessor.getByCode("josh", User.class);
assertNotNull(check);
user = accessor.getByCode("josh", User.class);
accessor.remove(user, false);
assertEquals(0, accessor.count(User.class));
} catch (UserInterfaceException ex) {
fail(ex.getMessage());
}
}
use of org.mx.error.UserInterfaceException in project main by JohnPeng739.
the class FfeeFamilyManageResource method createFamily.
@Path("family/create")
@POST
public DataVO<FamilyVO> createFamily(@QueryParam("userCode") String userCode, FamilyManageVO familyManageVO) {
sessionDataStore.setCurrentUserCode(userCode);
try {
Family family = familyManageService.createFamily(familyManageVO.getName(), familyManageVO.getFfeeAccountId(), familyManageVO.getMemberRole());
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(FamilyVO.transform(family));
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
}
}
use of org.mx.error.UserInterfaceException 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);
}
}
Aggregations