use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class StepNode method getCourseId.
@Override
public long getCourseId(@NotNull StepikApiClient stepikApiClient) {
StudyNode parent = getParent();
if (parent != null) {
return parent.getCourseId(stepikApiClient);
}
if (courseId != 0) {
return courseId;
}
Step data = getData();
if (data == null) {
return 0;
}
int lessonId = data.getLesson();
if (lessonId == 0) {
return 0;
}
try {
Units units = stepikApiClient.units().get().lesson(lessonId).execute();
if (units.isEmpty()) {
return 0;
}
LessonNode lessonNode = new LessonNode();
CompoundUnitLesson lessonData = lessonNode.getData();
if (lessonData != null) {
lessonData.setUnit(units.getFirst());
}
courseId = lessonNode.getCourseId(stepikApiClient);
return courseId;
} catch (StepikClientException ignored) {
}
return 0;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class StepNode method loadData.
@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
try {
Steps steps = stepikApiClient.steps().get().id(id).execute();
Step data;
if (!steps.isEmpty()) {
data = steps.getFirst();
} else {
data = new Step();
data.setId(id);
}
Step oldData = this.getData();
setData(data);
return oldData == null || !oldData.getUpdateDate().equals(data.getUpdateDate());
} catch (StepikClientException logged) {
logger.warn(String.format("Failed step lesson data id=%d", id), logged);
}
return true;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class LessonNode method loadData.
@Override
protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
try {
CompoundUnitLesson data = getData();
if (data == null) {
return true;
}
String updateDate = data.getUpdateDate();
Lessons lessons = stepikApiClient.lessons().get().id(id).execute();
Lesson lesson;
if (!lessons.isEmpty()) {
lesson = lessons.getFirst();
} else {
lesson = new Lesson();
lesson.setId(id);
}
data.setLesson(lesson);
return !updateDate.equals(data.getUpdateDate());
} catch (StepikClientException logged) {
logger.warn(String.format("Failed load lesson data id=%d", id), logged);
}
return true;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class LessonNode method getChildDataList.
@Override
protected List<Step> getChildDataList(@NotNull StepikApiClient stepikApiClient) {
Steps steps = new Steps();
try {
CompoundUnitLesson data = getData();
List<Long> stepsIds = data != null ? data.getLesson().getSteps() : Collections.emptyList();
if (!stepsIds.isEmpty()) {
steps = stepikApiClient.steps().get().id(stepsIds).execute();
}
} catch (StepikClientException logged) {
logger.warn("A lesson initialization don't is fully", logged);
}
return steps.getSteps();
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class FreeAnswerQuizHelper method isFrozen.
private boolean isFrozen() {
if (!needReview()) {
return true;
}
Step data = getStepNode().getData();
if (data == null) {
return true;
}
int instructionId = data.getInstruction();
if (instructionId == 0) {
return true;
}
StepikApiClient stepikClient = authAndGetStepikApiClient();
if (!isAuthenticated()) {
return true;
}
try {
Instructions instructions = stepikClient.instructions().get().id(instructionId).execute();
if (!instructions.isEmpty()) {
Instruction instruction = instructions.getFirst();
return instruction.isFrozen();
}
} catch (StepikClientException e) {
logger.warn(e);
}
return true;
}
Aggregations