Skip to content
Snippets Groups Projects
Commit de5a8dea authored by AnneliKlamas's avatar AnneliKlamas
Browse files

#52 Added additional error for wrong placing of feedback

parent dd6e41f5
Branches feature/52
No related tags found
1 merge request!55Resolve "feat: Fix files not uploading #52"
......@@ -11,7 +11,7 @@ Runs on port 8000
This project is a simple quiz converter that takes a DOCX file and converts it to a Moodle XML format or to the Coursera
DOCX depending on which endpoint is used.
Currently, question description nor answer can't start with the words "question", "feedback" nor "\t".
Currently, question description can't start with the words "question", "feedback" nor "default feedback".
Feedback doesn't support pictures.
......
......@@ -15,7 +15,7 @@ public class FeedbackHandler {
public void add(String text, ParagraphType paragraphType) {
switch (paragraphType) {
case DEFAULT_FEEDBACK -> state.setDefaultFeedback(text.replaceAll("^\s*([dD][eE][fF][aA][uU][lL][tT])\s*([fF][eE][eE][dD][bB][aA][cC][kK])\s*(:)", "").strip());
case FEEDBACK -> {
case ANSWER_OPTION_FEEDBACK -> {
var feedbackText = text.toLowerCase().replace("feedback", "").strip().replace(":", "").strip();
state.getAnswerOptions().get(state.getAnswerOptions().size() - 1).setFeedback(Optional.of(feedbackText));
}
......
package com.quiz.converter.models.enums;
public enum ParagraphType {
FEEDBACK,
ANSWER_OPTION_FEEDBACK,
QUESTION_DESCRIPTION,
ANSWER_OPTION,
QUESTION_DETAILS,
......@@ -9,3 +9,4 @@ public enum ParagraphType {
DEFAULT_FEEDBACK,
UNKNOWN
}
......@@ -5,5 +5,6 @@ public enum QuestionErrorType {
NO_ANSWER_OPTIONS_FOUND,
NO_CORRECT_ANSWER_FOUND,
ANSWER_OPTIONS_DONT_MATCH_TYPE,
INVALID_REGEX
INVALID_REGEX,
NO_ANSWER_OPTION_FOR_FEEDBACK
}
......@@ -108,7 +108,12 @@ public class CourseraDocxCreatorService {
var pictureRun = pictureParagraph.createRun();
var pictureData = Base64.getDecoder().decode(p.base64());
try {
pictureRun.addPicture(new ByteArrayInputStream(pictureData), p.type(), p.name(), Units.toEMU(p.width()), Units.toEMU(p.height()));
pictureRun.addPicture(
new ByteArrayInputStream(pictureData),
p.type(),
p.name(),
Units.toEMU(p.width()),
Units.toEMU(p.height()));
} catch (InvalidFormatException | IOException e) {
throw new RuntimeException(e);
}
......
......@@ -5,10 +5,9 @@ import com.quiz.converter.handlers.QuestionHandler;
import com.quiz.converter.handlers.QuestionValidationHandler;
import com.quiz.converter.models.*;
import com.quiz.converter.models.enums.ParagraphType;
import com.quiz.converter.models.enums.QuestionErrorType;
import com.quiz.converter.models.enums.QuestionWarningType;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFSDT;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
......@@ -55,7 +54,7 @@ public class FileUploadService {
descriptionPictures.addAll(paragraphPictures);
state.setPreviousParagraphType(paragraphType);
}
case FEEDBACK, DEFAULT_FEEDBACK -> {
case ANSWER_OPTION_FEEDBACK, DEFAULT_FEEDBACK -> {
var feedbackHandler = new FeedbackHandler(state);
feedbackHandler.add(text, paragraphType);
state.setPreviousParagraphType(paragraphType);
......@@ -88,7 +87,12 @@ public class FileUploadService {
if (text.replaceAll("\t", "").isEmpty() || text.replaceAll("\n", "").isEmpty()) return ParagraphType.EMPTY_TEXT;
var lowerCaseText = text.toLowerCase().strip();
if (lowerCaseText.matches("\s*(question).*")) return ParagraphType.QUESTION_DETAILS;
if (lowerCaseText.matches("\s*(feedback).*")) return ParagraphType.FEEDBACK;
if (lowerCaseText.matches("\s*(feedback).*")) {
if (state.getPreviousParagraphType().equals(ParagraphType.ANSWER_OPTION))
return ParagraphType.ANSWER_OPTION_FEEDBACK;
state.getErrors().add(QuestionErrorType.NO_ANSWER_OPTION_FOR_FEEDBACK);
return ParagraphType.UNKNOWN;
}
if (lowerCaseText.matches(".*(default)\s*(feedback).*")) return ParagraphType.DEFAULT_FEEDBACK;
if (lowerCaseText.matches("(\\s*\\**\\s*)*[a-zA-Z\\d]\\s*[:)].*")) return ParagraphType.ANSWER_OPTION;
if (state.getPreviousParagraphType().equals(ParagraphType.QUESTION_DETAILS))
......
......@@ -45,7 +45,8 @@
"NO_ANSWER_OPTIONS_FOUND": "No answer options found",
"NO_CORRECT_ANSWER_FOUND": "No correct answer found",
"ANSWER_OPTIONS_DONT_MATCH_TYPE": "Answer options don't match type",
"INVALID_REGEX": "Invalid regex"
"INVALID_REGEX": "Invalid regex",
"NO_ANSWER_OPTION_FOR_FEEDBACK": "Feedback for the answer does not have an answer option before it"
},
"warnings": {
"CHECK_QUESTION_NAME": "Couldn't find the end of the name. Name should be followed by hypen (-).",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment