Search in sources :

Example 1 with TemplateDepartment

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);
}
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 2 with TemplateDepartment

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.");
        }
    }
}
Also used : TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole)

Aggregations

Department (com.webank.wedatasphere.qualitis.entity.Department)2 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)2 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)2 User (com.webank.wedatasphere.qualitis.entity.User)1 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)1 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)1 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1