use of org.stepik.api.objects.submissions.Reply in project intellij-plugins by StepicOrg.
the class StepDescriptionUtils method getReply.
@Nullable
static Reply getReply(@NotNull StepNode stepNode, @NotNull StepType type, @NotNull Elements elements, @Nullable String data) {
Reply reply = new Reply();
switch(type) {
case CHOICE:
List<Boolean> choices = getChoiceData(elements);
reply.setChoices(choices);
break;
case STRING:
String text = getStringData(elements);
reply.setText(text);
break;
case FREE_ANSWER:
text = getStringData(elements);
reply.setText(text);
reply.setAttachments(emptyList());
break;
case NUMBER:
String number = getStringData(elements);
reply.setNumber(number);
break;
case DATASET:
String dataset;
if (data == null) {
dataset = getStringData(elements);
} else {
dataset = data;
}
reply.setFile(dataset);
break;
case TABLE:
List tableChoices = getChoices(elements);
reply.setChoices(tableChoices);
break;
case FILL_BLANKS:
List<String> blanks = getBlanks(elements);
reply.setBlanks(blanks);
break;
case SORTING:
case MATCHING:
List<Integer> ordering = getOrderingData(elements);
reply.setOrdering(ordering);
break;
case MATH:
String formula = getStringData(elements);
reply.setFormula(formula);
break;
default:
logger.warn("Unknown step type tried sending: " + type);
return null;
}
stepNode.setLastReply(reply);
return reply;
}
use of org.stepik.api.objects.submissions.Reply in project intellij-plugins by StepicOrg.
the class StepNode method cleanLastReply.
public void cleanLastReply() {
this.lastReply = new Reply();
this.lastSubmissionId = 0;
this.lastReplyTime = Date.from(Instant.EPOCH);
}
use of org.stepik.api.objects.submissions.Reply in project intellij-plugins by StepicOrg.
the class FormListener method sendStep.
private static void sendStep(@NotNull Project project, @NotNull StepNode stepNode, @NotNull Elements elements, @NotNull StepType type, long attemptId, @Nullable String data) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient(true);
StepikSubmissionsPostQuery query = stepikApiClient.submissions().post().attempt(attemptId);
Reply reply = getReply(stepNode, type, elements, data);
if (reply == null) {
return;
}
query.reply(reply).executeAsync().whenComplete(((submissions, e) -> {
if (submissions == null) {
logger.warn("Failed send step from browser", e);
StepikProjectManager.updateSelection(project);
return;
}
if (submissions.isEmpty()) {
logger.warn("Failed send step from browser", e);
return;
}
Submission submission = submissions.getFirst();
SendAction.checkStepStatus(project, stepikApiClient, stepNode, submission.getId(), new EmptyProgressIndicator());
}));
}
Aggregations