Search in sources :

Example 1 with CompoundUnitLesson

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

the class SerializationTest method serializeLessonNode.

@Test
public void serializeLessonNode() throws IOException, SAXException, ParserConfigurationException, InstantiationException, IllegalAccessException {
    LessonNode node = new LessonNode();
    CompoundUnitLesson data = node.getData();
    assertNotNull(data);
    data.getLesson();
    data.getUnit();
    serialize("LessonNode", node);
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Test(org.junit.Test)

Example 2 with CompoundUnitLesson

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

the class SerializationTest method serializeSectionNode.

@Test
public void serializeSectionNode() throws IOException, SAXException, ParserConfigurationException, InstantiationException, IllegalAccessException {
    SectionNode node = new SectionNode();
    node.getData();
    LessonNode lessonNode = new LessonNode();
    lessonNode.setParent(node);
    CompoundUnitLesson data = lessonNode.getData();
    assertNotNull(data);
    data.getLesson();
    data.getUnit();
    node.getChildren().add(lessonNode);
    serialize("SectionNode", node);
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Test(org.junit.Test)

Example 3 with CompoundUnitLesson

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

the class StepNode method getAssignment.

public Long getAssignment() {
    if (assignment == null) {
        StudyNode parent = getParent();
        if (parent != null && parent instanceof LessonNode) {
            LessonNode lesson = (LessonNode) parent;
            CompoundUnitLesson data = lesson.getData();
            if (data != null) {
                List<Long> steps = data.getLesson().getSteps();
                steps.sort(Long::compareTo);
                int index;
                if ((index = steps.indexOf(getId())) != -1) {
                    List<Long> assignments = data.getUnit().getAssignments();
                    if (index < assignments.size()) {
                        assignment = assignments.get(index);
                    }
                }
            }
        }
    }
    return assignment;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson)

Example 4 with CompoundUnitLesson

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

the class StepNode method getCourseId.

@Override
public long getCourseId(@NotNull StepikApiClient stepikApiClient) {
    StudyNode parent = getParent();
    if (parent != null) {
        return parent.getCourseId(stepikApiClient);
    }
    if (courseId != 0) {
        return courseId;
    }
    Step data = getData();
    if (data == null) {
        return 0;
    }
    int lessonId = data.getLesson();
    if (lessonId == 0) {
        return 0;
    }
    try {
        Units units = stepikApiClient.units().get().lesson(lessonId).execute();
        if (units.isEmpty()) {
            return 0;
        }
        LessonNode lessonNode = new LessonNode();
        CompoundUnitLesson lessonData = lessonNode.getData();
        if (lessonData != null) {
            lessonData.setUnit(units.getFirst());
        }
        courseId = lessonNode.getCourseId(stepikApiClient);
        return courseId;
    } catch (StepikClientException ignored) {
    }
    return 0;
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Step(org.stepik.api.objects.steps.Step) StepikClientException(org.stepik.api.exceptions.StepikClientException) Units(org.stepik.api.objects.units.Units)

Example 5 with CompoundUnitLesson

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

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