Search in sources :

Example 6 with Department

use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method queryRuleMetric.

@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> queryRuleMetric(RuleMetricQueryRequest request) throws UnExpectedRequestException {
    CommonChecker.checkObject(request, "Rule Metric query request");
    if (StringUtils.isBlank(request.getSubSystemName())) {
        request.setSubSystemName("");
    }
    if (StringUtils.isBlank(request.getRuleMetricName())) {
        request.setRuleMetricName("%");
    } else {
        request.setRuleMetricName("%" + request.getRuleMetricName() + "%");
    }
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to get all rule metric, page request: [{}], user: [{}]", request.toString(), userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    List<RuleMetric> ruleMetrics = new ArrayList<>();
    long total = 0;
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("SYS_ADMIN will get all rule metrics in query.");
        ruleMetrics.addAll(ruleMetricDao.queryAllRuleMetrics(request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
        total = ruleMetricDao.countQueryAllRuleMetrics(request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("DEPARTMENT_ADMIN will get rule metrics of all management departments and all projectors.");
        List<Department> departments = new ArrayList<>();
        for (UserRole temp : userRoles) {
            Department department = temp.getRole().getDepartment();
            if (department != null) {
                departments.add(department);
            }
        }
        ruleMetrics.addAll(ruleMetricDao.queryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
        total = ruleMetricDao.countQueryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
    } else {
        LOGGER.info("PROJECTOR  will get rule metrics of department and own.");
        List<Department> departments = new ArrayList<>();
        departments.add(loginUser.getDepartment());
        ruleMetrics.addAll(ruleMetricDao.queryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable(), request.getPage(), request.getSize()));
        total = ruleMetricDao.countQueryRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getSubSystemName(), request.getRuleMetricName(), request.getEnCode(), request.getType(), request.getAvailable());
    }
    GetAllResponse<RuleMetricResponse> response = new GetAllResponse<>();
    List<RuleMetricResponse> ruleMetricResponses = new ArrayList<>();
    for (RuleMetric ruleMetric : ruleMetrics) {
        ruleMetricResponses.add(new RuleMetricResponse(ruleMetric));
    }
    response.setData(ruleMetricResponses);
    response.setTotal(total);
    return new GeneralResponse<>("200", "{&RULE_METRIC_QUERY_SUCCESS}", response);
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 7 with Department

use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.

the class UserServiceImpl method modifyDepartment.

@Override
public GeneralResponse<?> modifyDepartment(ModifyDepartmentRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    User userInDb = userDao.findById(request.getUserId());
    if (null == userInDb) {
        throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}");
    }
    // Find department by name.
    Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
    if (null == departmentInDb) {
        throw new UnExpectedRequestException("Department of " + request.getDepartmentName() + " {&DOES_NOT_EXIST}");
    }
    userInDb.setDepartment(departmentInDb);
    // Save user
    userDao.saveUser(userInDb);
    LOGGER.info("Succeed to modify department, userId: {}, current_user: {}", userInDb.getId(), userInDb.getUserName());
    return new GeneralResponse<>("200", "{&MODIFY_DEPARTMENT_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) User(com.webank.wedatasphere.qualitis.entity.User)

Example 8 with Department

use of com.webank.wedatasphere.qualitis.entity.Department in project Qualitis by WeBankFinTech.

the class UserServiceImpl method addUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<AddUserResponse> addUser(UserAddRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of user by username
    String username = request.getUsername();
    User userInDb = userDao.findByUsername(username);
    if (userInDb != null) {
        throw new UnExpectedRequestException("username: " + username + " {&ALREADY_EXIST}");
    }
    // Generate random password and save user
    User newUser = new User();
    String password = RandomPasswordGenerator.generate(16);
    String passwordEncoded = Sha256Encoder.encode(password);
    newUser.setUserName(username);
    newUser.setPassword(passwordEncoded);
    newUser.setChineseName(request.getChineseName());
    // Find department by department name
    Department departmentInDb = departmentDao.findById(request.getDepartmentId());
    if (null == departmentInDb) {
        throw new UnExpectedRequestException("Department ID of " + request.getDepartmentId() + " {&DOES_NOT_EXIST}");
    }
    newUser.setDepartment(departmentInDb);
    User savedUser = userDao.saveUser(newUser);
    AddUserResponse addUserResponse = new AddUserResponse(savedUser, password);
    LOGGER.info("Succeed to create user, response: {}, current_user: {}", addUserResponse, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&CREATE_USER_SUCCESSFULLY}", addUserResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) User(com.webank.wedatasphere.qualitis.entity.User) AddUserResponse(com.webank.wedatasphere.qualitis.response.user.AddUserResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Department

use of com.webank.wedatasphere.qualitis.entity.Department 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 10 with Department

use of com.webank.wedatasphere.qualitis.entity.Department 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)20 User (com.webank.wedatasphere.qualitis.entity.User)15 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)15 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)14 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)11 ArrayList (java.util.ArrayList)11 List (java.util.List)10 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)9 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)9 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)7 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)7 Transactional (org.springframework.transaction.annotation.Transactional)7 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)4 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)3 DepartmentResponse (com.webank.wedatasphere.qualitis.response.DepartmentResponse)2 Date (java.util.Date)2