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;
}
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();
}
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;
});
}
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();
}
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();
}
Aggregations