Search in sources :

Example 11 with Task

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

the class ApplicationServiceImpl method filterProjectApplication.

@Override
public GeneralResponse<?> filterProjectApplication(FilterProjectRequest request) throws UnExpectedRequestException {
    // Check arguments
    FilterProjectRequest.checkRequest(request);
    Long userId = HttpUtils.getUserId(httpServletRequest);
    User user = userDao.findById(userId);
    Integer page = request.getPage();
    Integer size = request.getSize();
    Long projectId = request.getProjectId();
    int total = applicationDao.countByCreateUserAndProject(user.getUserName(), projectId).intValue();
    List<Application> applicationList = applicationDao.findByCreateUserAndProject(user.getUserName(), projectId, page, size);
    GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
    List<ApplicationResponse> applicationResponses = new ArrayList<>();
    for (Application application : applicationList) {
        List<Task> tasks = taskDao.findByApplication(application);
        ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
        if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
            response.setKillOption(true);
        } else {
            response.setKillOption(false);
        }
        applicationResponses.add(response);
    }
    getAllResponse.setData(applicationResponses);
    getAllResponse.setTotal(total);
    List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
    LOGGER.info("Succeed to find applications. size: {}, id of applications: {}", total, applicationIdList);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) User(com.webank.wedatasphere.qualitis.entity.User) ApplicationResponse(com.webank.wedatasphere.qualitis.response.ApplicationResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Application(com.webank.wedatasphere.qualitis.entity.Application)

Example 12 with Task

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

the class ApplicationServiceImpl method writeExcelFile.

private void writeExcelFile(File tmpFile, List<String> tables, UploadResultRequest request) throws UnExpectedRequestException {
    int sheetNo = 1;
    OutputStream tmpOutputStream = null;
    try {
        Path parentPath = Paths.get(tmpFile.getParent());
        if (Files.notExists(parentPath)) {
            tmpFile.getParentFile().mkdirs();
        }
        if (!tmpFile.exists()) {
            LOGGER.info("Start to create local file.");
            tmpFile.createNewFile();
        }
        tmpOutputStream = new FileOutputStream(tmpFile);
        ExcelWriter writer = new ExcelWriter(tmpOutputStream, ExcelTypeEnum.XLSX, true);
        // Find task with the start time and end time.
        for (String tableName : tables) {
            List<Task> tasks = taskDao.findWithSubmitTimeAndDatasource(request.getStartTime(), request.getEndTime(), request.getClusterName(), request.getDatabaseName(), tableName);
            List<TaskRuleSimple> taskRuleSimples = tasks.stream().map(Task::getTaskRuleSimples).flatMap(taskRuleSimpleSet -> taskRuleSimpleSet.stream()).distinct().collect(Collectors.toList());
            // Generate analysis result excel
            List<ExcelResult> results = new ArrayList<>(taskRuleSimples.size());
            for (TaskRuleSimple taskRuleSimple : taskRuleSimples) {
                ExcelResult excelResult = new ExcelResult();
                excelResult.setRuleName(taskRuleSimple.getRuleName());
                excelResult.setClusterName(request.getClusterName());
                excelResult.setDatabaseName(request.getDatabaseName());
                excelResult.setTableName(tableName);
                excelResult.setBeginTime(taskRuleSimple.getTask().getBeginTime());
                excelResult.setEndTime(taskRuleSimple.getTask().getEndTime());
                StringBuffer checkTemplateStr = new StringBuffer();
                StringBuffer resultStr = new StringBuffer();
                joinAlarmConfig(results, taskRuleSimple, excelResult, request, checkTemplateStr, resultStr);
                results.add(excelResult);
            }
            Sheet templateSheet = new Sheet(sheetNo++, 0, ExcelResult.class);
            templateSheet.setSheetName(tableName + "-" + ExcelSheetName.ANALYSIS_NAME);
            writer.write(results, templateSheet);
        }
        writer.finish();
    } catch (FileNotFoundException e) {
        LOGGER.error(e.getMessage(), e);
        throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        throw new UnExpectedRequestException("{&FAILED_TO_CREATE_LOCAL_FILE}");
    } finally {
        try {
            tmpOutputStream.close();
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}
Also used : Path(java.nio.file.Path) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ExcelResult(com.webank.wedatasphere.qualitis.excel.ExcelResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ExcelWriter(com.alibaba.excel.ExcelWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple) Sheet(com.alibaba.excel.metadata.Sheet)

Example 13 with Task

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

the class IndexServiceImpl method getTodaySubmitApplications.

@Override
public IndexApplicationTodayResponse getTodaySubmitApplications(String username, PageRequest pageRequest) {
    // Find applications submitted today
    String today = DateFormatUtils.format(new Date(), DATE_FORMAT_PATTERN);
    List<Application> applications = getUserApplications(username, today, pageRequest);
    if (applications == null || applications.isEmpty()) {
        LOGGER.info("[Home overview]user:{},date:{},The user and the task submitted by the specified date were not found.", username, today);
        return null;
    }
    // Get total num of applications today
    long totalNum = countUserApplications(username, today);
    // Get successful total num of applications today
    long totalSuccNum = countUserSuccApplications(username, today);
    // Get failed total num of applications today
    long totalFailNum = countUserFailApplications(username, today);
    // Get not pass total num of applications today
    long totalFailCheckNum = countUserFailCheckApplications(username, today);
    LOGGER.info("[Home overview]user:{},date:{},Find {} tasks submitted by the user's specified date, for a total of {}.", username, today, applications.size(), totalNum);
    List<IndexApplicationResponse> applicationResponses = new ArrayList<>();
    for (Application application : applications) {
        List<Task> tasks = taskDao.findByApplication(application);
        IndexApplicationResponse applicationResponse = new IndexApplicationResponse(application, tasks);
        applicationResponses.add(applicationResponse);
    }
    return new IndexApplicationTodayResponse(applicationResponses, totalNum, totalSuccNum, totalFailNum, totalFailCheckNum);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) IndexApplicationTodayResponse(com.webank.wedatasphere.qualitis.response.IndexApplicationTodayResponse) IndexApplicationResponse(com.webank.wedatasphere.qualitis.response.IndexApplicationResponse) ArrayList(java.util.ArrayList) Application(com.webank.wedatasphere.qualitis.entity.Application) Date(java.util.Date)

Example 14 with Task

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

the class ApplicationServiceImpl method filterApplicationId.

/**
 * Find application by applicationId
 * @param applicationId
 * @return
 */
@Override
public GeneralResponse<?> filterApplicationId(String applicationId) {
    Long userId = HttpUtils.getUserId(httpServletRequest);
    // Find applications by user
    User user = userDao.findById(userId);
    List<Application> applicationList;
    applicationList = applicationDao.findByCreateUserAndId(user.getUserName(), applicationId);
    if (applicationList == null) {
        LOGGER.info("User: {} , Not find applications with applicationId: {}", user.getUserName(), applicationId);
        return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS_BUT_FIND_NO_RESULTS}", null);
    }
    GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
    List<ApplicationResponse> applicationResponses = new ArrayList<>();
    for (Application application : applicationList) {
        List<Task> tasks = taskDao.findByApplication(application);
        ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
        if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
            response.setKillOption(true);
        } else {
            response.setKillOption(false);
        }
        applicationResponses.add(response);
    }
    getAllResponse.setData(applicationResponses);
    getAllResponse.setTotal(applicationList.size());
    List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
    LOGGER.info("User: {}, find {} applications with like applicationId : {},Id of applications: {}", user.getUserName(), applicationList.size(), applicationId, applicationIdList);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) User(com.webank.wedatasphere.qualitis.entity.User) ApplicationResponse(com.webank.wedatasphere.qualitis.response.ApplicationResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Application(com.webank.wedatasphere.qualitis.entity.Application)

Example 15 with Task

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

the class ApplicationServiceImpl method filterAdvanceApplication.

@Override
public GeneralResponse<?> filterAdvanceApplication(FilterAdvanceRequest request) {
    Long userId = HttpUtils.getUserId(httpServletRequest);
    // Find applications by user
    User user = userDao.findById(userId);
    List<Application> applicationList;
    long total = 0;
    // If application ID is not empty, just return application which ID like the input string.
    if (StringUtils.isNotBlank(request.getApplicationId())) {
        applicationList = applicationDao.findByCreateUserAndId(user.getUserName(), request.getApplicationId());
        total = applicationList.size();
    } else if (StringUtils.isNotBlank(request.getClusterName())) {
        if (request.getStatus() != null) {
            if (request.getStatus().equals(ApplicationStatusEnum.FINISHED.getCode())) {
                request.setStatus(TaskStatusEnum.PASS_CHECKOUT.getCode());
            } else if (request.getStatus().equals(ApplicationStatusEnum.NOT_PASS.getCode())) {
                request.setStatus(TaskStatusEnum.FAIL_CHECKOUT.getCode());
            } else if (request.getStatus().equals(ApplicationStatusEnum.SUCCESSFUL_CREATE_APPLICATION.getCode())) {
                request.setStatus(TaskStatusEnum.INITED.getCode());
            } else if (request.getStatus().equals(ApplicationStatusEnum.RUNNING.getCode())) {
                request.setStatus(TaskStatusEnum.RUNNING.getCode());
            } else if (request.getStatus() == 0) {
                request.setStatus(null);
            }
        }
        // If data source is not empty, it will be used as the basic filter.
        applicationList = applicationDao.findApplicationByAdavnceConditionsWithDatasource(user.getUserName(), request.getClusterName(), request.getDatabaseName(), request.getTableName(), request.getProjectId(), request.getStatus(), request.getCommentType(), request.getStartTime(), request.getEndTime(), request.getPage(), request.getSize());
        total = applicationDao.countApplicationByAdavnceConditionsWithDatasource(user.getUserName(), request.getClusterName(), request.getDatabaseName(), request.getTableName(), request.getProjectId(), request.getStatus(), request.getCommentType(), request.getStartTime(), request.getEndTime());
    } else {
        applicationList = applicationDao.findApplicationByAdavnceConditions(user.getUserName(), request.getProjectId(), request.getStatus(), request.getCommentType(), request.getStartTime(), request.getEndTime(), request.getPage(), request.getSize());
        total = applicationDao.countApplicationByAdavnceConditions(user.getUserName(), request.getProjectId(), request.getStatus(), request.getCommentType(), request.getStartTime(), request.getEndTime());
    }
    GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
    List<ApplicationResponse> applicationResponses = new ArrayList<>();
    for (Application application : applicationList) {
        List<Task> tasks = taskDao.findByApplication(application);
        ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
        if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
            response.setKillOption(true);
        } else {
            response.setKillOption(false);
        }
        applicationResponses.add(response);
    }
    getAllResponse.setData(applicationResponses);
    getAllResponse.setTotal(total);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) User(com.webank.wedatasphere.qualitis.entity.User) ApplicationResponse(com.webank.wedatasphere.qualitis.response.ApplicationResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Application(com.webank.wedatasphere.qualitis.entity.Application)

Aggregations

Task (com.webank.wedatasphere.qualitis.entity.Task)21 Application (com.webank.wedatasphere.qualitis.entity.Application)12 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)12 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)11 ArrayList (java.util.ArrayList)11 TaskRuleSimple (com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)7 Date (java.util.Date)6 DataQualityTask (com.webank.wedatasphere.qualitis.bean.DataQualityTask)5 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)5 TaskDataSource (com.webank.wedatasphere.qualitis.entity.TaskDataSource)5 TaskResult (com.webank.wedatasphere.qualitis.entity.TaskResult)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)5 TaskSubmitResult (com.webank.wedatasphere.qualitis.bean.TaskSubmitResult)4 TaskRuleAlarmConfig (com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)4 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)4 TaskRule (com.webank.wedatasphere.qualitis.bean.TaskRule)3 User (com.webank.wedatasphere.qualitis.entity.User)3 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)3 ExcelWriter (com.alibaba.excel.ExcelWriter)2