Search in sources :

Example 1 with Sections

use of org.stepik.api.objects.sections.Sections in project intellij-plugins by StepicOrg.

the class LessonNode method getCourseId.

@Override
public long getCourseId(@NotNull StepikApiClient stepikApiClient) {
    StudyNode parent = getParent();
    if (parent != null) {
        return parent.getCourseId(stepikApiClient);
    }
    if (courseId != 0) {
        return courseId;
    }
    CompoundUnitLesson data = getData();
    int sectionId = data != null ? data.getUnit().getSection() : 0;
    if (sectionId == 0) {
        return 0;
    }
    try {
        Sections sections = stepikApiClient.sections().get().id(sectionId).execute();
        if (sections.isEmpty()) {
            return 0;
        }
        courseId = sections.getFirst().getCourse();
        return courseId;
    } catch (StepikClientException ignored) {
    }
    return 0;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Sections(org.stepik.api.objects.sections.Sections) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 2 with Sections

use of org.stepik.api.objects.sections.Sections in project intellij-plugins by StepicOrg.

the class SectionNode method loadData.

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

Example 3 with Sections

use of org.stepik.api.objects.sections.Sections in project intellij-plugins by StepicOrg.

the class CourseNode method getChildDataList.

@Override
protected List<Section> getChildDataList(@NotNull StepikApiClient stepikApiClient) {
    Sections sections = new Sections();
    try {
        Course data = getData();
        List<Long> sectionsIds = data != null ? getData().getSections() : Collections.emptyList();
        if (!sectionsIds.isEmpty()) {
            sections = stepikApiClient.sections().get().id(sectionsIds).execute();
        }
    } catch (StepikClientException logged) {
        logger.warn("A course initialization don't is fully", logged);
    }
    return sections.getSections();
}
Also used : Sections(org.stepik.api.objects.sections.Sections) Course(org.stepik.api.objects.courses.Course) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Aggregations

StepikClientException (org.stepik.api.exceptions.StepikClientException)3 Sections (org.stepik.api.objects.sections.Sections)3 Course (org.stepik.api.objects.courses.Course)1 CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)1 Section (org.stepik.api.objects.sections.Section)1