Search in sources :

Example 41 with User

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

the class ProjectBatchServiceImpl method addRuleMetric.

private void addRuleMetric(ExcelRuleMetric excelRuleMetric, String userName) throws UnExpectedRequestException {
    RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(excelRuleMetric.getEnCode());
    if (ruleMetricInDb != null) {
        throw new UnExpectedRequestException("En code + [" + ruleMetricInDb.getEnCode() + "] +  of metric {&ALREADY_EXIST}");
    }
    LOGGER.info("Start to add rule metric, user: [{}]", userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    RuleMetric newRuleMetric = new RuleMetric();
    newRuleMetric.setCreateUser(userName);
    newRuleMetric.setName(excelRuleMetric.getName());
    newRuleMetric.setCnName(excelRuleMetric.getChName());
    newRuleMetric.setEnCode(excelRuleMetric.getEnCode());
    newRuleMetric.setMetricDesc(excelRuleMetric.getMetricDesc());
    newRuleMetric.setCreateTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    RuleMetric savedRuleMetric = ruleMetricDao.add(newRuleMetric);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("First level(created by SYS_ADMIN) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.DEFAULT_METRIC.getCode());
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.DEPARTMENT_METRIC.getCode());
        for (UserRole temp : userRoles) {
            Department department = temp.getRole().getDepartment();
            if (department != null) {
                RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
                ruleMetricDepartmentUser.setDepartment(department);
                ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
                ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
                LOGGER.info("Succeed to save rule metric department user.");
            }
        }
    } else {
        LOGGER.info("Third level(created by PROJECTOR) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.PERSONAL_METRIC.getCode());
        RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
        ruleMetricDepartmentUser.setDepartment(loginUser.getDepartment());
        ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
        ruleMetricDepartmentUser.setUser(loginUser);
        ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
        LOGGER.info("Succeed to save rule metric department user.");
    }
    savedRuleMetric.setBussCode(Integer.parseInt(excelRuleMetric.getDimension()));
    savedRuleMetric.setCreateUser(userName);
    savedRuleMetric.setFrequency(Integer.parseInt(excelRuleMetric.getFrequency()));
    savedRuleMetric.setDevDepartmentName(excelRuleMetric.getDevDepartmentName());
    savedRuleMetric.setOpsDepartmentName(excelRuleMetric.getOpsDepartmentName());
    savedRuleMetric.setDepartmentName(excelRuleMetric.getDepartmentName());
    savedRuleMetric.setSubSystemName(excelRuleMetric.getSubSystemName());
    savedRuleMetric.setProductName(excelRuleMetric.getProductName());
    savedRuleMetric.setFullCnName(excelRuleMetric.getFullCnName());
    savedRuleMetric.setBussCustom(excelRuleMetric.getBussCustom());
    savedRuleMetric.setAvailable(excelRuleMetric.getAvailable());
    savedRuleMetric.setType(excelRuleMetric.getType());
    ruleMetricDao.add(savedRuleMetric);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole)

Example 42 with User

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

the class RuleQueryServiceImpl method getColumnsByTableName.

@Override
public List<ColumnInfoDetail> getColumnsByTableName(String clusterName, Long datasourceId, String dbName, String tableName, String userName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    List<ColumnInfoDetail> result = null;
    User user = userDao.findByUsername(userName);
    if (user == null) {
        throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", userName));
    }
    try {
        if (StringUtils.isBlank(dbName)) {
            List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(clusterName, dbName, tableName, "%", userName);
            if (rules == null || rules.isEmpty()) {
                LOGGER.info("No rules for this datasource!");
                return null;
            }
            LOGGER.info("Rules related with context service table: [{}] are: {}", tableName, rules.toArray());
            String csId = rules.get(0).getCsId();
            String nodeName = rules.get(0).getName();
            GetUserTableByCsIdRequest getUserTableByCsIdRequest = new GetUserTableByCsIdRequest();
            getUserTableByCsIdRequest.setClusterName(clusterName);
            getUserTableByCsIdRequest.setLoginUser(userName);
            getUserTableByCsIdRequest.setNodeName(nodeName);
            getUserTableByCsIdRequest.setCsId(csId);
            DataInfo<CsTableInfoDetail> csTableInfoDetails = metaDataClient.getTableByCsId(getUserTableByCsIdRequest);
            if (csTableInfoDetails.getTotalCount() == 0) {
                LOGGER.info("Cannot find context service table with existed rules!");
                return null;
            }
            for (CsTableInfoDetail csTableInfoDetail : csTableInfoDetails.getContent()) {
                if (csTableInfoDetail.getTableName().equals(tableName)) {
                    GetUserColumnByCsRequest getUserColumnByCsRequest = new GetUserColumnByCsRequest();
                    getUserColumnByCsRequest.setClusterName(clusterName);
                    getUserColumnByCsRequest.setContextKey(csTableInfoDetail.getContextKey());
                    getUserColumnByCsRequest.setCsId(csId);
                    getUserColumnByCsRequest.setLoginUser(userName);
                    result = metaDataClient.getColumnByCsId(getUserColumnByCsRequest).getContent();
                    setRuleCount(result, user.getId(), clusterName, dbName, tableName);
                    break;
                } else {
                    continue;
                }
            }
        } else {
            if (datasourceId == null) {
                result = metaDataClient.getColumnInfo(clusterName, dbName, tableName, userName);
            } else {
                result = metaDataClient.getColumnsByDataSource(clusterName, userName, datasourceId, dbName, tableName).getContent();
            }
            setRuleCount(result, user.getId(), clusterName, dbName, tableName);
        }
        LOGGER.info("Datasource table number of columns: {}", result == null ? 0 : result.size());
    } catch (MetaDataAcquireFailedException e) {
        LOGGER.error("Datasource colums info {&DOES_NOT_EXIST}. Exception: {}", e);
        throw new MetaDataAcquireFailedException("Datasource colums info {&DOES_NOT_EXIST}. Exception: " + e.getMessage());
    } catch (UnExpectedRequestException e) {
        LOGGER.error("{&QUERY_PARAM_HAS_ERROR}. Exception: {}", e);
        throw new UnExpectedRequestException("{&QUERY_PARAM_HAS_ERROR}. Exception: " + e.getMessage());
    } catch (Exception e) {
        LOGGER.error("exception: {}", e);
    }
    return result;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ColumnInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.column.ColumnInfoDetail) GetUserTableByCsIdRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserTableByCsIdRequest) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) RuleQueryRule(com.webank.wedatasphere.qualitis.query.response.RuleQueryRule) GetUserColumnByCsRequest(com.webank.wedatasphere.qualitis.metadata.request.GetUserColumnByCsRequest)

