use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.
the class DepartmentManageResource method saveDepartment.
private DataVO<DepartmentVO> saveDepartment(DepartmentInfoVO departmentInfoVO) {
try {
Department department = departmentManageService.saveDepartment(departmentInfoVO.getDepartInfo());
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("Save 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 UserManageServiceCommonImpl method saveUser.
/**
* {@inheritDoc}
*
* @see UserManageService#saveUser(UserInfo)
*/
@Override
public User saveUser(UserInfo userInfo) {
if (userInfo == null) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
String userId = userInfo.getUserId();
User user;
if (!StringUtils.isBlank(userId)) {
user = accessor.getById(userId, User.class);
if (user == null) {
if (logger.isErrorEnabled()) {
logger.error(String.format("The User entity[%s] not found.", userId));
}
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
}
} else {
user = EntityFactory.createEntity(User.class);
}
if (!StringUtils.isBlank(userInfo.getDepartId())) {
Department depart = accessor.getById(userInfo.getDepartId(), Department.class);
if (depart == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.DEPARTMENT_NOT_FOUND);
}
user.setDepartment(depart);
} else {
user.setDepartment(null);
}
long birthday = userInfo.getBirthday();
if (birthday > 0) {
user.setBirthday(new Date(birthday));
}
user.setDesc(userInfo.getDesc());
user.setFirstName(userInfo.getFirstName());
user.setMiddleName(userInfo.getMiddleName());
user.setLastName(userInfo.getLastName());
user.setSex(userInfo.getSex());
user.setStation(userInfo.getStation());
user.setValid(userInfo.isValid());
user = this.save(user);
if (operateLogService != null) {
operateLogService.writeLog(String.format("保存用户[name=%s]信息成功。", user.getFullName()));
}
return user;
}
use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.
the class UserManageServiceImpl method save.
/**
* {@inheritDoc}
* @see UserManageServiceCommonImpl#save(User)
*/
@Override
protected User save(User user) {
Department oldDepart = null;
if (!StringUtil.isBlank(user.getId())) {
oldDepart = accessor.getById(user.getId(), User.class).getDepartment();
}
user = accessor.save(user, false);
Department depart = user.getDepartment();
if (oldDepart != null && !oldDepart.equals(depart)) {
// 与原有的部门不同,因此需要删除原有的部门和用户关系
oldDepart.getEmployees().remove(user);
accessor.save(oldDepart, false);
}
if (depart != null && !depart.equals(oldDepart)) {
// 新设置了部门
depart.getEmployees().add(user);
accessor.save(depart, false);
}
return user;
}
use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.
the class DepartmentManageResource method getDepartment.
@Path("departments/{id}")
@GET
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<DepartmentVO> getDepartment(@PathParam("id") String id) {
try {
Department department = accessor.getById(id, Department.class);
DepartmentVO vo = DepartmentVO.transform(department, true);
return new DataVO<>(vo);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Get 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 TestDepartment method testDeleteDepartment.
private void testDeleteDepartment(GeneralDictAccessor service) {
List<Department> departs = service.list(Department.class);
int departNum = departs.size();
for (Department depart : departs) {
service.remove(depart);
assertEquals(--departNum, service.count(Department.class));
assertEquals(departs.size(), service.count(Department.class, false));
}
departNum = departs.size();
for (Department depart : departs) {
service.remove(depart, false);
assertEquals(--departNum, service.count(Department.class, false));
}
}
Aggregations