Search in sources :

Example 1 with Lessons

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

use of org.stepik.api.objects.lessons.Lessons 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)

Aggregations

StepikClientException (org.stepik.api.exceptions.StepikClientException)2 CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)2 Lessons (org.stepik.api.objects.lessons.Lessons)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Lesson (org.stepik.api.objects.lessons.Lesson)1 Section (org.stepik.api.objects.sections.Section)1 Unit (org.stepik.api.objects.units.Unit)1 Units (org.stepik.api.objects.units.Units)1