Search in sources :

Example 1 with ApplicationResultResponse

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

the class OuterExecutionServiceImpl method getApplicationResult.

@Override
public GeneralResponse<?> getApplicationResult(String applicationId) throws UnExpectedRequestException {
    // Find application by applicationId
    Application applicationInDb = applicationDao.findById(applicationId);
    if (applicationInDb == null) {
        throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_EXIST}", applicationId));
    }
    Integer passNum = 0;
    Integer failedNum = 0;
    Integer notPassNum = 0;
    StringBuilder passMessage = new StringBuilder();
    StringBuilder failedMessage = new StringBuilder();
    StringBuilder notPassMessage = new StringBuilder();
    passMessage.append("The rules following below are pass(以下规则已通过校验): [");
    failedMessage.append("The rules following below are failed(以下规则已失败): [");
    notPassMessage.append("The rules following below are failed(以下规则未通过校验): [");
    // Find all tasks by application
    List<Task> tasks = taskDao.findByApplication(applicationInDb);
    // Find task rule simple in all tasks
    for (Task task : tasks) {
        // Add failed num, pass num if task status equals to Succeed, Failed
        if (task.getStatus().equals(TaskStatusEnum.FAILED.getCode())) {
            failedNum += task.getTaskRuleSimples().size();
            generateFailedMessage(task, failedMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.PASS_CHECKOUT.getCode())) {
            passNum += task.getTaskRuleSimples().size();
            generatePassMessage(task, passMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.FAIL_CHECKOUT.getCode())) {
            // Find not pass task if task status equals to failed_checkout
            for (TaskRuleSimple taskRuleSimple : task.getTaskRuleSimples()) {
                Boolean isPass = true;
                for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleSimple.getTaskRuleAlarmConfigList()) {
                    if (taskRuleAlarmConfig.getStatus().equals(AlarmConfigStatusEnum.NOT_PASS.getCode())) {
                        isPass = false;
                        break;
                    }
                }
                if (isPass) {
                    passNum++;
                    passMessage.append(taskRuleSimple.getRuleName()).append(", ");
                } else {
                    notPassNum++;
                    notPassMessage.append(taskRuleSimple.getRuleName()).append(", ");
                }
            }
        } else {
            throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_FINISHED_YET}", applicationId));
        }
    }
    passMessage.append("]").append(System.lineSeparator());
    failedMessage.append("]").append(System.lineSeparator());
    notPassMessage.append("]").append(System.lineSeparator());
    String resultMessage = passMessage.toString() + failedMessage.toString() + notPassMessage.toString();
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATION_RESULT}", new ApplicationResultResponse(passNum, failedNum, notPassNum, resultMessage));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ApplicationResultResponse(com.webank.wedatasphere.qualitis.response.ApplicationResultResponse) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) Application(com.webank.wedatasphere.qualitis.entity.Application) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)

Aggregations

Application (com.webank.wedatasphere.qualitis.entity.Application)1 Task (com.webank.wedatasphere.qualitis.entity.Task)1 TaskRuleAlarmConfig (com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig)1 TaskRuleSimple (com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 ApplicationResultResponse (com.webank.wedatasphere.qualitis.response.ApplicationResultResponse)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1