use of org.stepik.api.objects.units.Units 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.units.Units 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();
}
use of org.stepik.api.objects.units.Units 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;
}
Aggregations