use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class Node method getStatus.
@NotNull
@Override
public StudyStatus getStatus() {
if (isUnknownStatus()) {
status = UNCHECKED;
executor.execute(() -> {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
if (!isAuthenticated()) {
return;
}
Map<String, StudyNode> progressMap = new HashMap<>();
Node.this.getChildren().stream().filter(StudyNode::isUnknownStatus).forEach(child -> {
DC data = child.getData();
if (data != null) {
progressMap.put(data.getProgress(), child);
}
});
D data = Node.this.getData();
if (data != null) {
String progressId = data.getProgress();
if (progressId != null) {
progressMap.put(progressId, Node.this);
}
Set<String> progressIds = progressMap.keySet();
if (!progressIds.isEmpty()) {
int size = progressIds.size();
String[] list = progressIds.toArray(new String[size]);
int start = 0;
int end;
while (start < size) {
end = start + 20;
if (end > size) {
end = size;
}
String[] part = Arrays.copyOfRange(list, start, end);
start = end;
Progresses progresses;
try {
progresses = stepikApiClient.progresses().get().id(part).execute();
} catch (StepikClientException e) {
logger.warn(e);
return;
}
progresses.getItems().forEach(progress -> {
String id = progress.getId();
StudyNode node = progressMap.get(id);
if (progress.isPassed()) {
node.setRawStatus(SOLVED);
}
});
}
}
}
ApplicationManager.getApplication().invokeLater(() -> {
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
});
});
}
return status;
}
use of org.stepik.api.exceptions.StepikClientException 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;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class SectionNode method loadData.
@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
try {
Sections sections = stepikApiClient.sections().get().id(id).execute();
Section data;
if (!sections.isEmpty()) {
data = sections.getFirst();
} else {
data = new Section();
data.setId(id);
}
Section oldData = this.getData();
setData(data);
return oldData == null || !oldData.getUpdateDate().equals(data.getUpdateDate());
} catch (StepikClientException logged) {
logger.warn(String.format("Failed load section data id=%d", id), logged);
}
return true;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class StudyUtils method getRecommendation.
@Nullable
public static StudyNode<?, ?> getRecommendation(@NotNull StudyNode root) {
StudyObject data = root.getData();
if (data == null || !data.isAdaptive()) {
return null;
}
StudyNode studyNode = null;
StepikApiClient stepikClient = authAndGetStepikApiClient();
if (!isAuthenticated()) {
return null;
}
try {
Recommendations recommendations = stepikClient.recommendations().get().course(root.getId()).execute();
if (!recommendations.isEmpty()) {
Recommendation recommendation = recommendations.getFirst();
long lesson = recommendation.getLesson();
Steps steps = stepikClient.steps().get().lesson(lesson).execute();
if (!steps.isEmpty()) {
long stepId = steps.getFirst().getId();
studyNode = root.getChildByClassAndId(Step.class, stepId);
}
}
} catch (StepikClientException e) {
logger.warn(e);
}
return studyNode;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class CourseNode method getChildDataList.
@Override
protected List<Section> getChildDataList(@NotNull StepikApiClient stepikApiClient) {
Sections sections = new Sections();
try {
Course data = getData();
List<Long> sectionsIds = data != null ? getData().getSections() : Collections.emptyList();
if (!sectionsIds.isEmpty()) {
sections = stepikApiClient.sections().get().id(sectionsIds).execute();
}
} catch (StepikClientException logged) {
logger.warn("A course initialization don't is fully", logged);
}
return sections.getSections();
}
Aggregations