Search in sources :

Example 1 with UserRole

use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method addProjectReal.

@Override
public Project addProjectReal(Long userId, String projectName, String cnName, String projectDescription) throws UnExpectedRequestException {
    User user = userDao.findById(userId);
    // Automatically grant the highest authority to the system administrator.
    Role role = roleDao.findByRoleName(ADMIN);
    List<User> admins = userRoleDao.findByRole(role).stream().map(UserRole::getUser).collect(Collectors.toList());
    // Check existence of project by project name.
    Project projectInDb = projectDao.findByNameAndCreateUser(projectName, user.getUserName());
    if (projectInDb != null) {
        throw new UnExpectedRequestException(String.format("{&PROJECT}:%s {&ALREADY_EXIST}", projectName));
    }
    // Save project.
    Project newProject = new Project(projectName, cnName, projectDescription, user.getUserName(), user.getChineseName(), user.getDepartment() != null ? user.getDepartment().getName() : "", ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    // Create project user.
    if (admins.contains(user)) {
        createProjectUser(newProject, user);
    } else {
        createProjectUser(newProject, user);
        for (User currentAdmin : admins) {
            createProjectUser(newProject, currentAdmin);
        }
    }
    return newProject;
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser)

Example 2 with UserRole

use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.

the class ProjectBatchServiceImpl method modifyRuleMetric.

private void modifyRuleMetric(ExcelRuleMetric excelRuleMetric, RuleMetric ruleMetric, String userName) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check en code existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(excelRuleMetric.getEnCode());
    if (ruleMetricInDb != null && ruleMetricInDb.getId().longValue() != ruleMetric.getId().longValue()) {
        throw new UnExpectedRequestException("Rule Metric [EN_CODE=" + excelRuleMetric.getEnCode() + "] {&DOES_NOT_EXIST}");
    }
    LOGGER.info("Start to modify rule metric, modify request: [{}], user: [{}]", excelRuleMetric.toString(), userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("First level(created by SYS_ADMIN) indicator will be modified soon.");
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be modified soon.");
        if (ruleMetric.getLevel().equals(RuleMetricLevelEnum.DEFAULT_METRIC.getCode())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<Department> managedDepartment = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                managedDepartment.add(department);
            }
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetric);
        if (ruleMetricDepartmentUser != null && managedDepartment.contains(ruleMetricDepartmentUser.getDepartment())) {
            LOGGER.info("Rule metric[{}] comes from department: {}", ruleMetric.toString(), ruleMetricDepartmentUser.getDepartment().getName());
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("Third level(created by PROJECTOR) indicator will be modified soon.");
        if (!ruleMetric.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetric.getCreateUser().equals(loginUser.getUserName())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    }
    ruleMetric.setName(excelRuleMetric.getName());
    ruleMetric.setMetricDesc(excelRuleMetric.getMetricDesc());
    ruleMetric.setSubSystemName(excelRuleMetric.getSubSystemName());
    ruleMetric.setFullCnName(excelRuleMetric.getFullCnName());
    ruleMetric.setModifyUser(userName);
    ruleMetric.setModifyTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    ruleMetric.setType(excelRuleMetric.getType());
    ruleMetric.setFrequency(Integer.parseInt(excelRuleMetric.getFrequency()));
    ruleMetric.setEnCode(excelRuleMetric.getEnCode());
    ruleMetric.setDepartmentName(excelRuleMetric.getDepartmentName());
    ruleMetric.setDevDepartmentName(excelRuleMetric.getDevDepartmentName());
    ruleMetric.setOpsDepartmentName(excelRuleMetric.getOpsDepartmentName());
    ruleMetric.setAvailable(excelRuleMetric.getAvailable());
    ruleMetricDao.add(ruleMetric);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole)

Example 3 with UserRole

use of com.webank.wedatasphere.qualitis.entity.UserRole 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 4 with UserRole

use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method modifyRuleMetricReal.

private GeneralResponse<RuleMetricResponse> modifyRuleMetricReal(ModifyRuleMetricRequest request, String userName) throws UnExpectedRequestException, PermissionDeniedRequestException {
    if (request == null) {
        throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
    }
    // Check rule metric existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findById(request.getId());
    if (ruleMetricInDb == null) {
        throw new UnExpectedRequestException("Rule Metric [ID=" + request.getId() + "] {&DOES_NOT_EXIST}");
    }
    LOGGER.info("Start to modify rule metric, modify request: [{}], user: [{}]", request.toString(), userName);
    if (!ruleMetricInDb.getName().equals(request.getName())) {
        checkDuplicateName(request.getName());
    }
    if (!ruleMetricInDb.getEnCode().equals(request.getEnCode())) {
        checkDuplicateCode(request.getEnCode());
    }
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("First level(created by SYS_ADMIN) indicator will be modified soon.");
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be modified soon.");
        if (ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.DEFAULT_METRIC.getCode())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<Department> managedDepartment = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                managedDepartment.add(department);
            }
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null && managedDepartment.contains(ruleMetricDepartmentUser.getDepartment())) {
            LOGGER.info("Rule metric[{}]", ruleMetricInDb.toString());
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("Third level(created by PROJECTOR) indicator will be modified soon.");
        if (!ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetricInDb.getCreateUser().equals(loginUser.getUserName())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    }
    Integer bussCode = request.getBussCode();
    ruleMetricInDb.setName(request.getName());
    ruleMetricInDb.setCnName(request.getCnName());
    ruleMetricInDb.setMetricDesc(request.getDesc());
    ruleMetricInDb.setBussCode(bussCode);
    if (RuleMetricBussCodeEnum.SUBSYSTEM.getCode().equals(bussCode)) {
        ruleMetricInDb.setSubSystemName(request.getSubSystemName());
        ruleMetricInDb.setFullCnName(request.getFullCnName());
        // Empty them
        ruleMetricInDb.setBussCustom("");
        ruleMetricInDb.setProductName("");
    } else if (RuleMetricBussCodeEnum.PRODUCT.getCode().equals(bussCode)) {
        ruleMetricInDb.setProductName(request.getProductName());
        ruleMetricInDb.setSubSystemName("");
        ruleMetricInDb.setFullCnName("");
        ruleMetricInDb.setBussCustom("");
    } else if (RuleMetricBussCodeEnum.CUSTOM.getCode().equals(bussCode)) {
        ruleMetricInDb.setBussCustom(request.getBussCustom());
        ruleMetricInDb.setProductName("");
        ruleMetricInDb.setSubSystemName("");
        ruleMetricInDb.setFullCnName("");
    }
    ruleMetricInDb.setModifyUser(userName);
    ruleMetricInDb.setModifyTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    ruleMetricInDb.setType(request.getType());
    ruleMetricInDb.setEnCode(request.getEnCode());
    ruleMetricInDb.setFrequency(request.getFrequency());
    ruleMetricInDb.setDepartmentName(request.getDepartmentName());
    ruleMetricInDb.setDevDepartmentName(request.getDevDepartmentName());
    ruleMetricInDb.setOpsDepartmentName(request.getOpsDepartmentName());
    ruleMetricInDb.setAvailable(request.getAvailable());
    RuleMetricResponse response = new RuleMetricResponse(ruleMetricDao.add(ruleMetricInDb));
    return new GeneralResponse<>("200", "{&MODIFY_RULE_METRIC_SUCCESSFULLY}", response);
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) Date(java.util.Date) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with UserRole

