Commit da03566b authored by Daniel Gerhardt's avatar Daniel Gerhardt

Add migrations for slide and flashcard content formats

parent 6a26bbe7
......@@ -57,6 +57,8 @@ public class FromV2Migrator {
static final String V2_TYPE_SCHOOL = "school";
static final String V2_TYPE_YESNO = "yesno";
static final String V2_TYPE_FREETEXT = "freetext";
static final String V2_TYPE_SLIDE = "slide";
static final String V2_TYPE_FLASHCARD = "flashcard";
static final String V2_TYPE_GRID = "grid";
private static final Map<String, de.thm.arsnova.model.Content.Format> formatMapping;
......@@ -71,6 +73,8 @@ public class FromV2Migrator {
formatMapping.put(V2_TYPE_SCHOOL, de.thm.arsnova.model.Content.Format.SCALE);
formatMapping.put(V2_TYPE_YESNO, de.thm.arsnova.model.Content.Format.BINARY);
formatMapping.put(V2_TYPE_FREETEXT, de.thm.arsnova.model.Content.Format.TEXT);
formatMapping.put(V2_TYPE_SLIDE, de.thm.arsnova.model.Content.Format.TEXT);
formatMapping.put(V2_TYPE_FLASHCARD, de.thm.arsnova.model.Content.Format.TEXT);
formatMapping.put(V2_TYPE_GRID, de.thm.arsnova.model.Content.Format.GRID);
}
......@@ -190,6 +194,8 @@ public class FromV2Migrator {
public de.thm.arsnova.model.Content migrate(final Content from) {
final de.thm.arsnova.model.Content to;
final Map<String, Map<String, Object>> extensions;
final Map<String, Object> v2;
switch (from.getQuestionType()) {
case V2_TYPE_ABCD:
case V2_TYPE_SC:
......@@ -216,6 +222,31 @@ public class FromV2Migrator {
case V2_TYPE_FREETEXT:
to = new de.thm.arsnova.model.Content();
to.setFormat(de.thm.arsnova.model.Content.Format.TEXT);
break;
case V2_TYPE_SLIDE:
to = new de.thm.arsnova.model.Content();
to.setFormat(de.thm.arsnova.model.Content.Format.TEXT);
extensions = new HashMap<>();
to.setExtensions(extensions);
v2 = new HashMap<>();
extensions.put("v2", v2);
v2.put("format", V2_TYPE_SLIDE);
break;
case V2_TYPE_FLASHCARD:
to = new de.thm.arsnova.model.Content();
to.setFormat(de.thm.arsnova.model.Content.Format.TEXT);
extensions = new HashMap<>();
to.setExtensions(extensions);
v2 = new HashMap<>();
extensions.put("v2", v2);
v2.put("format", V2_TYPE_FLASHCARD);
if (!from.getPossibleAnswers().isEmpty()) {
to.setAdditionalText(from.getPossibleAnswers().get(0).getText());
to.setAdditionalTextTitle("Back");
}
break;
default:
throw new IllegalArgumentException("Unsupported content format.");
......
......@@ -19,14 +19,17 @@
package de.thm.arsnova.model.migration;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_ABCD;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_FLASHCARD;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_FREETEXT;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_GRID;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_MC;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_SCHOOL;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_SLIDE;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_VOTE;
import static de.thm.arsnova.model.migration.FromV2Migrator.V2_TYPE_YESNO;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -210,7 +213,24 @@ public class ToV2Migrator {
to.setQuestionType(V2_TYPE_FREETEXT);
break;
case TEXT:
to.setQuestionType(V2_TYPE_FREETEXT);
final String legacyType = (String) from.getExtensions()
.getOrDefault("v2", Collections.emptyMap()).getOrDefault("format", "");
switch (legacyType) {
case V2_TYPE_SLIDE:
to.setQuestionType(V2_TYPE_SLIDE);
break;
case V2_TYPE_FLASHCARD:
to.setQuestionType(V2_TYPE_FLASHCARD);
final AnswerOption back = new AnswerOption();
back.setText(from.getAdditionalText());
back.setCorrect(true);
to.setPossibleAnswers(Collections.singletonList(back));
break;
default:
to.setQuestionType(V2_TYPE_FREETEXT);
break;
}
break;
default:
throw new IllegalArgumentException("Unsupported content format.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment