Search in sources :

Example 21 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method getAllProjectByUserReal.

@Override
public GetAllResponse<ProjectResponse> getAllProjectByUserReal() {
    // Get username
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    // Find project user in different permissions.
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.CREATOR.getCode());
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    permissions.add(ProjectUserPermissionEnum.OPERATOR.getCode());
    permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
    List<Project> projects = projectUserDao.findByUsernameAndPermission(loginUser, permissions);
    long total = projectUserDao.countByUsernameAndPermission(loginUser, permissions);
    List<ProjectResponse> projectResponses = new ArrayList<>();
    for (Project project : projects) {
        projectResponses.add(new ProjectResponse(project));
    }
    GetAllResponse<ProjectResponse> response = new GetAllResponse<>();
    response.setTotal(total);
    response.setData(projectResponses);
    return response;
}
Also used : Project(com.webank.wedatasphere.qualitis.project.entity.Project) ProjectResponse(com.webank.wedatasphere.qualitis.project.response.ProjectResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 22 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method getAllProjectByUserReal.

@Override
public GetAllResponse<ProjectResponse> getAllProjectByUserReal(PageRequest request, Integer projectType) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    // Get user name
    String userName = HttpUtils.getUserName(httpServletRequest);
    // Paging get project
    int page = request.getPage();
    int size = request.getSize();
    List<ProjectUser> projectUsers = projectUserDao.findByUsernameAndPermissionAndProjectType(userName, projectType, page, size);
    long total = projectUserDao.countByUsernameAndPermissionAndProjectType(userName, projectType);
    List<ProjectResponse> projectResponses = new ArrayList<>();
    for (ProjectUser projectUser : projectUsers) {
        projectResponses.add(new ProjectResponse(projectUser.getProject()));
    }
    GetAllResponse<ProjectResponse> response = new GetAllResponse<>();
    response.setData(projectResponses);
    response.setTotal(total);
    return response;
}
Also used : ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ProjectResponse(com.webank.wedatasphere.qualitis.project.response.ProjectResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 23 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.

the class RuleMetricServiceImpl method getAllRuleMetric.

@Override
public GeneralResponse<GetAllResponse<RuleMetricResponse>> getAllRuleMetric(PageRequest request) throws UnExpectedRequestException {
    PageRequest.checkRequest(request);
    String userName = HttpUtils.getUserName(httpServletRequest);
    LOGGER.info("Start to get all rule metric, page request: [{}], user: [{}]", request.toString(), userName);
    User loginUser = userDao.findByUsername(userName);
    List<UserRole> userRoles = userRoleDao.findByUser(loginUser);
    Integer roleType = roleService.getRoleType(userRoles);
    List<RuleMetric> ruleMetrics = new ArrayList<>();
    long total = 0;
    if (roleType.equals(RoleDefaultTypeEnum.ADMIN.getCode())) {
        LOGGER.info("SYS_ADMIN will get all rule metrics.");
        ruleMetrics.addAll(ruleMetricDao.findAllRuleMetrics(request.getPage(), request.getSize()));
        total = ruleMetricDao.countAllRuleMetrics();
    } 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, request.getPage(), request.getSize()));
        total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, null);
    } 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, request.getPage(), request.getSize()));
        total = ruleMetricDao.countRuleMetrics(RuleMetricLevelEnum.DEFAULT_METRIC.getCode(), departments, loginUser);
    }
    GetAllResponse<RuleMetricResponse> response = new GetAllResponse<>();
    List<RuleMetricResponse> ruleMetricResponses = new ArrayList<>();
    for (RuleMetric ruleMetric : ruleMetrics) {
        ruleMetricResponses.add(new RuleMetricResponse(ruleMetric));
    }
    response.setData(ruleMetricResponses);
    response.setTotal(total);
    return new GeneralResponse<>("200", "{&GET_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) User(com.webank.wedatasphere.qualitis.entity.User) ArrayList(java.util.ArrayList) 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) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 24 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.

the class MetaDataServiceImpl method getUserTableByDbId.

@Override
public GeneralResponse<GetAllResponse<TableInfoDetail>> getUserTableByDbId(GetUserTableByDbIdRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
    // Check Arguments
    checkRequest(request);
    // Get login user
    String userName = HttpUtils.getUserName(httpServletRequest);
    if (StringUtils.isNotBlank(request.getProxyUser())) {
        userName = request.getProxyUser();
    }
    GetTableByUserAndDbRequest getTableByUserAndDbRequest = new GetTableByUserAndDbRequest(userName, request.getStartIndex(), request.getPageSize(), request.getClusterName(), request.getDbName());
    DataInfo<TableInfoDetail> response = metaDataClient.getTableByUserAndDb(getTableByUserAndDbRequest);
    GetAllResponse<TableInfoDetail> result = new GetAllResponse<>();
    result.setTotal(response.getTotalCount());
    result.setData(response.getContent());
    LOGGER.info("Succeed to get table by database. database: {}.{}", request.getClusterName(), request.getDbName());
    return new GeneralResponse<>("200", "{&GET_TABLE_SUCCESSFULLY}", result);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) GetTableByUserAndDbRequest(com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) TableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.TableInfoDetail) CsTableInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.table.CsTableInfoDetail)

