use of org.stepik.api.objects.submissions.Submissions 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();
}
use of org.stepik.api.objects.submissions.Submissions 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.objects.submissions.Submissions in project intellij-plugins by StepicOrg.
the class QuizHelper method loadSubmission.
private void loadSubmission(StepikApiClient stepikApiClient, long userId) {
long attemptId = attempt.getId();
StepNode stepNode = getStepNode();
StepikSubmissionsGetQuery query = stepikApiClient.submissions().get().order(Order.DESC).user(userId).step(stepNode.getId());
if (!useLastSubmission) {
query.attempt(attemptId);
}
Submissions submissions = query.execute();
modified = false;
if (!submissions.isEmpty()) {
submission = submissions.getFirst();
boolean lastSubmission = submission.getId() == stepNode.getLastSubmissionId();
boolean outdated = stepNode.getLastReplyTime().after(submission.getTime());
if (lastSubmission && outdated) {
reply = stepNode.getLastReply();
modified = !submission.getReply().equals(reply);
} else {
reply = submission.getReply();
stepNode.setLastReply(submission.getReply());
stepNode.setLastSubmissionId(submission.getId());
}
if (attemptId == submission.getAttempt()) {
status = submission.getStatus();
}
if (ACTIVE.equals(attempt.getStatus()) && status.equals("correct")) {
action = GET_ATTEMPT;
}
stepNode.setStatus(StudyStatus.of(status));
} else {
reply = stepNode.getLastReply();
modified = true;
}
}
use of org.stepik.api.objects.submissions.Submissions 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.objects.submissions.Submissions 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]));
}
Aggregations