use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class DownloadSubmission method getSubmissions.
@Nullable
private List<Submission> getSubmissions(@NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode) {
try {
long stepId = stepNode.getId();
long userId = getCurrentUser().getId();
Submissions submissions = stepikApiClient.submissions().get().step(stepId).user(userId).order(Order.DESC).execute();
return submissions.getSubmissions();
} catch (StepikClientException e) {
logger.warn("Failed get submissions", e);
return null;
}
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class ProgrammingLanguageUtils method getOrCreateMainFile.
@Nullable
private static PsiFile getOrCreateMainFile(@NotNull Project project, @NotNull VirtualFile parent, @NotNull SupportedLanguages language, @NotNull StepNode stepNode) {
String fileName = language.getMainFileName();
final VirtualFile[] file = { parent.findChild(fileName) };
Application application = ApplicationManager.getApplication();
if (file[0] == null) {
application.invokeAndWait(() -> application.runWriteAction(() -> {
try {
file[0] = parent.createChildData(null, fileName);
String template = null;
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
User user = getCurrentUser();
if (!user.isGuest()) {
try {
Submissions submissions = stepikApiClient.submissions().get().user(user.getId()).order(Order.DESC).step(stepNode.getId()).execute();
if (!submissions.isEmpty()) {
Optional<Submission> lastSubmission = submissions.getItems().stream().filter(submission -> SupportedLanguages.langOfName(submission.getReply().getLanguage()) == language).limit(1).findFirst();
if (lastSubmission.isPresent()) {
template = lastSubmission.get().getReply().getCode();
}
}
} catch (StepikClientException e) {
logger.warn(e);
}
}
if (template == null) {
template = stepNode.getTemplate(language);
}
file[0].setBinaryContent(template.getBytes());
} catch (IOException e) {
file[0] = null;
}
}));
}
return application.runReadAction((Computable<PsiFile>) () -> PsiManager.getInstance(project).findFile(file[0]));
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class StudyToolWindow method postView.
private void postView(@NotNull StepNode stepNode, boolean isTheory) {
executor.execute(() -> {
Long assignment = stepNode.getAssignment();
long stepId = stepNode.getId();
if (assignment != null && assignment != 0) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
if (!isAuthenticated()) {
return;
}
try {
stepikApiClient.views().post().assignment(assignment).step(stepId).execute();
} catch (StepikClientException e) {
logger.warn("Failed post view: stepId=" + stepId + "; assignment=" + assignment, e);
}
}
if (isTheory) {
stepNode.passed();
}
if (stepNode.getProject() == null) {
stepNode.setProject(project);
}
if (!project.isDisposed()) {
ApplicationManager.getApplication().invokeLater(() -> ProjectView.getInstance(project).refresh());
}
});
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class SendAction method checkStepStatus.
public static void checkStepStatus(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, final long submissionId, @NotNull ProgressIndicator indicator) {
String stepIdString = "id=" + stepNode.getId();
logger.info("Started check a status for step: " + stepIdString);
String stepStatus = EVALUATION;
int timer = 0;
String hint;
indicator.setIndeterminate(false);
Submission currentSubmission = null;
while (timer < FIVE_MINUTES) {
try {
Submissions submission = stepikApiClient.submissions().get().id(submissionId).execute();
if (!submission.isEmpty()) {
currentSubmission = submission.getFirst();
ActionUtils.setupCheckProgress(indicator, currentSubmission, timer);
stepStatus = currentSubmission.getStatus();
if (!EVALUATION.equals(stepStatus)) {
break;
}
}
Thread.sleep(PERIOD);
if (Utils.isCanceled()) {
Metrics.getStepStatusAction(project, stepNode, USER_CANCELED);
return;
}
timer += PERIOD;
} catch (StepikClientException | InterruptedException e) {
ActionUtils.notifyError(project, "Error", "Get Status error");
logger.info("Stop check a status for step: " + stepIdString, e);
return;
}
}
if (currentSubmission == null) {
logger.info(String.format("Stop check a status for step: %s without result", stepIdString));
return;
}
MetricsStatus actionStatus = EVALUATION.equals(stepStatus) ? TIME_OVER : SUCCESSFUL;
Metrics.getStepStatusAction(project, stepNode, actionStatus);
indicator.setIndeterminate(true);
indicator.setText("");
hint = currentSubmission.getHint();
if (stepNode.getType() == StepType.CODE) {
notify(project, stepNode, stepStatus, hint);
}
ApplicationManager.getApplication().invokeLater(() -> {
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
StepikProjectManager.updateSelection(project);
});
logger.info(String.format("Finish check a status for step: %s with status: %s", stepIdString, stepStatus));
}
use of org.stepik.api.exceptions.StepikClientException in project intellij-plugins by StepicOrg.
the class LessonNode method getCourseId.
@Override
public long getCourseId(@NotNull StepikApiClient stepikApiClient) {
StudyNode parent = getParent();
if (parent != null) {
return parent.getCourseId(stepikApiClient);
}
if (courseId != 0) {
return courseId;
}
CompoundUnitLesson data = getData();
int sectionId = data != null ? data.getUnit().getSection() : 0;
if (sectionId == 0) {
return 0;
}
try {
Sections sections = stepikApiClient.sections().get().id(sectionId).execute();
if (sections.isEmpty()) {
return 0;
}
courseId = sections.getFirst().getCourse();
return courseId;
} catch (StepikClientException ignored) {
}
return 0;
}
Aggregations