Fix multihints creation from stepic course after fixing migration from v3eap to v3 appcode/163.2122
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 1 Aug 2016 14:09:25 +0000 (17:09 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 1 Aug 2016 15:01:08 +0000 (18:01 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/StudySerializationUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/AnswerPlaceholder.java

index ea49362f0f605d5d13557a35b4540667ff08e38d..805df68d4eb0f67f4907011f297551dbb0acd7e7 100644 (file)
@@ -33,7 +33,7 @@ public class StudySerializationUtils {
   public static final String LENGTH = "length";
   public static final String POSSIBLE_ANSWER = "possible_answer";
   public static final String HINT = "hint";
-  public static final String HINTS = "hints";
+  public static final String ADDITIONAL_HINTS = "additional_hints";
   public static final String OFFSET = "offset";
   public static final String TEXT = "text";
   public static final String LESSONS = "lessons";
@@ -409,14 +409,23 @@ public class StudySerializationUtils {
             final Type listType = new TypeToken<List<String>>() {
             }.getType();
             final List<String> hints = gson.fromJson(hintString, listType);
-            for (String hint : hints) {
-              hintsArray.add(hint);
+            if (!hints.isEmpty()) {
+              for (int i = 0; i < hints.size(); i++) {
+                if (i == 0) {
+                  placeholderObject.addProperty(HINT, hints.get(0));
+                  continue;
+                }
+                hintsArray.add(hints.get(i));
+              }
+              placeholderObject.add(ADDITIONAL_HINTS, hintsArray);
+            }
+            else {
+              placeholderObject.addProperty(HINT, "");
             }
           }
           catch (JsonParseException e) {
             hintsArray.add(hintString);
           }
-          placeholderObject.add(HINTS, hintsArray);
         }
 
         return gson.fromJson(json, TaskFile.class);
index 76e96d52e4e8e3662e8618241fe0ebb4ce6ebafd..08866e92a19f72db57dbfab92daece3571953622 100644 (file)
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -18,7 +19,7 @@ public class AnswerPlaceholder {
   @SerializedName("hint")
   @Expose private String myHint = "";
 
-  @SerializedName("hints")
+  @SerializedName("additional_hints")
   @Expose private List<String> myAdditionalHints = new ArrayList<String>();
 
   @SerializedName("possible_answer")
@@ -181,6 +182,7 @@ public class AnswerPlaceholder {
 
   @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);