Search in sources :

Example 6 with Template

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

the class RuleTemplateServiceImpl method deleteRuleTemplate.

@Override
public void deleteRuleTemplate(Long templateId) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check template existence
    Template templateInDb = checkRuleTemplate(templateId);
    // Check operator permission
    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 delete template.");
        if (templateInDb.getLevel().intValue() != RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode()) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        if (userInDb.getId() != (templateInDb.getCreateUser().getId())) {
            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 delete 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);
            }
        }
        boolean exist = false;
        for (User user : createUsers) {
            if (user.getId() == templateInDb.getCreateUser().getId()) {
                exist = true;
                break;
            }
        }
        if (!exist) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        if (templateInDb.getLevel().equals(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode())) {
            if (templateInDb.getCreateUser() == null || !userInDb.getUserName().equals(templateInDb.getCreateUser().getUserName())) {
                throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
            }
        }
        LOGGER.info("The system admin is going to delete template.");
    }
    // Check rules of template
    ruleService.checkRuleOfTemplate(templateInDb);
    // Delete 'Templatedepartment' or 'TemplateUser'
    clearTemplateUser(templateInDb);
    List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
    for (TemplateDataSourceType templateDataSourceType : templateDataSourceTypes) {
        templateDataSourceTypeDao.delete(templateDataSourceType);
    }
    ruleTemplateDao.deleteTemplate(templateInDb);
}
Also used : PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Template(com.webank.wedatasphere.qualitis.rule.entity.Template)

Example 7 with Template

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

the class RuleTemplateServiceImpl method addFileTemplate.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class }, propagation = Propagation.REQUIRED)
public Template addFileTemplate(AddFileRuleRequest request) {
    Template newTemplate = new Template();
    newTemplate.setName(request.getProjectId() + "_" + request.getRuleName() + "_template");
    newTemplate.setTemplateType(RuleTemplateTypeEnum.FILE_COUSTOM.getCode());
    Template savedTemplate = ruleTemplateDao.saveTemplate(newTemplate);
    LOGGER.info("Succeed to save file custom template, template_id: {}", savedTemplate.getId());
    return savedTemplate;
}
Also used : Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Template

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

the class RuleTemplateServiceImpl method getMultiSourceTemplateMeta.

@Override
public GeneralResponse<?> getMultiSourceTemplateMeta(Long templateId) throws UnExpectedRequestException {
    // Check existence of template and if multi-table rule template
    Template templateInDb = checkRuleTemplate(templateId);
    if (!templateInDb.getTemplateType().equals(RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode())) {
        throw new UnExpectedRequestException("Template : [" + templateId + "] {&IS_NOT_A_MULTI_TEMPLATE}");
    }
    // return show_sql of template and template output
    TemplateInputDemandResponse templateInputDemandResponse = new TemplateInputDemandResponse(templateInDb, RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode());
    LOGGER.info("Succeed to get the meta of multi_rule_template. rule_template_id: {}", templateId);
    return new GeneralResponse<>("200", "{&GET_META_OF_MULTI_RULE_TEMPLATE_SUCCESSFULLY}", templateInputDemandResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateInputDemandResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateInputDemandResponse) Template(com.webank.wedatasphere.qualitis.rule.entity.Template)

Example 9 with Template

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

the class RuleTemplateServiceImpl method deleteFileRuleTemplate.

@Override
public void deleteFileRuleTemplate(Long templateId) throws UnExpectedRequestException {
    // Check template existence
    Template templateInDb = checkRuleTemplate(templateId);
    ruleTemplateDao.deleteTemplate(templateInDb);
    List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
    for (TemplateDataSourceType templateDataSourceType : templateDataSourceTypes) {
        templateDataSourceTypeDao.delete(templateDataSourceType);
    }
}
Also used : TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Template(com.webank.wedatasphere.qualitis.rule.entity.Template)

Example 10 with Template

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

the class RuleTemplateServiceImpl method getRuleMultiTemplateMeta.

/**
 * Get meta data information by template_id
 * @param ruleTemplateId
 * @return
 * @throws UnExpectedRequestException
 */
@Override
public GeneralResponse<TemplateMetaResponse> getRuleMultiTemplateMeta(Long ruleTemplateId) throws UnExpectedRequestException {
    // Find rule template by rule template id
    Template templateInDb = ruleTemplateDao.findById(ruleTemplateId);
    if (null == templateInDb) {
        throw new UnExpectedRequestException("rule_template_id {&CAN_NOT_BE_NULL_OR_EMPTY}");
    }
    // Find meta data of template
    List<TemplateOutputMeta> templateOutputMetas = templateOutputMetaDao.findByRuleTemplate(templateInDb);
    // Add child template
    if (templateInDb.getChildTemplate() != null) {
        templateOutputMetas.addAll(templateOutputMetaDao.findByRuleTemplate(templateInDb.getChildTemplate()));
    }
    List<Integer> types = templateDataSourceTypeDao.findByTemplate(templateInDb).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
    TemplateMetaResponse response = new TemplateMetaResponse(templateInDb, templateOutputMetas, types);
    LOGGER.info("Succeed to get rule_template, rule template id: {}", ruleTemplateId);
    return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_META_SUCCESSFULLY}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateMetaResponse(com.webank.wedatasphere.qualitis.rule.response.TemplateMetaResponse)

Aggregations

Template (com.webank.wedatasphere.qualitis.rule.entity.Template)29 ArrayList (java.util.ArrayList)17 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)13 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)11 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)10 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)9 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)9 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)9 HashSet (java.util.HashSet)8 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)6 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)6 List (java.util.List)6 User (com.webank.wedatasphere.qualitis.entity.User)5 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)5 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)5 Date (java.util.Date)5 Set (java.util.Set)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Department (com.webank.wedatasphere.qualitis.entity.Department)4