mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Flush course to json after adding new recommended task
This commit is contained in:
+37
-18
@@ -69,16 +69,15 @@ public class StudyProjectGenerator {
|
||||
public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir) {
|
||||
StudyTaskManager.getInstance(project).setUser(myUser);
|
||||
final Course course = getCourse(project);
|
||||
final File courseDirectory = StudyUtils.getCourseDirectory(project, course);
|
||||
if (course == null) {
|
||||
LOG.warn("Course is null");
|
||||
return;
|
||||
}
|
||||
final File courseDirectory = StudyUtils.getCourseDirectory(project, course);
|
||||
StudyTaskManager.getInstance(project).setCourse(course);
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND,
|
||||
() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
course.initCourse(false);
|
||||
StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
|
||||
course.setCourseDirectory(courseDirectory.getAbsolutePath());
|
||||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
|
||||
@@ -87,29 +86,49 @@ public class StudyProjectGenerator {
|
||||
})));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Course getCourse(@NotNull final Project project) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
final File courseFile = new File(new File(OUR_COURSES_DIR, mySelectedCourseInfo.getName()), EduNames.COURSE_META_FILE);
|
||||
if (courseFile.exists()) {
|
||||
reader = new InputStreamReader(new FileInputStream(courseFile), "UTF-8");
|
||||
Gson gson = new GsonBuilder().create();
|
||||
final Course course = gson.fromJson(reader, Course.class);
|
||||
course.initCourse(false);
|
||||
return course;
|
||||
return readCourseFromCache(courseFile);
|
||||
}
|
||||
else {
|
||||
final File adaptiveCourseFile = new File(new File(OUR_COURSES_DIR, ADAPTIVE_COURSE_PREFIX +
|
||||
mySelectedCourseInfo.getName() + "_" +
|
||||
myUser.getEmail()), EduNames.COURSE_META_FILE);
|
||||
if (adaptiveCourseFile.exists()) {
|
||||
return readCourseFromCache(adaptiveCourseFile);
|
||||
}
|
||||
|
||||
}
|
||||
final Course course = EduStepicConnector.getCourse(project, mySelectedCourseInfo);
|
||||
if (course != null) {
|
||||
flushCourse(project, course);
|
||||
course.initCourse(false);
|
||||
}
|
||||
catch (FileNotFoundException | UnsupportedEncodingException e) {
|
||||
LOG.error(e);
|
||||
return course;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Course readCourseFromCache(File courseFile) {
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = new InputStreamReader(new FileInputStream(courseFile), "UTF-8");
|
||||
Gson gson = new GsonBuilder().create();
|
||||
final Course course = gson.fromJson(reader, Course.class);
|
||||
course.initCourse(true);
|
||||
return course;
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
LOG.warn(e.getMessage());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
LOG.warn(e.getMessage());
|
||||
}
|
||||
finally {
|
||||
StudyUtils.closeSilently(reader);
|
||||
}
|
||||
final Course course = EduStepicConnector.getCourse(project, mySelectedCourseInfo);
|
||||
if (course != null) {
|
||||
flushCourse(project, course);
|
||||
}
|
||||
return course;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void openFirstTask(@NotNull final Course course, @NotNull final Project project) {
|
||||
@@ -146,7 +165,7 @@ public class StudyProjectGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
public void flushCourse(@NotNull final Project project, @NotNull final Course course) {
|
||||
public static void flushCourse(@NotNull final Project project, @NotNull final Course course) {
|
||||
final File courseDirectory = StudyUtils.getCourseDirectory(project, course);
|
||||
FileUtil.createDirectory(courseDirectory);
|
||||
flushCourseJson(course, courseDirectory);
|
||||
@@ -242,7 +261,7 @@ public class StudyProjectGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void flushCourseJson(@NotNull final Course course, @NotNull final File courseDirectory) {
|
||||
public static void flushCourseJson(@NotNull final Course course, @NotNull final File courseDirectory) {
|
||||
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
final String json = gson.toJson(course);
|
||||
final File courseJson = new File(courseDirectory, EduNames.COURSE_META_FILE);
|
||||
|
||||
+21
-9
@@ -17,12 +17,10 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.jetbrains.edu.learning.StudyTaskManager;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.actions.StudyNextStudyTaskAction;
|
||||
import com.jetbrains.edu.learning.checker.StudyExecutor;
|
||||
import com.jetbrains.edu.learning.core.EduNames;
|
||||
import com.jetbrains.edu.learning.courseFormat.Course;
|
||||
import com.jetbrains.edu.learning.courseFormat.Lesson;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import com.jetbrains.edu.learning.courseFormat.*;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyGenerator;
|
||||
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
|
||||
import com.jetbrains.edu.learning.editor.StudyEditor;
|
||||
@@ -193,8 +191,8 @@ public class EduAdaptiveStepicConnector {
|
||||
|
||||
if (task != null) {
|
||||
final Lesson adaptive = course.getLessons().get(0);
|
||||
final Task unsolvedTask = adaptive.getTaskList().get(adaptive.getTaskList().size() - 1);
|
||||
if (reaction == 0 || reaction == -1) {
|
||||
final Task unsolvedTask = adaptive.getTaskList().get(adaptive.getTaskList().size() - 1);
|
||||
unsolvedTask.setName(task.getName());
|
||||
unsolvedTask.setStepicId(task.getStepicId());
|
||||
unsolvedTask.setText(task.getText());
|
||||
@@ -222,6 +220,7 @@ public class EduAdaptiveStepicConnector {
|
||||
final File lessonDirectory = new File(course.getCourseDirectory(), EduNames.LESSON + String.valueOf(adaptive.getIndex()));
|
||||
final File taskDirectory = new File(lessonDirectory, EduNames.TASK + String.valueOf(adaptive.getTaskList().size()));
|
||||
StudyProjectGenerator.flushTask(task, taskDirectory);
|
||||
flushAdaptiveCourse(course, adaptive, unsolvedTask);
|
||||
final VirtualFile lessonDir = project.getBaseDir().findChild(EduNames.LESSON + String.valueOf(adaptive.getIndex()));
|
||||
|
||||
if (lessonDir != null) {
|
||||
@@ -249,12 +248,13 @@ public class EduAdaptiveStepicConnector {
|
||||
}
|
||||
|
||||
final File lessonDirectory = new File(course.getCourseDirectory(), EduNames.LESSON + String.valueOf(adaptive.getIndex()));
|
||||
final File taskDirectory = new File(lessonDirectory, EduNames.TASK + String.valueOf(adaptive.getTaskList().size()));
|
||||
StudyProjectGenerator.flushTask(task, taskDirectory);
|
||||
adaptive.initLesson(course, false);
|
||||
StudyProjectGenerator.flushLesson(lessonDirectory, adaptive);
|
||||
flushAdaptiveCourse(course, adaptive, unsolvedTask);
|
||||
adaptive.initLesson(course, true);
|
||||
ApplicationManager.getApplication().invokeLater(()->new StudyNextStudyTaskAction().navigateTask(project));
|
||||
}
|
||||
}
|
||||
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
|
||||
ApplicationManager.getApplication().invokeLater(() -> VirtualFileManager.getInstance().refreshWithoutFileWatcher(false));
|
||||
}
|
||||
else {
|
||||
LOG.warn("Recommendation reactions weren't posted");
|
||||
@@ -262,6 +262,17 @@ public class EduAdaptiveStepicConnector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void flushAdaptiveCourse(Course course, Lesson adaptive, Task unsolvedTask) {
|
||||
unsolvedTask.setLesson(null);
|
||||
final TaskFile file = unsolvedTask.getTaskFile(DEFAULT_TASKFILE_NAME);
|
||||
if (file != null) {
|
||||
file.setTask(null);
|
||||
}
|
||||
adaptive.setCourse(null);
|
||||
StudyProjectGenerator.flushCourseJson(course, new File(course.getCourseDirectory()));
|
||||
course.initCourse(true);
|
||||
}
|
||||
|
||||
private static void createTestFiles(Course course, Task task, Task unsolvedTask, VirtualFile lessonDir) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
try {
|
||||
@@ -301,6 +312,7 @@ public class EduAdaptiveStepicConnector {
|
||||
task.setName(name);
|
||||
task.setStepicId(lessonID);
|
||||
task.setText(step.text);
|
||||
task.setStatus(StudyStatus.Unchecked);
|
||||
if (step.options.samples != null) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (List<String> sample : step.options.samples) {
|
||||
|
||||
Reference in New Issue
Block a user