use of org.stepik.api.client.StepikApiClient in project intellij-plugins by StepicOrg.
the class Utils method getLessonStudyObject.
private static StudyObject getLessonStudyObject(long lessonId, long unitId) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
CompoundUnitLesson unitLesson = getCompoundUnitLessonStudyObject(stepikApiClient, unitId, lessonId);
Unit unit = unitLesson.getUnit();
if (unit.getId() != 0) {
Section section = getSectionStudyObject(stepikApiClient, unit.getSection());
if (section != null) {
return getCourseStudyObject(section.getCourse());
}
}
return unitLesson;
}
use of org.stepik.api.client.StepikApiClient in project intellij-plugins by StepicOrg.
the class StepikSendAction method check.
private void check(@NotNull Project project) {
logger.info("Start checking step");
StudyNode<?, ?> selected = StepikProjectManager.getSelected(project);
if (!(selected instanceof StepNode)) {
logger.info("Stop checking step: step is null or is not StepNode ");
return;
}
StepNode stepNode = (StepNode) selected;
String title = "Checking Step: " + stepNode.getName();
ProgressManager.getInstance().run(new Task.Backgroundable(project, title) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
StepikApiClient stepikApiClient = authAndGetStepikApiClient(true);
if (!isAuthenticated()) {
return;
}
Long submissionId = sendStep(stepikApiClient, project, stepNode);
if (submissionId == null) {
return;
}
Metrics.sendAction(project, stepNode, SUCCESSFUL);
SendAction.checkStepStatus(project, stepikApiClient, stepNode, submissionId, indicator);
logger.info(String.format("Finish checking step: id=%s", stepNode.getId()));
}
});
}
use of org.stepik.api.client.StepikApiClient in project intellij-plugins by StepicOrg.
the class Utils method getCourseStudyObject.
@NotNull
private static StudyObject getCourseStudyObject(long id) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
Course course = getCourse(stepikApiClient, id);
return course != null ? course : EMPTY_STUDY_OBJECT;
}
use of org.stepik.api.client.StepikApiClient 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.client.StepikApiClient 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;
}
Aggregations