use of com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment 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.TemplateDepartment in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method saveTemplateDepartment.
private void saveTemplateDepartment(Template template, List<UserRole> userRoles) {
for (UserRole temp : userRoles) {
Department department = temp.getRole().getDepartment();
if (department != null) {
TemplateDepartment templateDepartment = new TemplateDepartment();
templateDepartment.setDepartment(department);
templateDepartment.setTemplate(template);
templateDepartmentDao.saveDepartmentTemplate(templateDepartment);
LOGGER.info("Succeed to save department template.");
}
}
}
Aggregations