use of org.stepik.api.objects.progresses.Progresses 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.objects.progresses.Progresses in project intellij-plugins by StepicOrg.
the class StepHelper method solvedLesson.
public boolean solvedLesson() {
try {
StudyNode lesson = stepNode.getParent();
if (lesson == null) {
return false;
}
StudyObject data = lesson.getData();
if (data == null) {
return false;
}
String progressId = data.getProgress();
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
Progresses progresses = stepikApiClient.progresses().get().id(progressId).execute();
return !progresses.isEmpty() && progresses.getFirst().isPassed();
} catch (StepikClientException e) {
logger.warn(e);
}
return false;
}
Aggregations