Search in sources :

Example 1 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class TestDepartment method testDepartmentManager.

@Test
public void testDepartmentManager() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    DepartmentManageService departService = context.getBean(DepartmentManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        testInsertDepartment(service, departService);
        testEditDepartment(service, departService);
        assertEquals(3, service.count(User.class));
        assertEquals(3, service.count(Department.class));
        Department depart1 = service.getById(depart1Id, Department.class);
        assertNotNull(depart1);
        assertTrue(depart1.isValid());
        assertNull(depart1.getManager());
        User john = service.getById(TestUser.johnId, User.class);
        assertNotNull(john);
        assertTrue(john.isValid());
        DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), john.getId(), Arrays.asList(), true);
        depart1 = departService.saveDepartment(departInfo);
        assertEquals(3, service.count(Department.class));
        assertNotNull(depart1);
        depart1 = service.getById(depart1Id, Department.class);
        assertNotNull(depart1);
        assertNotNull(depart1.getManager());
        assertEquals(john, depart1.getManager());
        departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), null, Arrays.asList(), true);
        departService.saveDepartment(departInfo);
        depart1 = service.getById(depart1Id, Department.class);
        assertEquals(3, service.count(Department.class));
        assertNull(depart1.getManager());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) Test(org.junit.Test)

Example 2 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class TestDepartment method testInsertDepartment.

public static void testInsertDepartment(GeneralDictAccessor service, DepartmentManageService departService) {
    DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf("depart1", "depart1", "description");
    Department depart1 = departService.saveDepartment(departInfo);
    assertNotNull(depart1);
    assertNotNull(depart1.getId());
    depart1Id = depart1.getId();
    assertEquals(1, service.count(Department.class));
    depart1 = service.getById(depart1Id, Department.class);
    assertNotNull(depart1);
    assertEquals("depart1", depart1.getCode());
    assertEquals("depart1", depart1.getName());
    assertEquals("description", depart1.getDesc());
    depart1 = service.getByCode("depart1", Department.class);
    assertNotNull(depart1);
    assertEquals("depart1", depart1.getCode());
    assertEquals("depart1", depart1.getName());
    assertEquals("description", depart1.getDesc());
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart2", "depart2", "description");
    Department depart2 = departService.saveDepartment(departInfo);
    assertEquals(2, service.count(Department.class));
    assertNotNull(depart2);
    depart2Id = depart2.getId();
    assertNotNull(depart2.getId());
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService)

Example 3 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class TestUser method testUserDepartment.

@Test
public void testUserDepartment() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    UserManageService userService = context.getBean(UserManageService.class);
    assertNotNull(service);
    DepartmentManageService departManageService = context.getBean(DepartmentManageService.class);
    assertNotNull(departManageService);
    try {
        TestDepartment.testInsertDepartment(service, departManageService);
        TestDepartment.testEditDepartment(service, departManageService);
        testInsertUser(service, userService);
        testEditUser(service, userService);
        assertEquals(3, service.count(Department.class));
        assertEquals(3, service.count(User.class));
        User joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNull(joy.getDepartment());
        User josh = service.getById(joshId, User.class);
        assertNotNull(josh);
        assertNull(josh.getDepartment());
        Department depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        UserManageService.UserInfo userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, depart1.getId(), joy.getStation(), joy.isValid(), joy.getDesc());
        userService.saveUser(userInfo);
        joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNotNull(joy.getDepartment());
        assertEquals(depart1, joy.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(1, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(joy)), depart1.getEmployees());
        userInfo = UserManageService.UserInfo.valueOf(josh.getFirstName(), josh.getMiddleName(), josh.getLastName(), josh.getSex(), josh.getId(), 0, depart1.getId(), josh.getStation(), josh.isValid(), josh.getDesc());
        userService.saveUser(userInfo);
        josh = service.getById(joshId, User.class);
        assertNotNull(josh);
        assertNotNull(josh.getDepartment());
        assertEquals(depart1, josh.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(2, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(joy, josh)), depart1.getEmployees());
        userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, null, joy.getStation(), joy.isValid(), joy.getDesc());
        userService.saveUser(userInfo);
        joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNull(joy.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(1, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(josh)), depart1.getEmployees());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 4 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class DepartmentManageResource method deleteDepartment.

@Path("departments/{id}")
@DELETE
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<DepartmentVO> deleteDepartment(@QueryParam("userCode") String userCode, @PathParam("id") String id) {
    sessionDataStore.setCurrentUserCode(userCode);
    try {
        Department department = accessor.remove(id, Department.class);
        DepartmentVO vo = DepartmentVO.transform(department, true);
        sessionDataStore.removeCurrentUserCode();
        return new DataVO<>(vo);
    } catch (UserInterfaceException ex) {
        return new DataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Delete department fail.", ex);
        }
        return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) DataVO(org.mx.service.rest.vo.DataVO) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) DepartmentVO(org.mx.comps.rbac.rest.vo.DepartmentVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Example 5 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class DepartmentManageResource method departments.

@Path("departments")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<DepartmentVO>> departments(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        List<Department> departments = accessor.list(pagination, Department.class);
        List<DepartmentVO> vos = DepartmentVO.transform(departments);
        return new PaginationDataVO<>(pagination, vos);
    } catch (UserInterfaceException ex) {
        return new PaginationDataVO<>(ex);
    } catch (Exception ex) {
        if (logger.isErrorEnabled()) {
            logger.error("List departments fail.", ex);
        }
        return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
    }
}
Also used : Pagination(org.mx.dal.Pagination) Department(org.mx.comps.rbac.dal.entity.Department) PaginationDataVO(org.mx.service.rest.vo.PaginationDataVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) DepartmentVO(org.mx.comps.rbac.rest.vo.DepartmentVO) UserInterfaceException(org.mx.error.UserInterfaceException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) AuthenticateAround(org.mx.comps.jwt.AuthenticateAround)

Aggregations

Department (org.mx.comps.rbac.dal.entity.Department)13 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)6 User (org.mx.comps.rbac.dal.entity.User)4 DepartmentVO (org.mx.comps.rbac.rest.vo.DepartmentVO)4 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)4 UserInterfaceException (org.mx.error.UserInterfaceException)4 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)4 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)3 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)3 DataVO (org.mx.service.rest.vo.DataVO)3 Test (org.junit.Test)2 UserManageService (org.mx.comps.rbac.service.UserManageService)2 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Pagination (org.mx.dal.Pagination)1