use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class QuizHelper method getSubmissionsCount.
public int getSubmissionsCount() {
if (submissionsCount == -1) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
User user = getCurrentUser();
if (user.isGuest()) {
action = NEED_LOGIN;
return 0;
}
long userId = user.getId();
submissionsCount = 0;
int page = 1;
Submissions submissions;
do {
try {
submissions = stepikApiClient.submissions().get().step(getStepNode().getId()).user(userId).page(page).execute();
} catch (StepikClientException e) {
logger.warn("Failed get submissions count", e);
return 0;
}
submissionsCount += submissions.getCount();
page++;
} while (submissions.getMeta().getHasNext());
}
return submissionsCount;
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class QuizHelper method initStepOptions.
void initStepOptions() {
if (initialized) {
return;
}
initialized = true;
status = UNCHECKED;
action = GET_FIRST_ATTEMPT;
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
User user = getCurrentUser();
if (user.isGuest()) {
action = NEED_LOGIN;
fail();
initialized = false;
return;
}
long userId = user.getId();
try {
if (!loadAttempt(stepikApiClient, userId)) {
fail();
initialized = false;
return;
}
loadSubmission(stepikApiClient, userId);
done();
initialized = true;
} catch (StepikClientException e) {
logger.warn("Failed init test-step options", e);
fail();
}
}
use of org.stepik.api.exceptions.StepikClientException 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;
}
Aggregations