Search in sources :

Example 1 with DepartmentResponse

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

the class DepartmentServiceImpl method addDepartment.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<DepartmentResponse> addDepartment(DepartmentAddRequest request) throws UnExpectedRequestException {
    Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
    if (departmentInDb != null) {
        LOGGER.error("Department already exist.");
        throw new UnExpectedRequestException("Department {&ALREADY_EXIST}");
    }
    Department department = new Department();
    department.setName(request.getDepartmentName());
    Department savedDepartment = departmentDao.saveDepartment(department);
    LOGGER.info("Succeed to create department, saved department info is : {}", savedDepartment.toString());
    return new GeneralResponse<>("200", "{&ADD_DEPARTMENT_SUCCESSFULLY}", new DepartmentResponse(savedDepartment));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) DepartmentResponse(com.webank.wedatasphere.qualitis.response.DepartmentResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DepartmentResponse

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

the class DepartmentServiceImpl method findAllDepartment.

@Override
public GeneralResponse<GetAllResponse<DepartmentResponse>> findAllDepartment(PageRequest request) throws UnExpectedRequestException {
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    long total = departmentDao.countDepartment();
    List<Department> departmentList = departmentDao.findAllDepartment(page, size);
    List<DepartmentResponse> departmentResponses = new ArrayList<>(departmentList.size());
    for (Department department : departmentList) {
        departmentResponses.add(new DepartmentResponse(department));
    }
    GetAllResponse<DepartmentResponse> responses = new GetAllResponse<>();
    responses.setData(departmentResponses);
    responses.setTotal(total);
    LOGGER.info("Succeed to find all departments, page: {}, size: {}, departments: {}", page, size, responses);
    return new GeneralResponse("200", "{&GET_DEPARTMENT_SUCCESSFULLY}", responses);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) DepartmentResponse(com.webank.wedatasphere.qualitis.response.DepartmentResponse)

Aggregations

Department (com.webank.wedatasphere.qualitis.entity.Department)2 DepartmentResponse (com.webank.wedatasphere.qualitis.response.DepartmentResponse)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)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