Search in sources :

Example 6 with Department

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

Example 7 with Department

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;
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) Date(java.util.Date)

Example 8 with Department

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;
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department)

Example 9 with Department

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));
    }
}
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 10 with Department

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));
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department)

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