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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations