Search in sources :

Example 1 with StepikSubmissionsGetQuery

use of org.stepik.api.queries.submissions.StepikSubmissionsGetQuery in project intellij-plugins by StepicOrg.

the class QuizHelper method loadSubmission.

private void loadSubmission(StepikApiClient stepikApiClient, long userId) {
    long attemptId = attempt.getId();
    StepNode stepNode = getStepNode();
    StepikSubmissionsGetQuery query = stepikApiClient.submissions().get().order(Order.DESC).user(userId).step(stepNode.getId());
    if (!useLastSubmission) {
        query.attempt(attemptId);
    }
    Submissions submissions = query.execute();
    modified = false;
    if (!submissions.isEmpty()) {
        submission = submissions.getFirst();
        boolean lastSubmission = submission.getId() == stepNode.getLastSubmissionId();
        boolean outdated = stepNode.getLastReplyTime().after(submission.getTime());
        if (lastSubmission && outdated) {
            reply = stepNode.getLastReply();
            modified = !submission.getReply().equals(reply);
        } else {
            reply = submission.getReply();
            stepNode.setLastReply(submission.getReply());
            stepNode.setLastSubmissionId(submission.getId());
        }
        if (attemptId == submission.getAttempt()) {
            status = submission.getStatus();
        }
        if (ACTIVE.equals(attempt.getStatus()) && status.equals("correct")) {
            action = GET_ATTEMPT;
        }
        stepNode.setStatus(StudyStatus.of(status));
    } else {
        reply = stepNode.getLastReply();
        modified = true;
    }
}
Also used : StepNode(org.stepik.core.courseFormat.StepNode) Submissions(org.stepik.api.objects.submissions.Submissions) StepikSubmissionsGetQuery(org.stepik.api.queries.submissions.StepikSubmissionsGetQuery)

Aggregations

Submissions (org.stepik.api.objects.submissions.Submissions)1 StepikSubmissionsGetQuery (org.stepik.api.queries.submissions.StepikSubmissionsGetQuery)1 StepNode (org.stepik.core.courseFormat.StepNode)1