remove hack for storing multiple hints
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Thu, 3 Nov 2016 14:02:36 +0000 (17:02 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:40 +0000 (17:08 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholderSubtaskInfo.java
python/educational-core/student/testData/migration/4.xml

index b1ab9e68f83df8abbc8d859e715f7007921c5029..d2e7d54dd2156bc5784c79aa31e7ab82bb0c4f18 100644 (file)
@@ -22,6 +22,7 @@ import org.jdom.output.XMLOutputter;
 
 import java.io.File;
 import java.lang.reflect.Type;
 
 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;
 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);
                 valueElement.addContent(child.clone());
               }
               renameElement(getChildWithName(valueElement, TASK_TEXT), PLACEHOLDER_TEXT);
+              List<Element> 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<Element> newHints = new ArrayList<>();
+              newHints.add(firstHint);
+              newHints.addAll(additionalHints);
+              addChildList(valueElement, "hints", newHints);
             }
           }
         }
             }
           }
         }
index 58703fd809d3408765b7cb2c5601bf2dabe44d73..33d686984e746ffe6b8a235488418e47b8f2d802 100644 (file)
@@ -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.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.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 public class AnswerPlaceholderSubtaskInfo {
   private static final Logger LOG = Logger.getInstance(AnswerPlaceholderSubtaskInfo.class);
 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<String> myAdditionalHints = new ArrayList<>();
+  @SerializedName("hints")
+  @Expose private List<String> myHints = new ArrayList<>();
 
   @SerializedName("possible_answer")
   @Expose private String possibleAnswer = "";
 
   @SerializedName("possible_answer")
   @Expose private String possibleAnswer = "";
@@ -38,57 +33,25 @@ public class AnswerPlaceholderSubtaskInfo {
     myStatus = status;
   }
 
     myStatus = status;
   }
 
-  @Transient
-  public List<String> getHints() {
-    if (myHint.isEmpty() && myAdditionalHints.isEmpty()) return Collections.emptyList();
-    final ArrayList<String> result = new ArrayList<>();
-    result.add(myHint);
-    result.addAll(myAdditionalHints);
-    return result;
-  }
-
-  @Transient
-  public void setHints(@NotNull final List<String> 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) {
   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) {
   }
 
   public void removeHint(int i) {
-    if (i == 0) {
-      myHint = "";
+    if (i < myHints.size()) {
+      myHints.remove(i);
     }
     else {
     }
     else {
-      if (i - 1 <myAdditionalHints.size()) {
-        myAdditionalHints.remove(i - 1);
-      }
-      else {
-        LOG.warn("Trying to remove nonexistent hint. Hint to remove number: " + (i - 1) + "number of hints: " + getHints().size());
-      }
+      LOG.warn("Trying to remove nonexistent hint. Hint to remove number: " + i + " number of hints: " + myHints.size());
     }
   }
 
     }
   }
 
-  @NotNull
-  public List<String> getAdditionalHints() {
-    return myAdditionalHints;
+  public List<String> getHints() {
+    return myHints;
   }
 
   }
 
-  public void setAdditionalHints(@Nullable final List<String> additionalHints) {
-    myAdditionalHints = additionalHints;
+  public void setHints(List<String> hints) {
+    myHints = hints;
   }
 
   public String getPossibleAnswer() {
   }
 
   public String getPossibleAnswer() {
@@ -107,14 +70,6 @@ public class AnswerPlaceholderSubtaskInfo {
     myPlaceholderText = placeholderText;
   }
 
     myPlaceholderText = placeholderText;
   }
 
-  public String getHint() {
-    return myHint;
-  }
-
-  public void setHint(String hint) {
-    myHint = hint;
-  }
-
   public boolean getSelected() {
     return mySelected;
   }
   public boolean getSelected() {
     return mySelected;
   }
index 81b13fafe8a31750b83f2b7d5fad0f6ea1aa0886..944ffd640b2e85ae4fc66e571b1f15e30b8907f8 100644 (file)
                                               <option name="selected" value="false"/>
                                               <option name="status" value="Solved"/>
                                               <option name="placeholderText" value="test text"/>
                                               <option name="selected" value="false"/>
                                               <option name="status" value="Solved"/>
                                               <option name="placeholderText" value="test text"/>
+                                              <option name="hints">
+                                                <list>
+                                                  <option value="hint 1"/>
+                                                  <option value="hint 2"/>
+                                                </list>
+                                              </option>
                                             </AnswerPlaceholderSubtaskInfo>
                                           </value>
                                         </entry>
                                             </AnswerPlaceholderSubtaskInfo>
                                           </value>
                                         </entry>