Example 43 with User

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

the class RuleMetricServiceImpl method conditions.

@Override
public RuleMetricConditionResponse conditions() {
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to get rule metric condition, user: [{}]", userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    List<RuleMetric> ruleMetrics = new ArrayList<>();
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("SYS_ADMIN will get all rule metrics with conditions.");
        ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(0, Integer.MAX_VALUE));
    } 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, 0, Integer.MAX_VALUE));
    } 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, 0, Integer.MAX_VALUE));
    }
    Set<String> subSystemNameSet = ruleMetrics.stream().map(RuleMetric::getSubSystemName).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
    Set<RuleMetricTypeConfig> ruleMetricTypeConfigss = ruleMetricTypeConfigDao.findAllRuleMetricTypeConfig().stream().collect(Collectors.toSet());
    Set<String> enCode = ruleMetrics.stream().map(RuleMetric::getEnCode).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
    RuleMetricConditionResponse response = new RuleMetricConditionResponse();
    response.setSubSystemNameCondition(subSystemNameSet);
    response.setRuleMetricType(ruleMetricTypeConfigss);
    response.setEnCode(enCode);
    return response;
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) StringUtils(org.apache.commons.lang.StringUtils) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) RuleMetricValueResponse(com.webank.wedatasphere.qualitis.response.RuleMetricValueResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) RuleMetricBussCodeEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricBussCodeEnum) Context(javax.ws.rs.core.Context) ExcelReader(com.alibaba.excel.ExcelReader) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) ModifyRuleMetricRequest(com.webank.wedatasphere.qualitis.request.ModifyRuleMetricRequest) Department(com.webank.wedatasphere.qualitis.entity.Department) Set(java.util.Set) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) Collectors(java.util.stream.Collectors) ExecutionManagerImpl(com.webank.wedatasphere.qualitis.submitter.impl.ExecutionManagerImpl) ExcelTypeEnum(com.alibaba.excel.support.ExcelTypeEnum) List(java.util.List) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Sheet(com.alibaba.excel.metadata.Sheet) CommonChecker(com.webank.wedatasphere.qualitis.project.request.CommonChecker) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleDefaultTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) RuleMetricTypeConfigDao(com.webank.wedatasphere.qualitis.dao.RuleMetricTypeConfigDao) RuleMetricQueryRequest(com.webank.wedatasphere.qualitis.request.RuleMetricQueryRequest) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ArrayList(java.util.ArrayList) ExcelWriter(com.alibaba.excel.ExcelWriter) RuleMetricConditionResponse(com.webank.wedatasphere.qualitis.response.RuleMetricConditionResponse) RuleMetricLevelEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricLevelEnum) HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.webank.wedatasphere.qualitis.entity.User) ExcelRuleMetricListener(com.webank.wedatasphere.qualitis.excel.ExcelRuleMetricListener) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) RuleMetricService(com.webank.wedatasphere.qualitis.service.RuleMetricService) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) DownloadRuleMetricRequest(com.webank.wedatasphere.qualitis.request.DownloadRuleMetricRequest) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) HttpServletResponse(javax.servlet.http.HttpServletResponse) RuleMetricTypeConfig(com.webank.wedatasphere.qualitis.entity.RuleMetricTypeConfig) IOException(java.io.IOException) AddRuleMetricRequest(com.webank.wedatasphere.qualitis.request.AddRuleMetricRequest) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) URLEncoder(java.net.URLEncoder) ExcelSheetName(com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) RuleMetricDepartmentUserDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) TaskResultDao(com.webank.wedatasphere.qualitis.dao.TaskResultDao) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) RuleMetricTypeConfig(com.webank.wedatasphere.qualitis.entity.RuleMetricTypeConfig) ArrayList(java.util.ArrayList) RuleMetricConditionResponse(com.webank.wedatasphere.qualitis.response.RuleMetricConditionResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList)

