From d922d92ab1de6ba9a63da458a1b1bb9822d7053e Mon Sep 17 00:00:00 2001 From: "Liana.Bakradze" Date: Thu, 3 Nov 2016 17:02:36 +0300 Subject: [PATCH] remove hack for storing multiple hints --- .../edu/learning/StudySerializationUtils.java | 8 +++ .../AnswerPlaceholderSubtaskInfo.java | 65 +++---------------- .../student/testData/migration/4.xml | 6 ++ 3 files changed, 24 insertions(+), 55 deletions(-) diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java b/python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java index b1ab9e68f83d..d2e7d54dd215 100644 --- a/python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java +++ b/python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java @@ -22,6 +22,7 @@ import org.jdom.output.XMLOutputter; import java.io.File; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -223,6 +224,13 @@ public class StudySerializationUtils { valueElement.addContent(child.clone()); } renameElement(getChildWithName(valueElement, TASK_TEXT), PLACEHOLDER_TEXT); + List additionalHints = ContainerUtil.map(getChildList(valueElement, ADDITIONAL_HINTS), Element::clone); + Element hint = getChildWithName(valueElement, HINT); + Element firstHint = new Element(OPTION).setAttribute(VALUE, hint.getAttributeValue(VALUE)); + List newHints = new ArrayList<>(); + newHints.add(firstHint); + newHints.addAll(additionalHints); + addChildList(valueElement, "hints", newHints); } } } diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholderSubtaskInfo.java b/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholderSubtaskInfo.java index 58703fd809d3..33d686984e74 100644 --- a/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholderSubtaskInfo.java +++ b/python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholderSubtaskInfo.java @@ -3,21 +3,16 @@ package com.jetbrains.edu.learning.courseFormat; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.util.xmlb.annotations.Transient; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class AnswerPlaceholderSubtaskInfo { private static final Logger LOG = Logger.getInstance(AnswerPlaceholderSubtaskInfo.class); - @SerializedName("hint") - @Expose private String myHint = ""; - @SerializedName("additional_hints") - @Expose private List myAdditionalHints = new ArrayList<>(); + @SerializedName("hints") + @Expose private List myHints = new ArrayList<>(); @SerializedName("possible_answer") @Expose private String possibleAnswer = ""; @@ -38,57 +33,25 @@ public class AnswerPlaceholderSubtaskInfo { myStatus = status; } - @Transient - public List getHints() { - if (myHint.isEmpty() && myAdditionalHints.isEmpty()) return Collections.emptyList(); - final ArrayList result = new ArrayList<>(); - result.add(myHint); - result.addAll(myAdditionalHints); - return result; - } - - @Transient - public void setHints(@NotNull final List hints) { - if (hints.isEmpty()) { - myHint = ""; - myAdditionalHints.clear(); - } - else { - myHint = hints.get(0); - myAdditionalHints = hints.subList(1, hints.size()); - } - } - public void addHint(@NotNull final String text) { - if (myHint.isEmpty() && myAdditionalHints.isEmpty()) { - myHint = text; - } - else { - myAdditionalHints.add(text); - } + myHints.add(text); } public void removeHint(int i) { - if (i == 0) { - myHint = ""; + if (i < myHints.size()) { + myHints.remove(i); } else { - if (i - 1 getAdditionalHints() { - return myAdditionalHints; + public List getHints() { + return myHints; } - public void setAdditionalHints(@Nullable final List additionalHints) { - myAdditionalHints = additionalHints; + public void setHints(List hints) { + myHints = hints; } public String getPossibleAnswer() { @@ -107,14 +70,6 @@ public class AnswerPlaceholderSubtaskInfo { myPlaceholderText = placeholderText; } - public String getHint() { - return myHint; - } - - public void setHint(String hint) { - myHint = hint; - } - public boolean getSelected() { return mySelected; } diff --git a/python/educational-core/student/testData/migration/4.xml b/python/educational-core/student/testData/migration/4.xml index 81b13fafe8a3..944ffd640b2e 100644 --- a/python/educational-core/student/testData/migration/4.xml +++ b/python/educational-core/student/testData/migration/4.xml @@ -78,6 +78,12 @@