Example 25 with GetAllResponse

use of com.webank.wedatasphere.qualitis.response.GetAllResponse in project Qualitis by WeBankFinTech.

the class MetaDataController method getDbsByDataSource.

@GET
@Path("data_source/dbs")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<GetAllResponse<DbInfoDetail>> getDbsByDataSource(@QueryParam("clusterName") String clusterName, @QueryParam("proxyUser") String proxyUser, @QueryParam("dataSourceId") Long dataSourceId) {
    try {
        if (dataSourceId == null || StringUtils.isBlank(clusterName)) {
            throw new UnExpectedRequestException("Request " + "{&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Map response = metaDataService.getDbsByDataSource(clusterName, proxyUser, dataSourceId);
        GetAllResponse allResponse = new GetAllResponse();
        List<String> dbs = (List<String>) response.get("dbs");
        List<DbInfoDetail> dbInfoDetails = new ArrayList<>(CollectionUtils.isEmpty(dbs) ? 0 : dbs.size());
        for (String db : dbs) {
            DbInfoDetail dbInfoDetail = new DbInfoDetail(db);
            dbInfoDetails.add(dbInfoDetail);
        }
        allResponse.setTotal(CollectionUtils.isEmpty(dbInfoDetails) ? 0 : dbInfoDetails.size());
        allResponse.setData(dbInfoDetails);
        return new GeneralResponse<>("200", "{&GET_DB_SUCCESSFULLY}", allResponse);
    } catch (MetaDataAcquireFailedException e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", e.getMessage(), null);
    } catch (UnExpectedRequestException e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", e.getMessage(), null);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new GeneralResponse<>("500", "{&FAILED_TO_GET_DATABASE_BY_CLUSTER}", null);
    }
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) DbInfoDetail(com.webank.wedatasphere.qualitis.metadata.response.db.DbInfoDetail) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) ArrayList(java.util.ArrayList) List(java.util.List) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Aggregations

GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)28 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)26 ArrayList (java.util.ArrayList)21 User (com.webank.wedatasphere.qualitis.entity.User)9 List (java.util.List)8 Application (com.webank.wedatasphere.qualitis.entity.Application)5 Department (com.webank.wedatasphere.qualitis.entity.Department)5 Task (com.webank.wedatasphere.qualitis.entity.Task)5 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)5 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Map (java.util.Map)4 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)3 Project (com.webank.wedatasphere.qualitis.project.entity.Project)3 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)3 RuleTemplateResponse (com.webank.wedatasphere.qualitis.rule.response.RuleTemplateResponse)3 ClusterInfoDao (com.webank.wedatasphere.qualitis.dao.ClusterInfoDao)2 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)2 ProxyUser (com.webank.wedatasphere.qualitis.entity.ProxyUser)2 RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)2