Search in sources :

Example 6 with CompoundUnitLesson

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

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

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

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

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

CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)11 StepikClientException (org.stepik.api.exceptions.StepikClientException)6 Lesson (org.stepik.api.objects.lessons.Lesson)3 Section (org.stepik.api.objects.sections.Section)3 Unit (org.stepik.api.objects.units.Unit)3 Units (org.stepik.api.objects.units.Units)3 Test (org.junit.Test)2 Lessons (org.stepik.api.objects.lessons.Lessons)2 Step (org.stepik.api.objects.steps.Step)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 Course (org.stepik.api.objects.courses.Course)1 Sections (org.stepik.api.objects.sections.Sections)1 Steps (org.stepik.api.objects.steps.Steps)1 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)1