Search in sources :

Example 6 with RuleTemplateResponse

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

the class RuleTemplateServiceImpl method addRuleTemplate.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class }, propagation = Propagation.REQUIRED)
public RuleTemplateResponse addRuleTemplate(AddRuleTemplateRequest request) throws UnExpectedRequestException {
    AddRuleTemplateRequest.checkRequest(request, false);
    LOGGER.info("Add default rule template request detail: {}", request.toString());
    // Save template.
    checkTemplateName(request.getTemplateName());
    Template newTemplate = new Template();
    newTemplate.setName(request.getTemplateName());
    newTemplate.setClusterNum(request.getClusterNum());
    newTemplate.setDbNum(request.getDbNum());
    newTemplate.setTableNum(request.getTableNum());
    newTemplate.setFieldNum(request.getFieldNum());
    newTemplate.setActionType(request.getActionType());
    newTemplate.setMidTableAction(request.getMidTableAction());
    newTemplate.setSaveMidTable(request.getSaveMidTable());
    newTemplate.setShowSql(request.getMidTableAction());
    newTemplate.setTemplateType(request.getTemplateType());
    newTemplate.setImportExportName(UuidGenerator.generate());
    // Save create user info.
    User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
    newTemplate.setCreateUser(userInDb);
    Template savedTemplate = ruleTemplateDao.saveTemplate(newTemplate);
    for (Integer type : request.getDatasourceType()) {
        TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(type, savedTemplate);
        templateDataSourceTypeDao.save(templateDataSourceType);
    }
    LOGGER.info("Succeed to save rule template, template_id: {}", savedTemplate.getId());
    // Determine the template level and save association table.
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    Integer roleType = roleService.getRoleType(userRoles);
    // Save department template
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        savedTemplate.setLevel(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode());
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        savedTemplate.setLevel(RuleTemplateLevelEnum.DEPARTMENT_TEMPLATE.getCode());
        saveTemplateDepartment(ruleTemplateDao.saveTemplate(savedTemplate), userRoles);
    } else {
        savedTemplate.setLevel(RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode());
        saveTemplateUser(userInDb, ruleTemplateDao.saveTemplate(savedTemplate));
    }
    // Save template info.
    createAndSaveTemplateInfo(savedTemplate, request);
    return new RuleTemplateResponse(savedTemplate);
}
Also used : RuleTemplateResponse(com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse) TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Template (com.webank.wedatasphere.qualitis.rule.entity.Template)6 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)6 ArrayList (java.util.ArrayList)5 User (com.webank.wedatasphere.qualitis.entity.User)4 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)4 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)4 Department (com.webank.wedatasphere.qualitis.entity.Department)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)3 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)3 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)3 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)3 List (java.util.List)3 Transactional (org.springframework.transaction.annotation.Transactional)2 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 TemplateMidTableInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta)1 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)1 TemplateStatisticsInputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta)1 AddRuleTemplateRequest (com.webank.wedatasphere.qualitis.rule.request.AddRuleTemplateRequest)1 TemplateMidTableInputMetaResponse (com.webank.wedatasphere.qualitis.rule.response.TemplateMidTableInputMetaResponse)1 TemplateOutputMetaResponse (com.webank.wedatasphere.qualitis.rule.response.TemplateOutputMetaResponse)1