Search in sources :

Example 26 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class QuizHelper method getSubmissionsCount.

public int getSubmissionsCount() {
    if (submissionsCount == -1) {
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        User user = getCurrentUser();
        if (user.isGuest()) {
            action = NEED_LOGIN;
            return 0;
        }
        long userId = user.getId();
        submissionsCount = 0;
        int page = 1;
        Submissions submissions;
        do {
            try {
                submissions = stepikApiClient.submissions().get().step(getStepNode().getId()).user(userId).page(page).execute();
            } catch (StepikClientException e) {
                logger.warn("Failed get submissions count", e);
                return 0;
            }
            submissionsCount += submissions.getCount();
            page++;
        } while (submissions.getMeta().getHasNext());
    }
    return submissionsCount;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) User(org.stepik.api.objects.users.User) StepikAuthManager.getCurrentUser(org.stepik.core.stepik.StepikAuthManager.getCurrentUser) Submissions(org.stepik.api.objects.submissions.Submissions) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 27 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class QuizHelper method initStepOptions.

void initStepOptions() {
    if (initialized) {
        return;
    }
    initialized = true;
    status = UNCHECKED;
    action = GET_FIRST_ATTEMPT;
    StepikApiClient stepikApiClient = authAndGetStepikApiClient();
    User user = getCurrentUser();
    if (user.isGuest()) {
        action = NEED_LOGIN;
        fail();
        initialized = false;
        return;
    }
    long userId = user.getId();
    try {
        if (!loadAttempt(stepikApiClient, userId)) {
            fail();
            initialized = false;
            return;
        }
        loadSubmission(stepikApiClient, userId);
        done();
        initialized = true;
    } catch (StepikClientException e) {
        logger.warn("Failed init test-step options", e);
        fail();
    }
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) User(org.stepik.api.objects.users.User) StepikAuthManager.getCurrentUser(org.stepik.core.stepik.StepikAuthManager.getCurrentUser) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 28 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class StepHelper method solvedLesson.

public boolean solvedLesson() {
    try {
        StudyNode lesson = stepNode.getParent();
        if (lesson == null) {
            return false;
        }
        StudyObject data = lesson.getData();
        if (data == null) {
            return false;
        }
        String progressId = data.getProgress();
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        Progresses progresses = stepikApiClient.progresses().get().id(progressId).execute();
        return !progresses.isEmpty() && progresses.getFirst().isPassed();
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return false;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Progresses(org.stepik.api.objects.progresses.Progresses) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StepikClientException (org.stepik.api.exceptions.StepikClientException)28 StepikApiClient (org.stepik.api.client.StepikApiClient)12 NotNull (org.jetbrains.annotations.NotNull)10 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)9 CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)6 Submissions (org.stepik.api.objects.submissions.Submissions)5 HashMap (java.util.HashMap)4 Nullable (org.jetbrains.annotations.Nullable)4 Step (org.stepik.api.objects.steps.Step)4 ArrayList (java.util.ArrayList)3 StudyObject (org.stepik.api.objects.StudyObject)3 TokenInfo (org.stepik.api.objects.auth.TokenInfo)3 Course (org.stepik.api.objects.courses.Course)3 Sections (org.stepik.api.objects.sections.Sections)3 Steps (org.stepik.api.objects.steps.Steps)3 User (org.stepik.api.objects.users.User)3 StepikAuthManager.getCurrentUser (org.stepik.core.stepik.StepikAuthManager.getCurrentUser)3 IOException (java.io.IOException)2 ClientResponse (org.stepik.api.client.ClientResponse)2 TransportClient (org.stepik.api.client.TransportClient)2