Search in sources :

Example 26 with GetAllResponse

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

the class RuleTemplateServiceImpl method getCustomRuleTemplateByUser.

@Override
public GeneralResponse<GetAllResponse<RuleTemplateResponse>> getCustomRuleTemplateByUser(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    // Get userId
    Long userId = HttpUtils.getUserId(httpServletRequest);
    int size = request.getSize();
    int page = request.getPage();
    List<Template> templates = userRuleTemplateDao.findByUserId(userId, page, size);
    long total = userRuleTemplateDao.countByUserId(userId);
    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 get custom rule_template. response: {}", response);
    return new GeneralResponse<>("200", "{&GET_CUSTOM_RULE_TEMPLATE_SUCCESSFULLY}", response);
}
Also used : 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) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 27 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse 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 28 with GetAllResponse

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

Aggregations

GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)28 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)26 ArrayList (java.util.ArrayList)21 User (com.webank.wedatasphere.qualitis.entity.User)9 List (java.util.List)8 Application (com.webank.wedatasphere.qualitis.entity.Application)5 Department (com.webank.wedatasphere.qualitis.entity.Department)5 Task (com.webank.wedatasphere.qualitis.entity.Task)5 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)5 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Map (java.util.Map)4 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)3 Project (com.webank.wedatasphere.qualitis.project.entity.Project)3 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)3 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)3 ClusterInfoDao (com.webank.wedatasphere.qualitis.dao.ClusterInfoDao)2 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)2 ProxyUser (com.webank.wedatasphere.qualitis.entity.ProxyUser)2 RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)2