Search in sources :

Example 1 with Section

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

the class Utils method getLessonStudyObject.

private static StudyObject getLessonStudyObject(long lessonId, long unitId) {
    StepikApiClient stepikApiClient = authAndGetStepikApiClient();
    CompoundUnitLesson unitLesson = getCompoundUnitLessonStudyObject(stepikApiClient, unitId, lessonId);
    Unit unit = unitLesson.getUnit();
    if (unit.getId() != 0) {
        Section section = getSectionStudyObject(stepikApiClient, unit.getSection());
        if (section != null) {
            return getCourseStudyObject(section.getCourse());
        }
    }
    return unitLesson;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Unit(org.stepik.api.objects.units.Unit) Section(org.stepik.api.objects.sections.Section)

Example 2 with Section

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

the class SectionNode method getChildDataList.

@Override
protected List<CompoundUnitLesson> getChildDataList(@NotNull StepikApiClient stepikApiClient) {
    List<CompoundUnitLesson> objects = new ArrayList<>();
    try {
        List<Long> unitsIds;
        Section data = getData();
        unitsIds = data != null ? data.getUnits() : Collections.emptyList();
        if (!unitsIds.isEmpty()) {
            int size = unitsIds.size();
            Long[] list = unitsIds.toArray(new Long[size]);
            int start = 0;
            int end;
            while (start < size) {
                end = start + 20;
                if (end > size) {
                    end = size;
                }
                Long[] part = Arrays.copyOfRange(list, start, end);
                start = end;
                Units units = stepikApiClient.units().get().id(part).execute();
                Map<Long, Unit> unitsMap = new HashMap<>();
                List<Long> lessonsIds = new ArrayList<>();
                units.getUnits().forEach(unit -> {
                    long lessonId = unit.getLesson();
                    lessonsIds.add(lessonId);
                    unitsMap.put(lessonId, unit);
                });
                Lessons lessons = stepikApiClient.lessons().get().id(lessonsIds).execute();
                lessons.getLessons().forEach(lesson -> objects.add(new CompoundUnitLesson(unitsMap.get(lesson.getId()), lesson)));
            }
        }
    } catch (StepikClientException logged) {
        logger.warn("A section initialization don't is fully", logged);
    }
    return objects;
}
Also used : HashMap(java.util.HashMap) Lessons(org.stepik.api.objects.lessons.Lessons) ArrayList(java.util.ArrayList) Unit(org.stepik.api.objects.units.Unit) Section(org.stepik.api.objects.sections.Section) StepikClientException(org.stepik.api.exceptions.StepikClientException) Units(org.stepik.api.objects.units.Units) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson)

Example 3 with Section

use of org.stepik.api.objects.sections.Section 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 4 with Section

use of org.stepik.api.objects.sections.Section 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

Section (org.stepik.api.objects.sections.Section)4 CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)3 StepikClientException (org.stepik.api.exceptions.StepikClientException)2 Unit (org.stepik.api.objects.units.Unit)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 Course (org.stepik.api.objects.courses.Course)1 Lesson (org.stepik.api.objects.lessons.Lesson)1 Lessons (org.stepik.api.objects.lessons.Lessons)1 Sections (org.stepik.api.objects.sections.Sections)1 Step (org.stepik.api.objects.steps.Step)1 Units (org.stepik.api.objects.units.Units)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1