Search in sources :

Example 1 with Reply

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;
}
Also used : Reply(org.stepik.api.objects.submissions.Reply) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with 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);
}
Also used : Reply(org.stepik.api.objects.submissions.Reply)

Example 3 with Reply

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());
    }));
}
Also used : HTMLFormElement(org.w3c.dom.html.HTMLFormElement) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StudyNode(org.stepik.core.courseFormat.StudyNode) StepikSubmissionsPostQuery(org.stepik.api.queries.submissions.StepikSubmissionsPostQuery) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Submission(org.stepik.api.objects.submissions.Submission) StepikAuthState(org.stepik.core.stepik.StepikAuthState) Files(java.nio.file.Files) StepNode(org.stepik.core.courseFormat.StepNode) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StudyUtils(org.stepik.core.StudyUtils) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) FileChooser(javafx.stage.FileChooser) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SendAction(org.stepik.plugin.actions.SendAction) EventListener(org.w3c.dom.events.EventListener) StepType(org.stepik.core.courseFormat.StepType) Event(org.w3c.dom.events.Event) StepikProjectManager(org.stepik.core.StepikProjectManager) StepikApiClient(org.stepik.api.client.StepikApiClient) Reply(org.stepik.api.objects.submissions.Reply) StepikAuthManager(org.stepik.core.stepik.StepikAuthManager) NotNull(org.jetbrains.annotations.NotNull) StepDescriptionUtils.getReply(org.stepik.core.ui.StepDescriptionUtils.getReply) ProjectFilesUtils.getOrCreateSrcDirectory(org.stepik.core.utils.ProjectFilesUtils.getOrCreateSrcDirectory) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Submission(org.stepik.api.objects.submissions.Submission) Reply(org.stepik.api.objects.submissions.Reply) StepDescriptionUtils.getReply(org.stepik.core.ui.StepDescriptionUtils.getReply) StepikSubmissionsPostQuery(org.stepik.api.queries.submissions.StepikSubmissionsPostQuery)

Aggregations

Reply (org.stepik.api.objects.submissions.Reply)3 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 Logger (com.intellij.openapi.diagnostic.Logger)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collectors (java.util.stream.Collectors)1 FileChooser (javafx.stage.FileChooser)1 NotNull (org.jetbrains.annotations.NotNull)1 StepikApiClient (org.stepik.api.client.StepikApiClient)1 Submission (org.stepik.api.objects.submissions.Submission)1 StepikSubmissionsPostQuery (org.stepik.api.queries.submissions.StepikSubmissionsPostQuery)1 StepikProjectManager (org.stepik.core.StepikProjectManager)1 StudyUtils (org.stepik.core.StudyUtils)1