Fix according to review IDEA-CR-11509: 1) Add expose annotations to fields in Course...
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Tue, 21 Jun 2016 16:18:06 +0000 (19:18 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Tue, 21 Jun 2016 16:20:39 +0000 (19:20 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Lesson.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduAdaptiveStepicConnector.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java
python/educational-core/student/src/com/jetbrains/edu/learning/stepic/StepicWrappers.java

index 2222c29026b4f5ec4b632b2cf5d8578d7327918f..6b60f47f6faa60fa00b81a518d3e4651408baac2 100644 (file)
@@ -18,9 +18,9 @@ public class Course {
   @Expose private String description;
   @Expose private String name;
   private String myCourseDirectory = "";
-  private int id;
+  @Expose private int id;
   private boolean myUpToDate;
-  private boolean isAdaptive = false;
+  @Expose private boolean isAdaptive = false;
   @Expose @SerializedName("language") private String myLanguage = "Python";
 
   //this field is used to distinguish ordinary and CheckIO projects,
index 1fb6a4f931636d40b328df62faac344544f57921..56765a78f1ce5ab625d57b2b4071b6caf4732b1a 100644 (file)
@@ -11,11 +11,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class Lesson implements StudyItem {
-  public int id;
+  @Expose private int myId;
   @Transient public List<Integer> steps;
   @Transient public List<String> tags;
-  @Transient
-  Boolean is_public;
+  @Transient boolean is_public;
 
   @Expose
   @SerializedName("title")
@@ -97,4 +96,12 @@ public class Lesson implements StudyItem {
     }
     return StudyStatus.Solved;
   }
+
+  public int getId() {
+    return myId;
+  }
+
+  public void setId(int id) {
+    this.myId = id;
+  }
 }
index fd50ea62cf7f2eb9742bc3654034ecf249cef91f..18225c548598a104ad045cea451a203f43a51e71 100644 (file)
@@ -88,9 +88,9 @@ public class EduAdaptiveStepicConnector {
             lessonContainer = getFromStepic(EduStepicNames.LESSONS + lessonId, StepicWrappers.LessonContainer.class);
           if (lessonContainer.lessons.size() == 1) {
             final Lesson realLesson = lessonContainer.lessons.get(0);
-            course.getLessons().get(0).id = Integer.parseInt(lessonId);
+            course.getLessons().get(0).setId(Integer.parseInt(lessonId));
 
-            viewAllSteps(client, realLesson.id);
+            viewAllSteps(client, realLesson.getId());
 
             for (int stepId : realLesson.steps) {
               final StepicWrappers.Step step = getStep(stepId);
@@ -190,7 +190,14 @@ public class EduAdaptiveStepicConnector {
     setTimeout(post);
     try {
       final CloseableHttpResponse execute = client.execute(post);
-      return execute.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED;
+      if (execute.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
+        return true;
+      }
+      else {
+        LOG.warn("Stepic returned non-201 status code: " + execute.getStatusLine().getStatusCode() + " " +
+                 EntityUtils.toString(execute.getEntity()));
+        return false;
+      }
     }
     catch (IOException e) {
       LOG.warn(e.getMessage());
@@ -205,7 +212,7 @@ public class EduAdaptiveStepicConnector {
       final StepicUser user = StudyTaskManager.getInstance(project).getUser();
 
       final boolean recommendationReaction =
-        user != null && postRecommendationReaction(project, String.valueOf(editor.getTaskFile().getTask().getLesson().id),
+        user != null && postRecommendationReaction(project, String.valueOf(editor.getTaskFile().getTask().getLesson().getId()),
                                                    String.valueOf(user.getId()), reaction);
       if (recommendationReaction) {
         final Task task = getNextRecommendation(project, course);
@@ -282,6 +289,7 @@ public class EduAdaptiveStepicConnector {
       }
       else {
         LOG.warn("Recommendation reactions weren't posted");
+        ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project));        
       }
     }
   }
index a70a18bb8c3fac652266138e2311b577dd2fc6c5..665586af22a2acb7b8b223950ae71d6549b841e4 100644 (file)
@@ -627,7 +627,7 @@ public class EduStepicConnector {
   }
 
   public static int updateLesson(@NotNull final Project project, @NotNull final Lesson lesson, ProgressIndicator indicator) {
-    final HttpPut request = new HttpPut(EduStepicNames.STEPIC_API_URL + EduStepicNames.LESSONS + String.valueOf(lesson.id));
+    final HttpPut request = new HttpPut(EduStepicNames.STEPIC_API_URL + EduStepicNames.LESSONS + String.valueOf(lesson.getId()));
     if (ourClient == null) {
       if (!login(project)) {
         LOG.error("Failed to push lesson");
@@ -655,9 +655,9 @@ public class EduStepicConnector {
 
       for (Task task : lesson.getTaskList()) {
         indicator.checkCanceled();
-        postTask(project, task, lesson.id);
+        postTask(project, task, lesson.getId());
       }
-      return lesson.id;
+      return lesson.getId();
     }
     catch (IOException e) {
       LOG.error(e.getMessage());
@@ -685,12 +685,12 @@ public class EduStepicConnector {
         return 0;
       }
       final Lesson postedLesson = new Gson().fromJson(responseString, Course.class).getLessons().get(0);
-      lesson.id = postedLesson.id;
+      lesson.setId(postedLesson.getId());
       for (Task task : lesson.getTaskList()) {
         indicator.checkCanceled();
-        postTask(project, task, postedLesson.id);
+        postTask(project, task, postedLesson.getId());
       }
-      return postedLesson.id;
+      return postedLesson.getId();
     }
     catch (IOException e) {
       LOG.error(e.getMessage());
index c44d8c1b4fae5c7b7c1907e11920c0fea9ec052d..83363d59b0824c8a2225e50ab5349ecd47634e59 100644 (file)
@@ -163,7 +163,7 @@ public class StepicWrappers {
     public LessonWrapper(Lesson lesson) {
       this.lesson = new Lesson();
       this.lesson.setName(lesson.getName());
-      this.lesson.id = lesson.id;
+      this.lesson.setId(lesson.getId());
       this.lesson.steps = new ArrayList<Integer>();
     }
   }