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