Search in sources :

Example 1 with RoleResponse

use of com.webank.wedatasphere.qualitis.response.RoleResponse in project Qualitis by WeBankFinTech.

the class RoleServiceImpl method addRole.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RoleResponse> addRole(RoleAddRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role by role name
    String roleName = request.getRoleName();
    Role roleInDb = roleDao.findByRoleName(roleName);
    if (roleInDb != null) {
        throw new UnExpectedRequestException("role name {&ALREADY_EXIST}, request: " + request);
    }
    // Save new role
    Role newRole = new Role();
    newRole.setName(roleName);
    if (request.getDepartmentName() != null) {
        Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
        if (departmentInDb == null) {
            throw new UnExpectedRequestException("department {&DOES_NOT_EXIST}, name: " + request.getDepartmentName());
        }
        LOGGER.info("Succeed to find department. Name: " + departmentInDb.getName());
        newRole.setDepartment(departmentInDb);
    }
    Role savedRole = roleDao.saveRole(newRole);
    RoleResponse roleResponse = new RoleResponse(savedRole);
    LOGGER.info("Succeed to add role, role: {}, current_user: {}", roleResponse, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&CREATE_ROLE_SUCCESSFULLY}", roleResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleResponse(com.webank.wedatasphere.qualitis.response.RoleResponse) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleResponse

use of com.webank.wedatasphere.qualitis.response.RoleResponse in project Qualitis by WeBankFinTech.

the class RoleServiceImpl method getAllRole.

@Override
public GeneralResponse<GetAllResponse<RoleResponse>> getAllRole(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    List<Role> roles = roleDao.findAllRole(page, size);
    long total = roleDao.countAll();
    List<RoleResponse> roleResponses = new ArrayList<>();
    for (Role role : roles) {
        RoleResponse tmp = new RoleResponse(role);
        roleResponses.add(tmp);
    }
    GetAllResponse<RoleResponse> responses = new GetAllResponse<>();
    responses.setData(roleResponses);
    responses.setTotal(total);
    LOGGER.info("Succeed to find all roles, page: {}, size: {}, role: {}, current_user: {}", page, size, responses, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&FIND_ALL_ROLES_SUCCESSFULLY}", responses);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ArrayList(java.util.ArrayList) RoleResponse(com.webank.wedatasphere.qualitis.response.RoleResponse) UserAndRoleResponse(com.webank.wedatasphere.qualitis.response.UserAndRoleResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Aggregations

GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 RoleResponse (com.webank.wedatasphere.qualitis.response.RoleResponse)2 UserAndRoleResponse (com.webank.wedatasphere.qualitis.response.UserAndRoleResponse)2 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 ArrayList (java.util.ArrayList)1 Transactional (org.springframework.transaction.annotation.Transactional)1