Search in sources :

Example 1 with UNCHECKED

use of org.stepik.core.courseFormat.StudyStatus.UNCHECKED 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)

Aggregations

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