Skip to content

Commit 116a3f1

Browse files
committed
Check for updates and others to core
1 parent 032aece commit 116a3f1

12 files changed

+56
-40
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/CheckForNewExercisesOrUpdates.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fi.helsinki.cs.tmc.actions;
22

3+
import fi.helsinki.cs.tmc.core.TmcCore;
34
import fi.helsinki.cs.tmc.core.domain.Course;
5+
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
46
import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder;
57
import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
68
import fi.helsinki.cs.tmc.data.CourseListUtils;
@@ -21,7 +23,7 @@
2123
import java.awt.event.ActionEvent;
2224
import java.awt.event.ActionListener;
2325
import java.util.ArrayList;
24-
import java.util.List;
26+
import java.util.concurrent.Callable;
2527
import javax.swing.AbstractAction;
2628
import javax.swing.Icon;
2729
import org.apache.commons.lang3.StringUtils;
@@ -92,7 +94,8 @@ public void run() {
9294
}
9395
eventBus.post(new InvokedEvent(currentCourseBeforeUpdate));
9496

95-
BgTask.start("Checking for new exercises", serverAccess.getFullCourseInfoTask(currentCourseBeforeUpdate), new BgTaskListener<Course>() {
97+
Callable<Course> getFullCourseInfoTask = TmcCore.get().getCourseDetails(ProgressObserver.NULL_OBSERVER, courseDb.getCurrentCourse());
98+
BgTask.start("Checking for new exercises", getFullCourseInfoTask, new BgTaskListener<Course>() {
9699
@Override
97100
public void bgTaskReady(Course receivedCourse) {
98101
if (receivedCourse != null) {

tmc-plugin/src/fi/helsinki/cs/tmc/actions/CheckForNewReviews.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package fi.helsinki.cs.tmc.actions;
22

33
import fi.helsinki.cs.tmc.core.domain.Course;
4-
import fi.helsinki.cs.tmc.data.Review;
4+
import fi.helsinki.cs.tmc.core.domain.Review;
55
import fi.helsinki.cs.tmc.model.CourseDb;
66
import fi.helsinki.cs.tmc.model.ReviewDb;
77
import fi.helsinki.cs.tmc.model.ServerAccess;

tmc-plugin/src/fi/helsinki/cs/tmc/actions/DownloadCompletedExercises.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
@Messages("CTL_DownloadCompletedExercises=Download old completed exercises")
2828
public final class DownloadCompletedExercises implements ActionListener {
2929

30-
private ServerAccess serverAccess;
3130
private CourseDb courseDb;
3231
private ConvenientDialogDisplayer dialogs;
3332
private TmcEventBus eventBus;
3433

3534
public DownloadCompletedExercises() {
36-
this.serverAccess = new ServerAccess();
3735
this.courseDb = CourseDb.getInstance();
3836
this.dialogs = ConvenientDialogDisplayer.getDefault();
3937
this.eventBus = TmcEventBus.getDefault();

tmc-plugin/src/fi/helsinki/cs/tmc/actions/DownloadExercisesAction.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package fi.helsinki.cs.tmc.actions;
22

3+
import fi.helsinki.cs.tmc.core.TmcCore;
34
import fi.helsinki.cs.tmc.core.domain.Exercise;
5+
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
46
import fi.helsinki.cs.tmc.events.TmcEvent;
57
import fi.helsinki.cs.tmc.events.TmcEventBus;
68
import fi.helsinki.cs.tmc.model.CourseDb;
79
import fi.helsinki.cs.tmc.model.ProjectMediator;
8-
import fi.helsinki.cs.tmc.model.ServerAccess;
910
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
1011
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
1112
import fi.helsinki.cs.tmc.utilities.AggregatingBgTaskListener;
1213
import fi.helsinki.cs.tmc.utilities.BgTask;
1314
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
14-
import fi.helsinki.cs.tmc.utilities.zip.NbProjectUnzipper;
1515

16+
import com.google.common.collect.Lists;
17+
import java.lang.reflect.InvocationTargetException;
1618
import java.util.Collection;
1719
import java.util.List;
1820
import java.util.concurrent.Callable;
1921
import java.util.logging.Level;
2022
import java.util.logging.Logger;
2123
import javax.swing.SwingUtilities;
24+
import org.openide.util.Exceptions;
2225

2326
/**
2427
* Downloads and opens the given exercises in the background.
@@ -27,7 +30,6 @@ public class DownloadExercisesAction {
2730

2831
private static final Logger logger = Logger.getLogger(DownloadExercisesAction.class.getName());
2932

30-
private ServerAccess serverAccess;
3133
private CourseDb courseDb;
3234
private ProjectMediator projectMediator;
3335
private ConvenientDialogDisplayer dialogs;
@@ -36,7 +38,6 @@ public class DownloadExercisesAction {
3638
private List<Exercise> exercisesToDownload;
3739

3840
public DownloadExercisesAction(List<Exercise> exercisesToOpen) {
39-
this.serverAccess = new ServerAccess();
4041
this.courseDb = CourseDb.getInstance();
4142
this.projectMediator = ProjectMediator.getInstance();
4243
this.dialogs = ConvenientDialogDisplayer.getDefault();
@@ -56,31 +57,34 @@ public void run() {
5657
}
5758

5859
private void startDownloading(final Exercise exercise, final BgTaskListener<TmcProjectInfo> listener) {
59-
BgTask.start("Downloading " + exercise.getName(), serverAccess.getDownloadingExerciseZipTask(exercise), new BgTaskListener<byte[]>() {
60-
@Override
61-
public void bgTaskReady(final byte[] zipData) {
62-
BgTask.start("Extracting project", new Callable<TmcProjectInfo>() {
63-
@Override
64-
public TmcProjectInfo call() throws Exception {
65-
NbProjectUnzipper unzipper = new NbProjectUnzipper();
66-
unzipper.unzipProject(zipData, projectMediator.getProjectDirForExercise(exercise));
67-
TmcProjectInfo proj = projectMediator.tryGetProjectForExercise(exercise);
68-
69-
if (proj == null) {
70-
throw new RuntimeException("Failed to open project for exercise " + exercise.getName());
71-
}
72-
73-
// Need to invoke courseDb in swing thread to avoid races
74-
SwingUtilities.invokeAndWait(new Runnable() {
75-
@Override
76-
public void run() {
77-
courseDb.exerciseDownloaded(exercise);
78-
}
79-
});
60+
Callable<List<Exercise>> downloadExercisesTask = TmcCore.get().downloadOrUpdateExercises(ProgressObserver.NULL_OBSERVER, Lists.newArrayList(exercise));
8061

81-
return proj;
62+
BgTask.start("Downloading " + exercise.getName(), downloadExercisesTask, new BgTaskListener<List<Exercise>>() {
63+
@Override
64+
public void bgTaskReady(List<Exercise> result) {
65+
try {
66+
67+
// There is only one exercise given as parameter.
68+
TmcProjectInfo proj = projectMediator.tryGetProjectForExercise(result.get(0));
69+
70+
if (proj == null) {
71+
throw new RuntimeException("Failed to open project for exercise " + exercise.getName());
8272
}
83-
}, listener);
73+
74+
// Need to invoke courseDb in swing thread to avoid races
75+
SwingUtilities.invokeAndWait(new Runnable() {
76+
@Override
77+
public void run() {
78+
courseDb.exerciseDownloaded(exercise);
79+
}
80+
});
81+
listener.bgTaskReady(proj);
82+
83+
} catch (InterruptedException ex) {
84+
Exceptions.printStackTrace(ex);
85+
} catch (InvocationTargetException ex) {
86+
Exceptions.printStackTrace(ex);
87+
}
8488
}
8589

8690
@Override

tmc-plugin/src/fi/helsinki/cs/tmc/actions/ReviewEventListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package fi.helsinki.cs.tmc.actions;
22

33
import com.google.gson.Gson;
4-
import fi.helsinki.cs.tmc.data.Review;
4+
5+
import fi.helsinki.cs.tmc.core.domain.Review;
56
import fi.helsinki.cs.tmc.events.TmcEventBus;
67
import fi.helsinki.cs.tmc.events.TmcEventListener;
78
import fi.helsinki.cs.tmc.model.CourseDb;
@@ -14,6 +15,7 @@
1415
import fi.helsinki.cs.tmc.utilities.BgTask;
1516
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
1617
import fi.helsinki.cs.tmc.utilities.CancellableCallable;
18+
1719
import java.awt.Image;
1820
import java.awt.event.ActionEvent;
1921
import java.awt.event.ActionListener;
@@ -154,7 +156,7 @@ private static class ReviewOpened {
154156

155157
public ReviewOpened(Review review) {
156158
this.id = review.getId();
157-
this.url = review.getUrl();
159+
this.url = review.getUrl().toString();
158160
this.submissionId = review.getSubmissionId();
159161
this.markedAsRead = review.isMarkedAsRead();
160162
}

tmc-plugin/src/fi/helsinki/cs/tmc/data/CourseListUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import java.util.List;
66

7+
@Deprecated
78
public class CourseListUtils {
89
/**
910
* Returns the course with the given name or null if not found.
1011
*/
12+
@Deprecated
1113
public static Course getCourseByName(List<Course> courses, String courseName) {
1214
for (Course course : courses) {
1315
if (course.getName().equals(courseName)) {
@@ -18,6 +20,7 @@ public static Course getCourseByName(List<Course> courses, String courseName) {
1820
return null;
1921
}
2022

23+
@Deprecated
2124
public static boolean hasCourseByName(List<Course> courses, String courseName) {
2225
return getCourseByName(courses, courseName) != null;
2326
}

tmc-plugin/src/fi/helsinki/cs/tmc/data/ExerciseListUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import java.util.List;
66

7+
@Deprecated
78
public class ExerciseListUtils {
89
/**
910
* Returns the exercise with the given name or null if not found.
1011
*/
12+
@Deprecated
1113
public static Exercise getExerciseByName(List<Exercise> exercises, String exerciseName) {
1214
if (exerciseName == null) {
1315
return null;
@@ -22,6 +24,7 @@ public static Exercise getExerciseByName(List<Exercise> exercises, String exerci
2224
return null;
2325
}
2426

27+
@Deprecated
2528
public static void setCourseNameForEach(List<Exercise> exercises, String courseName) {
2629
for (Exercise ex : exercises) {
2730
ex.setCourseName(courseName);

tmc-plugin/src/fi/helsinki/cs/tmc/data/serialization/ReviewListParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package fi.helsinki.cs.tmc.data.serialization;
22

3+
import fi.helsinki.cs.tmc.core.domain.Review;
4+
35
import com.google.gson.Gson;
46
import com.google.gson.GsonBuilder;
5-
import fi.helsinki.cs.tmc.data.Review;
67
import java.util.Arrays;
78
import java.util.Date;
89
import java.util.List;

tmc-plugin/src/fi/helsinki/cs/tmc/model/ReviewDb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package fi.helsinki.cs.tmc.model;
22

3-
import fi.helsinki.cs.tmc.data.Review;
3+
import fi.helsinki.cs.tmc.core.domain.Review;
44
import fi.helsinki.cs.tmc.events.TmcEvent;
55
import fi.helsinki.cs.tmc.events.TmcEventBus;
6+
67
import java.util.ArrayList;
78
import java.util.HashSet;
89
import java.util.List;
9-
import java.util.Set;
1010
import java.util.logging.Logger;
1111

1212
/**

tmc-plugin/src/fi/helsinki/cs/tmc/model/ServerAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.google.gson.reflect.TypeToken;
1313

1414
import fi.helsinki.cs.tmc.core.domain.submission.FeedbackAnswer;
15-
import fi.helsinki.cs.tmc.data.Review;
15+
import fi.helsinki.cs.tmc.core.domain.Review;
1616
import fi.helsinki.cs.tmc.data.serialization.CourseInfoParser;
1717
import fi.helsinki.cs.tmc.data.serialization.CourseListParser;
1818
import fi.helsinki.cs.tmc.data.serialization.ReviewListParser;

0 commit comments

Comments
 (0)