Search in sources :

Example 1 with Lesson

use of org.stepik.api.objects.lessons.Lesson 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 2 with Lesson

use of org.stepik.api.objects.lessons.Lesson in project intellij-plugins by StepicOrg.

the class Utils method getCompoundUnitLessonStudyObject.

@NotNull
private static CompoundUnitLesson getCompoundUnitLessonStudyObject(@NotNull StepikApiClient stepikApiClient, long unitId, long lessonId) {
    Units units = null;
    if (unitId != 0) {
        try {
            units = stepikApiClient.units().get().id(unitId).execute();
        } catch (StepikClientException e) {
            logger.warn(e);
            units = new Units();
        }
    }
    Unit unit = null;
    if (unitId != 0 && !units.isEmpty()) {
        unit = units.getFirst();
    }
    Lesson lesson = getLesson(lessonId, stepikApiClient);
    return lesson != null ? new CompoundUnitLesson(unit, lesson) : new CompoundUnitLesson();
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Unit(org.stepik.api.objects.units.Unit) StepikClientException(org.stepik.api.exceptions.StepikClientException) Lesson(org.stepik.api.objects.lessons.Lesson) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Units(org.stepik.api.objects.units.Units) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Lesson

use of org.stepik.api.objects.lessons.Lesson in project intellij-plugins by StepicOrg.

the class StudyNodeFactory method createTree.

public static StudyNode createTree(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StudyObject data) {
    StudyNode root = null;
    if (data instanceof Course) {
        root = new CourseNode(project, stepikApiClient, (Course) data);
    } else if (data instanceof Section) {
        root = new SectionNode(project, stepikApiClient, (Section) data);
    } else if (data instanceof Lesson) {
        CompoundUnitLesson compoundData = new CompoundUnitLesson(null, (Lesson) data);
        root = new LessonNode(project, stepikApiClient, compoundData);
    } else if (data instanceof CompoundUnitLesson) {
        root = new LessonNode(project, stepikApiClient, (CompoundUnitLesson) data);
    } else if (data instanceof Step) {
        root = new StepNode(project, stepikApiClient, (Step) data);
    }
    return root;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Step(org.stepik.api.objects.steps.Step) Course(org.stepik.api.objects.courses.Course) Section(org.stepik.api.objects.sections.Section) Lesson(org.stepik.api.objects.lessons.Lesson) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson)

Aggregations

CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)3 Lesson (org.stepik.api.objects.lessons.Lesson)3 StepikClientException (org.stepik.api.exceptions.StepikClientException)2 NotNull (org.jetbrains.annotations.NotNull)1 Course (org.stepik.api.objects.courses.Course)1 Lessons (org.stepik.api.objects.lessons.Lessons)1 Section (org.stepik.api.objects.sections.Section)1 Step (org.stepik.api.objects.steps.Step)1 Unit (org.stepik.api.objects.units.Unit)1 Units (org.stepik.api.objects.units.Units)1