Search in sources :

Example 16 with Department

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

Example 17 with Department

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

the class RuleTemplateServiceImpl method modifyRuleTemplate.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public RuleTemplateResponse modifyRuleTemplate(ModifyRuleTemplateRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    AddRuleTemplateRequest addRuleTemplateRequest = ModifyRuleTemplateRequest.checkRequest(request);
    // Check template existence
    Template templateInDb = checkRuleTemplate(request.getTemplateId());
    // Check user info.
    User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.PROJECTOR.getCode())) {
        LOGGER.info("The projector is going to modify template.");
        if (templateInDb.getLevel().intValue() != RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode()) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        if (!userInDb.equals(templateInDb.getCreateUser())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("The department admin is going to modify template.");
        if (templateInDb.getLevel().intValue() == RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode()) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<User> createUsers = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                List<User> userList = userDao.findByDepartment(department);
                createUsers.addAll(userList);
            }
        }
        if (!createUsers.contains(templateInDb.getCreateUser())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("The system admin is going to modify template.");
    }
    // delete output meta
    templateOutputMetaService.deleteByTemplate(templateInDb);
    // delete mid_table input meta
    templateMidTableInputMetaService.deleteByTemplate(templateInDb);
    // delete statistics input meta
    templateStatisticsInputMetaService.deleteByTemplate(templateInDb);
    // delete template type relationship
    templateDataSourceTypeDao.deleteByTemplate(templateInDb);
    // Save template.
    if (!templateInDb.getName().equals(request.getTemplateName())) {
        checkTemplateName(request.getTemplateName());
    }
    templateInDb.setName(request.getTemplateName());
    templateInDb.setClusterNum(request.getClusterNum());
    templateInDb.setDbNum(request.getDbNum());
    templateInDb.setTableNum(request.getTableNum());
    templateInDb.setFieldNum(request.getFieldNum());
    templateInDb.setActionType(request.getActionType());
    templateInDb.setMidTableAction(request.getMidTableAction());
    templateInDb.setSaveMidTable(request.getSaveMidTable());
    templateInDb.setShowSql(request.getMidTableAction());
    templateInDb.setTemplateType(request.getTemplateType());
    templateInDb.setModifyUser(userInDb);
    Template savedTemplate = ruleTemplateDao.saveTemplate(templateInDb);
    List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(savedTemplate);
    List<Integer> templateDataSourceTypeIntegers = templateDataSourceTypes.stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
    for (Integer type : request.getDatasourceType()) {
        if (!templateDataSourceTypeIntegers.contains(type)) {
            TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(type, savedTemplate);
            templateDataSourceTypeDao.save(templateDataSourceType);
        }
    }
    LOGGER.info("Succeed to save rule template, template_id: {}", savedTemplate.getId());
    // Save template info.
    createAndSaveTemplateInfo(savedTemplate, addRuleTemplateRequest);
    return new RuleTemplateResponse(savedTemplate);
}
Also used : PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) AddRuleTemplateRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleTemplateRequest) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Department

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

the class RuleTemplateServiceImpl method getDefaultRuleTemplate.

@Override
public GeneralResponse<GetAllResponse<RuleTemplateResponse>> getDefaultRuleTemplate(TemplatePageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    TemplatePageRequest.checkRequest(request);
    int size = request.getSize();
    int page = request.getPage();
    String dataSourceType = request.getDataSourceType();
    Integer dataSourceTypeCode = TemplateDataSourceTypeEnum.getCode(dataSourceType);
    List<User> users = new ArrayList<>();
    List<Template> templates;
    List<Department> departments = new ArrayList<>();
    long total = 0;
    User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        templates = ruleTemplateDao.findAllDefaultTemplate(page, size);
        total = ruleTemplateDao.countAllDefaultTemplate();
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                departments.add(department);
                List<User> userList = userDao.findByDepartment(department);
                users.addAll(userList);
            }
        }
        templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
        total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
    } else {
        Department department = userInDb.getDepartment();
        if (department != null) {
            departments.add(department);
        }
        users.add(userInDb);
        templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
        total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.SINGLE_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
    }
    GetAllResponse<RuleTemplateResponse> response = new GetAllResponse<>();
    response.setTotal(total);
    List<RuleTemplateResponse> responseList = new ArrayList<>();
    for (Template template : templates) {
        RuleTemplateResponse ruleTemplateResponse = new RuleTemplateResponse(template);
        List<Integer> types = templateDataSourceTypeDao.findByTemplate(template).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
        ruleTemplateResponse.setDatasourceType(types);
        responseList.add(ruleTemplateResponse);
    }
    response.setData(responseList);
    LOGGER.info("Succeed to find default rule_template. response: {}", response);
    return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_SUCCESSFULLY}", response);
}
Also used : TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) ArrayList(java.util.ArrayList) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 19 with Department

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

the class RuleTemplateServiceImpl method getMultiRuleTemplate.

/**
 * Paging get template
 * @param request
 * @return
 */
@Override
public GeneralResponse<GetAllResponse<RuleTemplateResponse>> getMultiRuleTemplate(TemplatePageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    TemplatePageRequest.checkRequest(request);
    int size = request.getSize();
    int page = request.getPage();
    String dataSourceType = request.getDataSourceType();
    Integer dataSourceTypeCode = TemplateDataSourceTypeEnum.getCode(dataSourceType);
    List<User> users = new ArrayList<>(1);
    List<Department> departments = new ArrayList<>(1);
    List<Template> templates;
    long total = 0;
    User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        templates = ruleTemplateDao.findAllMultiTemplate(dataSourceTypeCode, page, size);
        total = ruleTemplateDao.countAllMultiTemplate(dataSourceTypeCode);
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                departments.add(department);
                List<User> userList = userDao.findByDepartment(department);
                users.addAll(userList);
            }
        }
        templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
        total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
    } else {
        Department department = userInDb.getDepartment();
        if (department != null) {
            departments.add(department);
        }
        users.add(userInDb);
        templates = ruleTemplateDao.findTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode, page, size);
        total = ruleTemplateDao.countTemplates(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode(), RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode(), departments.size() == 0 ? null : departments, users.size() == 0 ? null : users, dataSourceTypeCode);
    }
    GetAllResponse<RuleTemplateResponse> response = new GetAllResponse<>();
    response.setTotal(total);
    List<RuleTemplateResponse> responseList = new ArrayList<>();
    for (Template template : templates) {
        RuleTemplateResponse ruleTemplateResponse = new RuleTemplateResponse(template);
        List<Integer> types = templateDataSourceTypeDao.findByTemplate(template).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
        ruleTemplateResponse.setDatasourceType(types);
        responseList.add(ruleTemplateResponse);
    }
    response.setData(responseList);
    LOGGER.info("Succeed to find multi rule_template. response: {}", response);
    return new GeneralResponse<>("200", "{&GET_MULTI_RULE_TEMPLATE_SUCCESSFULLY}", response);
}
Also used : TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) ArrayList(java.util.ArrayList) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 20 with Department

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

the class RuleTemplateServiceImpl method saveTemplateDepartment.

private void saveTemplateDepartment(Template template, List<UserRole> userRoles) {
    for (UserRole temp : userRoles) {
        Department department = temp.getRole().getDepartment();
        if (department != null) {
            TemplateDepartment templateDepartment = new TemplateDepartment();
            templateDepartment.setDepartment(department);
            templateDepartment.setTemplate(template);
            templateDepartmentDao.saveDepartmentTemplate(templateDepartment);
            LOGGER.info("Succeed to save department template.");
        }
    }
}
Also used : TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole)

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