Search in sources :

Example 11 with Department

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

the class DepartmentServiceImpl method deleteDepartment.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteDepartment(Long departmentId) throws UnExpectedRequestException {
    if (departmentId == null) {
        throw new UnExpectedRequestException("department id {&CAN_NOT_BE_NULL_OR_EMPTY}");
    }
    Department departmentInDb = departmentDao.findById(departmentId);
    if (departmentInDb == null) {
        LOGGER.error("Department donot exist.");
        throw new UnExpectedRequestException("Department {&DOES_NOT_EXIST}");
    }
    // Check user exists.
    checkUser(departmentInDb);
    // Check role exists.
    checkRole(departmentInDb);
    departmentDao.deleteDepartment(departmentInDb);
    LOGGER.info("Succeed to delete department, saved department id is : {}", departmentId);
    return new GeneralResponse<>("200", "{&DELETE_DEPARTMENT_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Department

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

the class DepartmentServiceImpl method modifyDepartment.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyDepartment(DepartmentModifyRequest request) throws UnExpectedRequestException {
    request.checkRequest();
    Department departmentInDb = departmentDao.findById(request.getDepartmentId());
    if (departmentInDb == null) {
        LOGGER.error("Department donot exist.");
        throw new UnExpectedRequestException("Department {&DOES_NOT_EXIST}");
    }
    departmentInDb.setName(request.getDepartmentName());
    Department savedDepartment = departmentDao.saveDepartment(departmentInDb);
    LOGGER.info("Succeed to modify department, saved department info is : {}", savedDepartment.toString());
    return new GeneralResponse<>("200", "{&MODIFY_DEPARTMENT_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Department

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

the class ProjectBatchServiceImpl method addRuleMetric.

private void addRuleMetric(ExcelRuleMetric excelRuleMetric, String userName) throws UnExpectedRequestException {
    RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(excelRuleMetric.getEnCode());
    if (ruleMetricInDb != null) {
        throw new UnExpectedRequestException("En code + [" + ruleMetricInDb.getEnCode() + "] +  of metric {&ALREADY_EXIST}");
    }
    LOGGER.info("Start to add rule metric, user: [{}]", userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    RuleMetric newRuleMetric = new RuleMetric();
    newRuleMetric.setCreateUser(userName);
    newRuleMetric.setName(excelRuleMetric.getName());
    newRuleMetric.setCnName(excelRuleMetric.getChName());
    newRuleMetric.setEnCode(excelRuleMetric.getEnCode());
    newRuleMetric.setMetricDesc(excelRuleMetric.getMetricDesc());
    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.setRuleMetric(savedRuleMetric);
        ruleMetricDepartmentUser.setUser(loginUser);
        ruleMetricDepartmentUserDao.add(ruleMetricDepartmentUser);
        LOGGER.info("Succeed to save rule metric department user.");
    }
    savedRuleMetric.setBussCode(Integer.parseInt(excelRuleMetric.getDimension()));
    savedRuleMetric.setCreateUser(userName);
    savedRuleMetric.setFrequency(Integer.parseInt(excelRuleMetric.getFrequency()));
    savedRuleMetric.setDevDepartmentName(excelRuleMetric.getDevDepartmentName());
    savedRuleMetric.setOpsDepartmentName(excelRuleMetric.getOpsDepartmentName());
    savedRuleMetric.setDepartmentName(excelRuleMetric.getDepartmentName());
    savedRuleMetric.setSubSystemName(excelRuleMetric.getSubSystemName());
    savedRuleMetric.setProductName(excelRuleMetric.getProductName());
    savedRuleMetric.setFullCnName(excelRuleMetric.getFullCnName());
    savedRuleMetric.setBussCustom(excelRuleMetric.getBussCustom());
    savedRuleMetric.setAvailable(excelRuleMetric.getAvailable());
    savedRuleMetric.setType(excelRuleMetric.getType());
    ruleMetricDao.add(savedRuleMetric);
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) 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 14 with Department

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

the class RuleMetricServiceImpl method conditions.

@Override
public RuleMetricConditionResponse conditions() {
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to get rule metric condition, user: [{}]", userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    List<RuleMetric> ruleMetrics = new ArrayList<>();
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("SYS_ADMIN will get all rule metrics with conditions.");
        ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(0, Integer.MAX_VALUE));
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("DEPARTMENT_ADMIN will get rule metrics of all management departments and all projectors.");
        List<Department> departments = new ArrayList<>();
        for (UserRole temp : userRoles) {
            Department department = temp.getRole().getDepartment();
            if (department != null) {
                departments.add(department);
            }
        }
        ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null, 0, Integer.MAX_VALUE));
    } else {
        LOGGER.info("PROJECTOR  will get rule metrics of department and own.");
        List<Department> departments = new ArrayList<>();
        departments.add(loginUser.getDepartment());
        ruleMetrics.addAll(ruleMetricDao.findRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser, 0, Integer.MAX_VALUE));
    }
    Set<String> subSystemNameSet = ruleMetrics.stream().map(RuleMetric::getSubSystemName).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
    Set<RuleMetricTypeConfig> ruleMetricTypeConfigss = ruleMetricTypeConfigDao.findAllRuleMetricTypeConfig().stream().collect(Collectors.toSet());
    Set<String> enCode = ruleMetrics.stream().map(RuleMetric::getEnCode).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toSet());
    RuleMetricConditionResponse response = new RuleMetricConditionResponse();
    response.setSubSystemNameCondition(subSystemNameSet);
    response.setRuleMetricType(ruleMetricTypeConfigss);
    response.setEnCode(enCode);
    return response;
}
Also used : ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) StringUtils(org.apache.commons.lang.StringUtils) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) HiveRuleDetail(com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail) RuleMetricValueResponse(com.webank.wedatasphere.qualitis.response.RuleMetricValueResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig) RuleMetricDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDao) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) RuleMetricBussCodeEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricBussCodeEnum) Context(javax.ws.rs.core.Context) ExcelReader(com.alibaba.excel.ExcelReader) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) ModifyRuleMetricRequest(com.webank.wedatasphere.qualitis.request.ModifyRuleMetricRequest) Department(com.webank.wedatasphere.qualitis.entity.Department) Set(java.util.Set) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) Collectors(java.util.stream.Collectors) ExecutionManagerImpl(com.webank.wedatasphere.qualitis.submitter.impl.ExecutionManagerImpl) ExcelTypeEnum(com.alibaba.excel.support.ExcelTypeEnum) List(java.util.List) RuleMetricResponse(com.webank.wedatasphere.qualitis.response.RuleMetricResponse) Sheet(com.alibaba.excel.metadata.Sheet) CommonChecker(com.webank.wedatasphere.qualitis.project.request.CommonChecker) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RoleDefaultTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RoleDefaultTypeEnum) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) FastDateFormat(org.apache.commons.lang.time.FastDateFormat) RuleMetricTypeConfigDao(com.webank.wedatasphere.qualitis.dao.RuleMetricTypeConfigDao) RuleMetricQueryRequest(com.webank.wedatasphere.qualitis.request.RuleMetricQueryRequest) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ArrayList(java.util.ArrayList) ExcelWriter(com.alibaba.excel.ExcelWriter) RuleMetricConditionResponse(com.webank.wedatasphere.qualitis.response.RuleMetricConditionResponse) RuleMetricLevelEnum(com.webank.wedatasphere.qualitis.constant.RuleMetricLevelEnum) HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.webank.wedatasphere.qualitis.entity.User) ExcelRuleMetricListener(com.webank.wedatasphere.qualitis.excel.ExcelRuleMetricListener) ExcelRuleMetric(com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) RuleMetricService(com.webank.wedatasphere.qualitis.service.RuleMetricService) TaskResult(com.webank.wedatasphere.qualitis.entity.TaskResult) DownloadRuleMetricRequest(com.webank.wedatasphere.qualitis.request.DownloadRuleMetricRequest) RoleService(com.webank.wedatasphere.qualitis.service.RoleService) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) HttpServletResponse(javax.servlet.http.HttpServletResponse) RuleMetricTypeConfig(com.webank.wedatasphere.qualitis.entity.RuleMetricTypeConfig) IOException(java.io.IOException) AddRuleMetricRequest(com.webank.wedatasphere.qualitis.request.AddRuleMetricRequest) DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) URLEncoder(java.net.URLEncoder) ExcelSheetName(com.webank.wedatasphere.qualitis.project.constant.ExcelSheetName) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) RuleMetricDepartmentUserDao(com.webank.wedatasphere.qualitis.dao.RuleMetricDepartmentUserDao) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) TaskResultDao(com.webank.wedatasphere.qualitis.dao.TaskResultDao) WriteExcelException(com.webank.wedatasphere.qualitis.rule.exception.WriteExcelException) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) RuleMetricDepartmentUser(com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser) User(com.webank.wedatasphere.qualitis.entity.User) RuleMetricTypeConfig(com.webank.wedatasphere.qualitis.entity.RuleMetricTypeConfig) ArrayList(java.util.ArrayList) RuleMetricConditionResponse(com.webank.wedatasphere.qualitis.response.RuleMetricConditionResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with Department

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

the class RuleMetricServiceImpl method deleteRuleMetric.

@Override
@Transactional(rollbackFor = { Exception.class, RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RuleMetricResponse> deleteRuleMetric(long id) throws UnExpectedRequestException, PermissionDeniedRequestException {
    if (id <= 0) {
        throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
    }
    // Check rule metric existence.
    RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
    if (ruleMetricInDb == null) {
        throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
    }
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to delete rule metric, rule metric ID: [{}], user: [{}]", id, 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("SYS_ADMIN will delete rule metric.");
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null) {
            LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        }
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("DEPARTMENT_ADMIN will delete rule metric.");
        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[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        LOGGER.info("PROJECTOR will delete rule metric.");
        if (!ruleMetricInDb.getLevel().equals(RuleMetricLevelEnum.PERSONAL_METRIC.getCode()) || !ruleMetricInDb.getCreateUser().equals(loginUser.getUserName())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        RuleMetricDepartmentUser ruleMetricDepartmentUser = ruleMetricDepartmentUserDao.findByRuleMetric(ruleMetricInDb);
        if (ruleMetricDepartmentUser != null) {
            LOGGER.info("Rule metric[{}] will be delete.", ruleMetricInDb.toString());
            ruleMetricDepartmentUserDao.delete(ruleMetricDepartmentUser);
        } else {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    }
    ruleMetricDao.delete(ruleMetricInDb);
    return new GeneralResponse<>("200", "{&DELETE_RULE_METRIC_SUCCESSFULLY}", null);
}
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) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Department(com.webank.wedatasphere.qualitis.entity.Department) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Department (com.webank.wedatasphere.qualitis.entity.Department)20 User (com.webank.wedatasphere.qualitis.entity.User)15 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)15 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)14 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)11 ArrayList (java.util.ArrayList)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)7 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)7 Transactional (org.springframework.transaction.annotation.Transactional)7 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4 TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)4 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)3 DepartmentResponse (com.webank.wedatasphere.qualitis.response.DepartmentResponse)2 Date (java.util.Date)2