Search in sources :

Example 6 with Submissions

use of org.stepik.api.objects.submissions.Submissions in project intellij-plugins by StepicOrg.

the class SendAction method checkStepStatus.

public static void checkStepStatus(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, final long submissionId, @NotNull ProgressIndicator indicator) {
    String stepIdString = "id=" + stepNode.getId();
    logger.info("Started check a status for step: " + stepIdString);
    String stepStatus = EVALUATION;
    int timer = 0;
    String hint;
    indicator.setIndeterminate(false);
    Submission currentSubmission = null;
    while (timer < FIVE_MINUTES) {
        try {
            Submissions submission = stepikApiClient.submissions().get().id(submissionId).execute();
            if (!submission.isEmpty()) {
                currentSubmission = submission.getFirst();
                ActionUtils.setupCheckProgress(indicator, currentSubmission, timer);
                stepStatus = currentSubmission.getStatus();
                if (!EVALUATION.equals(stepStatus)) {
                    break;
                }
            }
            Thread.sleep(PERIOD);
            if (Utils.isCanceled()) {
                Metrics.getStepStatusAction(project, stepNode, USER_CANCELED);
                return;
            }
            timer += PERIOD;
        } catch (StepikClientException | InterruptedException e) {
            ActionUtils.notifyError(project, "Error", "Get Status error");
            logger.info("Stop check a status for step: " + stepIdString, e);
            return;
        }
    }
    if (currentSubmission == null) {
        logger.info(String.format("Stop check a status for step: %s without result", stepIdString));
        return;
    }
    MetricsStatus actionStatus = EVALUATION.equals(stepStatus) ? TIME_OVER : SUCCESSFUL;
    Metrics.getStepStatusAction(project, stepNode, actionStatus);
    indicator.setIndeterminate(true);
    indicator.setText("");
    hint = currentSubmission.getHint();
    if (stepNode.getType() == StepType.CODE) {
        notify(project, stepNode, stepStatus, hint);
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        if (!project.isDisposed()) {
            ProjectView.getInstance(project).refresh();
        }
        StepikProjectManager.updateSelection(project);
    });
    logger.info(String.format("Finish check a status for step: %s with status: %s", stepIdString, stepStatus));
}
Also used : Submission(org.stepik.api.objects.submissions.Submission) MetricsStatus(org.stepik.core.metrics.MetricsStatus) Submissions(org.stepik.api.objects.submissions.Submissions) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Aggregations

Submissions (org.stepik.api.objects.submissions.Submissions)6 StepikClientException (org.stepik.api.exceptions.StepikClientException)5 Nullable (org.jetbrains.annotations.Nullable)3 StepikApiClient (org.stepik.api.client.StepikApiClient)2 Submission (org.stepik.api.objects.submissions.Submission)2 User (org.stepik.api.objects.users.User)2 SupportedLanguages (org.stepik.core.SupportedLanguages)2 StepNode (org.stepik.core.courseFormat.StepNode)2 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)2 StepikAuthManager.getCurrentUser (org.stepik.core.stepik.StepikAuthManager.getCurrentUser)2 ProjectView (com.intellij.ide.projectView.ProjectView)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 Project (com.intellij.openapi.project.Project)1 Computable (com.intellij.openapi.util.Computable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1