use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method addRuleMetricReal.

private GeneralResponse<RuleMetricResponse> addRuleMetricReal(AddRuleMetricRequest request, String userName) throws UnExpectedRequestException {
    checkDuplicateName(request.getName());
    checkDuplicateCode(request.getEnCode());
    LOGGER.info("Start to add rule metric, add request: [{}], user: [{}]", request.toString(), userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    RuleMetric newRuleMetric = new RuleMetric(request.getName(), request.getCnName(), request.getDesc(), request.getSubSystemName(), request.getFullCnName(), request.getProductName(), request.getDepartmentName(), request.getDevDepartmentName(), request.getOpsDepartmentName(), request.getType(), request.getEnCode(), request.getFrequency(), request.getAvailable(), request.getBussCode(), request.getBussCustom());
    newRuleMetric.setCreateUser(userName);
    newRuleMetric.setCreateTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    RuleMetric savedRuleMetric = ruleMetricDao.add(newRuleMetric);
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("First level(created by SYS_ADMIN) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.DEFAULT_METRIC.getCode());
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("Second level(created by DEPARTMENT_ADMIN) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.DEPARTMENT_METRIC.getCode());
        for (UserRole temp : userRoles) {
            Department department = temp.getRole().getDepartment();
            if (department != null) {
                RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
                ruleMetricDepartmentUser.setDepartment(department);
                ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
                ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
                LOGGER.info("Succeed to save rule metric department user.");
            }
        }
    } else {
        LOGGER.info("Third level(created by PROJECTOR) indicator will be created soon.");
        savedRuleMetric.setLevel(RuleMetricLevelEnum.PERSONAL_METRIC.getCode());
        RuleMetricDepartmentUser ruleMetricDepartmentUser = new RuleMetricDepartmentUser();
        ruleMetricDepartmentUser.setDepartment(loginUser.getDepartment());
        ruleMetricDepartmentUser.setUser(loginUser);
        ruleMetricDepartmentUser.setRuleMetric(savedRuleMetric);
        ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
        LOGGER.info("Succeed to save rule metric department user.");
    }
    RuleMetricResponse response = new RuleMetricResponse(ruleMetricDao.add(savedRuleMetric));
    return new GeneralResponse<>("200", "{&ADD_RULE_METRIC_SUCCESSFULLY}", response);
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Date(java.util.Date)

Aggregations

UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)24 User (com.webank.wedatasphere.qualitis.entity.User)21 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)15 Department (com.webank.wedatasphere.qualitis.entity.Department)14 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)12 ArrayList (java.util.ArrayList)11 Transactional (org.springframework.transaction.annotation.Transactional)11 List (java.util.List)10 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)9 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)9 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)8 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)7 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)7 Role (com.webank.wedatasphere.qualitis.entity.Role)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)5 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)5 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)5 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)4 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)3