Example 44 with User

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

the class RuleMetricServiceImpl method deleteRuleMetric.

@Override
@Transactional(rollbackFor = { Exception.class, RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleMetricResponse> deleteRuleMetric(long id) throws UnExpectedRequestException, PermissionDeniedRequestException {
    if (id <= 0) {
        throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
    }
    // Check rule metric existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
    if (ruleMetricInDb == null) {
        throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
    }
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to delete rule metric, rule metric ID: [{}], user: [{}]", id, userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("SYS_ADMIN will delete rule metric.");
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null) {
            LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        }
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("DEPARTMENT_ADMIN will delete rule metric.");
        if (ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.DEFAULT_METRIC.getCode())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<Department> managedDepartment = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                managedDepartment.add(department);
            }
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null && managedDepartment.contains(ruleMetricDepartmentUser.getDepartment())) {
            LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("PROJECTOR will delete rule metric.");
        if (!ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetricInDb.getCreateUser().equals(loginUser.getUserName())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null) {
            LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    }
    ruleMetricDao.delete(ruleMetricInDb);
    return new GeneralResponse<>("200", "{&DELETE_RULE_METRIC_SUCCESSFULLY}", null);
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with User

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

User (com.webank.wedatasphere.qualitis.entity.User)54 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)38 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)30 Transactional (org.springframework.transaction.annotation.Transactional)23 ArrayList (java.util.ArrayList)22 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)21 Department (com.webank.wedatasphere.qualitis.entity.Department)15 List (java.util.List)14 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)13 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)12 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)10 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)7 Application (com.webank.wedatasphere.qualitis.entity.Application)6 Task (com.webank.wedatasphere.qualitis.entity.Task)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)5