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());
}
}
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());
}
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());
}
}
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));
}
}
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));
}
}
Aggregations