Search in sources :

Example 16 with UserInterfaceException

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));
    }
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) Pagination(org.mx.dal.Pagination) RoleVO(org.mx.comps.rbac.rest.vo.RoleVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 17 with UserInterfaceException

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));
    }
}
Also used : Pagination(org.mx.dal.Pagination) User(org.mx.comps.rbac.dal.entity.User) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserVO(org.mx.comps.rbac.rest.vo.UserVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 18 with UserInterfaceException

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());
    }
}
Also used : User(org.mx.test.entity.User) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserInterfaceException(org.mx.error.UserInterfaceException) GeneralAccessor(org.mx.dal.service.GeneralAccessor) Test(org.junit.Test)

Example 19 with UserInterfaceException

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);
    }
}
Also used : DataVO(org.mx.service.rest.vo.DataVO) Family(org.mx.tools.ffee.dal.entity.Family) UserInterfaceException(org.mx.error.UserInterfaceException)

Example 20 with UserInterfaceException

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);
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) UserInterfaceException(org.mx.error.UserInterfaceException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Aggregations

UserInterfaceException (org.mx.error.UserInterfaceException)32 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)30 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)30 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)27 DataVO (org.mx.service.rest.vo.DataVO)24 Pagination (org.mx.dal.Pagination)7 Account (org.mx.comps.rbac.dal.entity.Account)5 User (org.mx.comps.rbac.dal.entity.User)5 UserVO (org.mx.comps.rbac.rest.vo.UserVO)5 Accredit (org.mx.comps.rbac.dal.entity.Accredit)4 Department (org.mx.comps.rbac.dal.entity.Department)4 Privilege (org.mx.comps.rbac.dal.entity.Privilege)4 Role (org.mx.comps.rbac.dal.entity.Role)4 AccreditVO (org.mx.comps.rbac.rest.vo.AccreditVO)4 DepartmentVO (org.mx.comps.rbac.rest.vo.DepartmentVO)4 PrivilegeVO (org.mx.comps.rbac.rest.vo.PrivilegeVO)4 RoleVO (org.mx.comps.rbac.rest.vo.RoleVO)4 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)3 Test (org.junit.Test)1 AccountVO (org.mx.comps.rbac.rest.vo.AccountVO)1