Search in sources :

Example 6 with RuleMetricResponse

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

the class RuleMetricServiceImpl method getAllRuleMetric.

@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> getAllRuleMetric(PageRequest request) throws UnExpectedRequestException {
    PageRequest.checkRequest(request);
    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.");
        ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(request.getPage(), request.getSize()));
        total = ruleMetricDao.countAllRuleMetrics();
    } 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.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, request.getPage(), request.getSize()));
        total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null);
    } else {
        LOGGER.info("PROJECTOR  will get rule metrics of department and own.");
        List<Department> departments = new ArrayList<>();
        departments.add(loginUser.getDepartment());
        ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, request.getPage(), request.getSize()));
        total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser);
    }
    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", "{&GET_RULE_METRIC_SUCCESSFULLY}", 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)

Aggregations

Department (com.webank.wedatasphere.qualitis.entity.Department)6 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)6 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)6 User (com.webank.wedatasphere.qualitis.entity.User)6 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)6 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)6 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)3 Date (java.util.Date)2 ExcelReader (com.alibaba.excel.ExcelReader)1 ExcelWriter (com.alibaba.excel.ExcelWriter)1 Sheet (com.alibaba.excel.metadata.Sheet)1 ExcelTypeEnum (com.alibaba.excel.support.ExcelTypeEnum)1 RuleMetricBussCodeEnum (com.webank.wedatasphere.qualitis.constant.RuleMetricBussCodeEnum)1 RuleMetricLevelEnum (com.webank.wedatasphere.qualitis.constant.RuleMetricLevelEnum)1