Skip to content

Commit

Permalink
changes all url string to URI type
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthKipsu authored and wakr committed Sep 12, 2015
1 parent d30a825 commit dbbf735
Show file tree
Hide file tree
Showing 34 changed files with 283 additions and 231 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fi/helsinki/cs/tmc/core/TmcCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public ListenableFuture<List<Exercise>> getNewAndUpdatedExercises(Course course)
*/
public ListenableFuture<HttpResult> sendFeedback(Map<String, String> answers, URI url)
throws TmcCoreException {
SendFeedback feedback = new SendFeedback(settings, answers, url.toString());
SendFeedback feedback = new SendFeedback(settings, answers, url);
return threadPool.submit(feedback);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fi/helsinki/cs/tmc/core/commands/GetCourse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class GetCourse extends Command<Course> {

private TmcApi tmcApi;
private String url;
private URI url;

/**
* Constructs a new get course command with {@code settings} for fetching course details for
Expand All @@ -40,7 +40,7 @@ public GetCourse(TmcSettings settings, URI courseUri) {
super(settings);

this.tmcApi = new TmcApi(settings);
this.url = courseUri.toString();
this.url = courseUri;
}

/**
Expand All @@ -51,7 +51,7 @@ public Course call() throws TmcCoreException, URISyntaxException {
validate(this.settings.getUsername(), "Username must be set!");
validate(this.settings.getPassword(), "Password must be set!");

String urlWithApiVersion = new UrlHelper(settings).withParams(this.url);
URI urlWithApiVersion = new UrlHelper(settings).withParams(this.url);
Optional<Course> course;
try {
course = tmcApi.getCourse(urlWithApiVersion);
Expand All @@ -61,13 +61,13 @@ public Course call() throws TmcCoreException, URISyntaxException {

if (!course.isPresent()) {
throw new TmcCoreException(
"Attempted to fetch nonexistent course " + urlWithApiVersion);
"Attempted to fetch nonexistent course " + urlWithApiVersion);
}

return course.get();
}

private String pollServerForCourseUrl(String courseName) throws TmcCoreException {
private URI pollServerForCourseUrl(String courseName) throws TmcCoreException {
List<Course> courses = null;
try {
courses = tmcApi.getCourses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public URI call()

Optional<Course> currentCourse = settings.getCurrentCourse();
if (currentCourse.isPresent()) {
return URI.create(submitter.submitPasteWithComment(this.path, this.comment));
return submitter.submitPasteWithComment(this.path, this.comment);
} else {
throw new TmcCoreException("Unable to determine course");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public URI call()

Optional<Course> currentCourse = settings.getCurrentCourse();
if (currentCourse.isPresent()) {
return URI.create(submitter.submitWithCodeReviewRequest(this.path, this.comment));
return submitter.submitWithCodeReviewRequest(this.path, this.comment);
} else {
throw new TmcCoreException("Cannot request a code review. Unable to determine course.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.net.URI;

import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -16,13 +17,13 @@
public class SendFeedback extends Command<HttpResult> {

private Map<String, String> answers;
private String url;
private URI url;

/**
* Constructs a send feedback command with {@code settings} for sending {@code answers} to
* {@code url}.
*/
public SendFeedback(TmcSettings settings, Map<String, String> answers, String url) {
public SendFeedback(TmcSettings settings, Map<String, String> answers, URI url) {
super(settings);
this.answers = answers;
this.url = url;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fi/helsinki/cs/tmc/core/commands/Submit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import fi.helsinki.cs.tmc.langs.domain.NoLanguagePluginFoundException;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;

Expand Down Expand Up @@ -77,11 +78,11 @@ public SubmissionResult call()
assertHasRequiredData();

if (observer != null) {
String returnUrl = submitter.submit(this.path, observer);
URI returnUrl = submitter.submit(this.path, observer);
return submissionPoller.getSubmissionResult(returnUrl, observer);
}

String returnUrl = submitter.submit(this.path);
URI returnUrl = submitter.submit(this.path);
return submissionPoller.getSubmissionResult(returnUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;

import java.io.IOException;
import java.net.URI;

/**
* A {@link Command} for authenticating the user details saved in {@link TmcSettings}.
Expand Down Expand Up @@ -49,7 +50,9 @@ public Boolean call() throws TmcCoreException, IOException {

int response =
communicator
.makeGetRequest(settings.getServerAddress() + TMC_SERVER_ROUTE, auth)
.makeGetRequest(
URI.create(settings.getServerAddress() + TMC_SERVER_ROUTE),
auth)
.getStatusCode();

return (response >= HTTP_SUCCESS_RANGE_MIN && response <= HTTP_SUCCESS_RANGE_MAX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -51,7 +52,7 @@ public ExerciseDownloader(UrlCommunicator urlCommunicator, TmcApi tmcApi) {
* @param courseUrl course url
* @return info about downloading.
*/
public Optional<List<Exercise>> downloadExercises(String courseUrl) throws IOException {
public Optional<List<Exercise>> downloadExercises(URI courseUrl) throws IOException {
List<Exercise> exercises = tmcApi.getExercises(courseUrl);
if (exercises.isEmpty()) {
return Optional.absent();
Expand Down Expand Up @@ -194,7 +195,7 @@ public double getPercents(int exCount, int exercisesSize) {
* @param zipUrl url which will be downloaded
* @param path where to download
*/
private void downloadExerciseZip(String zipUrl, String path) {
private void downloadExerciseZip(URI zipUrl, String path) {
File file = new File(path);
urlCommunicator.downloadToFile(zipUrl, file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import fi.helsinki.cs.tmc.core.exceptions.TmcCoreException;
import fi.helsinki.cs.tmc.core.zipping.ProjectRootFinder;
import fi.helsinki.cs.tmc.core.zipping.RootFinder;
import fi.helsinki.cs.tmc.langs.io.EverythingIsStudentFileStudentFilePolicy;
import fi.helsinki.cs.tmc.langs.io.zip.StudentFileAwareZipper;
import fi.helsinki.cs.tmc.langs.io.zip.Zipper;
import fi.helsinki.cs.tmc.langs.util.TaskExecutor;
import fi.helsinki.cs.tmc.langs.util.TaskExecutorImpl;

Expand All @@ -19,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -94,10 +92,10 @@ private boolean deadlineGone(Date current, Date deadline) {
* Submits folder of exercise to TMC. Finds it from current directory.
*
* @param currentPath path from which this was called.
* @return String with url from which to get results or null if exercise was not found.
* @return URI from which to get results or null if exercise was not found.
* @throws IOException if zip creation fails
*/
public String submit(String currentPath)
public URI submit(String currentPath)
throws IOException, ParseException, ExpiredException, IllegalArgumentException,
TmcCoreException, URISyntaxException, NoLanguagePluginFoundException {
Exercise currentExercise = initExercise(currentPath);
Expand All @@ -109,10 +107,10 @@ public String submit(String currentPath)
*
* @param currentPath path from which this was called.
* @param observer {@link ProgressObserver} that is informed of the submission progress
* @return String with url from which to get results or null if exercise was not found.
* @return URI from which to get results or null if exercise was not found.
* @throws IOException if zip creation fails
*/
public String submit(String currentPath, ProgressObserver observer)
public URI submit(String currentPath, ProgressObserver observer)
throws ParseException, ExpiredException, IllegalArgumentException, IOException,
TmcCoreException, URISyntaxException, NoLanguagePluginFoundException {
Exercise currentExercise = initExercise(currentPath);
Expand All @@ -124,10 +122,10 @@ public String submit(String currentPath, ProgressObserver observer)
* paste.
*
* @param currentPath path from which this was called.
* @return String with url from which to get paste URL or null if exercise was not found.
* @return URI from which to get paste URL or null if exercise was not found.
* @throws IOException if zip creation fails
*/
public String submitPaste(String currentPath)
public URI submitPaste(String currentPath)
throws IOException, ParseException, ExpiredException, IllegalArgumentException,
TmcCoreException, URISyntaxException, NoLanguagePluginFoundException {
Exercise currentExercise = initExercise(currentPath);
Expand All @@ -139,10 +137,10 @@ public String submitPaste(String currentPath)
* Result includes URL of paste.
*
* @param currentPath path from which this was called.
* @return String with url from which to get paste URL or null if exercise was not found.
* @return URI from which to get paste URL or null if exercise was not found.
* @throws IOException if failed to create zip.
*/
public String submitPasteWithComment(String currentPath, String comment)
public URI submitPasteWithComment(String currentPath, String comment)
throws IOException, ParseException, ExpiredException, IllegalArgumentException,
TmcCoreException, URISyntaxException, NoLanguagePluginFoundException {
Exercise currentExercise = initExercise(currentPath);
Expand All @@ -155,7 +153,7 @@ public String submitPasteWithComment(String currentPath, String comment)
/**
* Requests a code review for a exercise.
*/
public String submitWithCodeReviewRequest(Path currentPath, String message)
public URI submitWithCodeReviewRequest(Path currentPath, String message)
throws IOException, ParseException, ExpiredException, IllegalArgumentException,
TmcCoreException, URISyntaxException, NoLanguagePluginFoundException {
Exercise currentExercise = initExercise(currentPath.toString());
Expand Down Expand Up @@ -193,18 +191,18 @@ private Exercise searchExercise(String currentPath)
return currentExercise.get();
}

private String sendSubmissionToServerWithPaste(byte[] file, String url) throws IOException {
private URI sendSubmissionToServerWithPaste(byte[] file, URI url) throws IOException {
HttpResult result =
urlCommunicator.makePostWithByteArray(
url, file, new HashMap<String, String>(), new HashMap<String, String>());
return tmcApi.getPasteUrl(result);
}

private String sendZipFile(String currentPath, Exercise currentExercise, boolean paste)
private URI sendZipFile(String currentPath, Exercise currentExercise, boolean paste)
throws IOException, URISyntaxException, NoLanguagePluginFoundException {
String returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
URI returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
byte[] zippedExercise = langs.compressProject(Paths.get(currentPath));
String resultUrl;
URI resultUrl;
if (paste) {
resultUrl = sendSubmissionToServerWithPaste(zippedExercise, returnUrl);
} else {
Expand All @@ -213,14 +211,14 @@ private String sendZipFile(String currentPath, Exercise currentExercise, boolean
return resultUrl;
}

private String sendZipFile(
private URI sendZipFile(
String currentPath, Exercise currentExercise, ProgressObserver observer, boolean paste)
throws IOException, URISyntaxException, NoLanguagePluginFoundException {
String returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
URI returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
observer.progress("zipping exercise");
byte[] zippedExercise = langs.compressProject(Paths.get(currentPath));
observer.progress("submitting exercise");
String resultUrl;
URI resultUrl;
if (paste) {
resultUrl = sendSubmissionToServerWithPaste(zippedExercise, returnUrl);
} else {
Expand All @@ -229,12 +227,12 @@ private String sendZipFile(
return resultUrl;
}

private String sendZipFileWithParams(
private URI sendZipFileWithParams(
String currentPath, Exercise currentExercise, boolean paste, Map<String, String> params)
throws IOException, URISyntaxException, NoLanguagePluginFoundException {
String returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
URI returnUrl = urlHelper.withParams(currentExercise.getReturnUrl());
byte[] zippedExercise = langs.compressProject(Paths.get(currentPath));
String resultUrl;
URI resultUrl;
if (paste) {
resultUrl = sendSubmissionToServerWithPasteAndParams(zippedExercise, returnUrl, params);
} else {
Expand All @@ -247,23 +245,23 @@ private String findExerciseFolderToZip(String currentPath) {
return rootFinder.getRootDirectory(Paths.get(currentPath)).get().toString();
}

private String sendSubmissionToServer(byte[] file, String url) throws IOException {
private URI sendSubmissionToServer(byte[] file, URI url) throws IOException {
HttpResult result =
urlCommunicator.makePostWithByteArray(
url, file, new HashMap<String, String>(), new HashMap<String, String>());
return tmcApi.getSubmissionUrl(result);
}

private String sendSubmissionToServerWithParams(
byte[] file, String url, Map<String, String> params) throws IOException {
private URI sendSubmissionToServerWithParams(
byte[] file, URI url, Map<String, String> params) throws IOException {
HttpResult result =
urlCommunicator.makePostWithByteArray(
url, file, new HashMap<String, String>(), params);
return tmcApi.getSubmissionUrl(result);
}

private String sendSubmissionToServerWithPasteAndParams(
byte[] file, String url, Map<String, String> params) throws IOException {
private URI sendSubmissionToServerWithPasteAndParams(
byte[] file, URI url, Map<String, String> params) throws IOException {
HttpResult result =
urlCommunicator.makePostWithByteArray(
url, file, new HashMap<String, String>(), params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;

import java.io.IOException;
import java.net.URI;
import java.util.List;
import org.apache.log4j.Logger;

public class SubmissionPoller {

Expand Down Expand Up @@ -57,7 +57,7 @@ public SubmissionPoller(TmcApi tmcApi, int timeout) {
* @return SubmissionResult containing details of submission. Null if timed out.
* @throws InterruptedException if thread failed to sleep
*/
private Optional<SubmissionResult> pollSubmissionUrl(String url)
private Optional<SubmissionResult> pollSubmissionUrl(URI url)
throws InterruptedException, IOException {
for (int i = 0; i < timeOut; i++) {
String json = tmcApi.getRawTextFrom(url);
Expand All @@ -78,7 +78,7 @@ private Optional<SubmissionResult> pollSubmissionUrl(String url)
* @return SubmissionResult containing details of submission. Null if timed out.
* @throws InterruptedException if thread failed to sleep
*/
private Optional<SubmissionResult> pollSubmissionUrl(String url, ProgressObserver observer)
private Optional<SubmissionResult> pollSubmissionUrl(URI url, ProgressObserver observer)
throws InterruptedException, IOException {
for (int i = 0; i < timeOut; i++) {
String json = tmcApi.getRawTextFrom(url);
Expand All @@ -104,7 +104,7 @@ public List<FeedbackQuestion> getFeedbackQuestions() {
*
* @param url the submission url
*/
public SubmissionResult getSubmissionResult(String url)
public SubmissionResult getSubmissionResult(URI url)
throws InterruptedException, TmcCoreException, IOException {
Optional<SubmissionResult> result = pollSubmissionUrl(url);
if (!result.isPresent()) {
Expand All @@ -120,7 +120,7 @@ public SubmissionResult getSubmissionResult(String url)
* @param url the submission url
* @param observer {@link ProgressObserver} that is informed of the polling status
*/
public SubmissionResult getSubmissionResult(String url, ProgressObserver observer)
public SubmissionResult getSubmissionResult(URI url, ProgressObserver observer)
throws InterruptedException, TmcCoreException, IOException {
Optional<SubmissionResult> result = pollSubmissionUrl(url, observer);
if (!result.isPresent()) {
Expand Down
Loading

0 comments on commit dbbf735

Please sign in to comment.