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);
}
Aggregations