Search in sources :

Example 1 with Progresses

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;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) SOLVED(org.stepik.core.courseFormat.StudyStatus.SOLVED) UNCHECKED(org.stepik.core.courseFormat.StudyStatus.UNCHECKED) HashMap(java.util.HashMap) Progresses(org.stepik.api.objects.progresses.Progresses) StepikClientException(org.stepik.api.exceptions.StepikClientException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Progresses

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;
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Progresses(org.stepik.api.objects.progresses.Progresses) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) StudyNode(org.stepik.core.courseFormat.StudyNode)

Aggregations

StepikApiClient (org.stepik.api.client.StepikApiClient)2 StepikClientException (org.stepik.api.exceptions.StepikClientException)2 Progresses (org.stepik.api.objects.progresses.Progresses)2 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)2 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1 StudyObject (org.stepik.api.objects.StudyObject)1 StudyNode (org.stepik.core.courseFormat.StudyNode)1 SOLVED (org.stepik.core.courseFormat.StudyStatus.SOLVED)1 UNCHECKED (org.stepik.core.courseFormat.StudyStatus.UNCHECKED)1