Search in sources :

Example 6 with StepikClientException

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

the class StepNode method getCourseId.

@Override
public long getCourseId(@NotNull StepikApiClient stepikApiClient) {
    StudyNode parent = getParent();
    if (parent != null) {
        return parent.getCourseId(stepikApiClient);
    }
    if (courseId != 0) {
        return courseId;
    }
    Step data = getData();
    if (data == null) {
        return 0;
    }
    int lessonId = data.getLesson();
    if (lessonId == 0) {
        return 0;
    }
    try {
        Units units = stepikApiClient.units().get().lesson(lessonId).execute();
        if (units.isEmpty()) {
            return 0;
        }
        LessonNode lessonNode = new LessonNode();
        CompoundUnitLesson lessonData = lessonNode.getData();
        if (lessonData != null) {
            lessonData.setUnit(units.getFirst());
        }
        courseId = lessonNode.getCourseId(stepikApiClient);
        return courseId;
    } catch (StepikClientException ignored) {
    }
    return 0;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Step(org.stepik.api.objects.steps.Step) StepikClientException(org.stepik.api.exceptions.StepikClientException) Units(org.stepik.api.objects.units.Units)

Example 7 with StepikClientException

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

the class StepNode method loadData.

@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
    try {
        Steps steps = stepikApiClient.steps().get().id(id).execute();
        Step data;
        if (!steps.isEmpty()) {
            data = steps.getFirst();
        } else {
            data = new Step();
            data.setId(id);
        }
        Step oldData = this.getData();
        setData(data);
        return oldData == null || !oldData.getUpdateDate().equals(data.getUpdateDate());
    } catch (StepikClientException logged) {
        logger.warn(String.format("Failed step lesson data id=%d", id), logged);
    }
    return true;
}
Also used : Steps(org.stepik.api.objects.steps.Steps) Step(org.stepik.api.objects.steps.Step) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 8 with StepikClientException

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

the class LessonNode method loadData.

@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
    try {
        CompoundUnitLesson data = getData();
        if (data == null) {
            return true;
        }
        String updateDate = data.getUpdateDate();
        Lessons lessons = stepikApiClient.lessons().get().id(id).execute();
        Lesson lesson;
        if (!lessons.isEmpty()) {
            lesson = lessons.getFirst();
        } else {
            lesson = new Lesson();
            lesson.setId(id);
        }
        data.setLesson(lesson);
        return !updateDate.equals(data.getUpdateDate());
    } catch (StepikClientException logged) {
        logger.warn(String.format("Failed load lesson data id=%d", id), logged);
    }
    return true;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Lessons(org.stepik.api.objects.lessons.Lessons) Lesson(org.stepik.api.objects.lessons.Lesson) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 9 with StepikClientException

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

the class LessonNode method getChildDataList.

@Override
protected List<Step> getChildDataList(@NotNull StepikApiClient stepikApiClient) {
    Steps steps = new Steps();
    try {
        CompoundUnitLesson data = getData();
        List<Long> stepsIds = data != null ? data.getLesson().getSteps() : Collections.emptyList();
        if (!stepsIds.isEmpty()) {
            steps = stepikApiClient.steps().get().id(stepsIds).execute();
        }
    } catch (StepikClientException logged) {
        logger.warn("A lesson initialization don't is fully", logged);
    }
    return steps.getSteps();
}
Also used : Steps(org.stepik.api.objects.steps.Steps) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 10 with StepikClientException

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

the class FreeAnswerQuizHelper method isFrozen.

private boolean isFrozen() {
    if (!needReview()) {
        return true;
    }
    Step data = getStepNode().getData();
    if (data == null) {
        return true;
    }
    int instructionId = data.getInstruction();
    if (instructionId == 0) {
        return true;
    }
    StepikApiClient stepikClient = authAndGetStepikApiClient();
    if (!isAuthenticated()) {
        return true;
    }
    try {
        Instructions instructions = stepikClient.instructions().get().id(instructionId).execute();
        if (!instructions.isEmpty()) {
            Instruction instruction = instructions.getFirst();
            return instruction.isFrozen();
        }
    } catch (StepikClientException e) {
        logger.warn(e);
    }
    return true;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Instructions(org.stepik.api.objects.instructions.Instructions) Step(org.stepik.api.objects.steps.Step) Instruction(org.stepik.api.objects.instructions.Instruction) StepikClientException(org.stepik.api.exceptions.StepikClientException)

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