Search in sources :

Example 11 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class CourseNode method loadData.

@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
    try {
        Courses courses = stepikApiClient.courses().get().id(id).execute();
        Course data;
        if (!courses.isEmpty()) {
            data = courses.getFirst();
        } else {
            data = new Course();
            data.setId(id);
        }
        Course oldData = this.getData();
        setData(data);
        return oldData == null || !oldData.getUpdateDate().equals(data.getUpdateDate());
    } catch (StepikClientException logged) {
        logger.warn(String.format("Failed load course data id=%d", id), logged);
    }
    return true;
}
Also used : Courses(org.stepik.api.objects.courses.Courses) Course(org.stepik.api.objects.courses.Course) StepikClientException(org.stepik.api.exceptions.StepikClientException)

Example 12 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class CourseNode method getAuthors.

@SuppressWarnings("unused")
@NotNull
public List<User> getAuthors(@NotNull StepikApiClient stepikApiClient) {
    if (authors == null) {
        List<Long> authorsIds;
        Course data = getData();
        authorsIds = data != null ? data.getAuthors() : Collections.emptyList();
        if (!authorsIds.isEmpty()) {
            try {
                if (!isAuthenticated()) {
                    return Collections.emptyList();
                }
                Users users = stepikApiClient.users().get().id(authorsIds).execute();
                authors = users.getUsers();
            } catch (StepikClientException e) {
                return Collections.emptyList();
            }
        }
    }
    return authors != null ? authors : Collections.emptyList();
}
Also used : Users(org.stepik.api.objects.users.Users) Course(org.stepik.api.objects.courses.Course) StepikClientException(org.stepik.api.exceptions.StepikClientException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class StepikProjectGenerator method getCourses.

@NotNull
public static CompletableFuture<List<StudyObject>> getCourses(@NotNull SupportedLanguages programmingLanguage) {
    return CompletableFuture.supplyAsync(() -> {
        List<StudyObject> courses = new ArrayList<>();
        List<Long> coursesIds = getHardcodedCoursesId(programmingLanguage);
        if (!coursesIds.isEmpty()) {
            StepikApiClient stepikApiClient = authAndGetStepikApiClient();
            try {
                courses = stepikApiClient.courses().get().id(coursesIds).execute().getCourses().stream().map(course -> (StudyObject) course).collect(Collectors.toList());
            } catch (StepikClientException e) {
                logger.warn("Failed get courses", e);
            }
        }
        courses.sort((course1, course2) -> {
            long id1 = course1.getId();
            long id2 = course2.getId();
            int index1 = coursesIds.indexOf(id1);
            int index2 = coursesIds.indexOf(id2);
            return Integer.compare(index1, index2);
        });
        return courses;
    });
}
Also used : StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) ArrayList(java.util.ArrayList) StudyObject(org.stepik.api.objects.StudyObject) StepikClientException(org.stepik.api.exceptions.StepikClientException) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class Utils method getCompoundUnitLessonStudyObject.

@NotNull
private static CompoundUnitLesson getCompoundUnitLessonStudyObject(@NotNull StepikApiClient stepikApiClient, long unitId, long lessonId) {
    Units units = null;
    if (unitId != 0) {
        try {
            units = stepikApiClient.units().get().id(unitId).execute();
        } catch (StepikClientException e) {
            logger.warn(e);
            units = new Units();
        }
    }
    Unit unit = null;
    if (unitId != 0 && !units.isEmpty()) {
        unit = units.getFirst();
    }
    Lesson lesson = getLesson(lessonId, stepikApiClient);
    return lesson != null ? new CompoundUnitLesson(unit, lesson) : new CompoundUnitLesson();
}
Also used : CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Unit(org.stepik.api.objects.units.Unit) StepikClientException(org.stepik.api.exceptions.StepikClientException) Lesson(org.stepik.api.objects.lessons.Lesson) CompoundUnitLesson(org.stepik.api.objects.lessons.CompoundUnitLesson) Units(org.stepik.api.objects.units.Units) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with StepikClientException

use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.

the class StepikSendAction method getSubmissionId.

@Nullable
private static Long getSubmissionId(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, long intAttemptId) {
    SupportedLanguages currentLang = stepNode.getCurrentLang();
    String code = getCode(project, stepNode, currentLang);
    if (code == null) {
        logger.info(String.format("Sending step failed: id=%s. Step content is null", stepNode.getId()));
        return null;
    }
    Submissions submissions;
    try {
        submissions = stepikApiClient.submissions().post().attempt(intAttemptId).language(currentLang.getName()).code(code).execute();
        if (submissions.isEmpty()) {
            notifyFailed(project, stepNode, "Submissions is empty", null);
            return null;
        }
    } catch (StepikClientException e) {
        notifyFailed(project, stepNode, "Failed post submission", e);
        return null;
    }
    return submissions.getFirst().getId();
}
Also used : SupportedLanguages(org.stepik.core.SupportedLanguages) Submissions(org.stepik.api.objects.submissions.Submissions) StepikClientException(org.stepik.api.exceptions.StepikClientException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StepikClientException (org.stepik.api.exceptions.StepikClientException)28 StepikApiClient (org.stepik.api.client.StepikApiClient)12 NotNull (org.jetbrains.annotations.NotNull)10 StepikAuthManager.authAndGetStepikApiClient (org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient)9 CompoundUnitLesson (org.stepik.api.objects.lessons.CompoundUnitLesson)6 Submissions (org.stepik.api.objects.submissions.Submissions)5 HashMap (java.util.HashMap)4 Nullable (org.jetbrains.annotations.Nullable)4 Step (org.stepik.api.objects.steps.Step)4 ArrayList (java.util.ArrayList)3 StudyObject (org.stepik.api.objects.StudyObject)3 TokenInfo (org.stepik.api.objects.auth.TokenInfo)3 Course (org.stepik.api.objects.courses.Course)3 Sections (org.stepik.api.objects.sections.Sections)3 Steps (org.stepik.api.objects.steps.Steps)3 User (org.stepik.api.objects.users.User)3 StepikAuthManager.getCurrentUser (org.stepik.core.stepik.StepikAuthManager.getCurrentUser)3 IOException (java.io.IOException)2 ClientResponse (org.stepik.api.client.ClientResponse)2 TransportClient (org.stepik.api.client.TransportClient)2