mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 23:59:01 +02:00
Included slf4j jars and implemented Snapshot Fetch API.
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
|
||||
import org.eclipse.jgit.api.AddCommand;
|
||||
import org.eclipse.jgit.api.CommitCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -7,7 +7,6 @@ import uk.ac.ic.wlgitbridge.git.handler.WLReceivePackFactory;
|
||||
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
|
||||
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositoryBuilder;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotAPI;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||
import uk.ac.ic.wlgitbridge.git.handler.hook.CheckNonFastForwardHook;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotAPI;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request;
|
||||
|
||||
import com.ning.http.client.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public abstract class Request {
|
||||
|
||||
private final String url;
|
||||
|
||||
private Future<Response> response;
|
||||
private IOException exception;
|
||||
|
||||
public Request(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
protected abstract Realm buildRequestRealm();
|
||||
|
||||
public void request() {
|
||||
AsyncHttpClient client = new AsyncHttpClient();
|
||||
try {
|
||||
response = client.prepareGet(url).setRealm(buildRequestRealm()).execute();
|
||||
} catch (IOException e) {
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
public String getResponse() throws IOException, ExecutionException, InterruptedException {
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
return response.get().getResponseBody();
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request;
|
||||
|
||||
import com.ning.http.client.Realm;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.Request;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public abstract class SnapshotAPIRequest extends Request {
|
||||
|
||||
private static final String USERNAME = "staging";
|
||||
private static final String PASSWORD = "6kUfbv0R";
|
||||
|
||||
private static final String BASE_URL = "https://radiant-wind-3058.herokuapp.com/api/v0/docs";
|
||||
|
||||
public SnapshotAPIRequest(String projectName, String apiCall) {
|
||||
super(BASE_URL + "/" + projectName + apiCall);
|
||||
}
|
||||
|
||||
protected Realm buildRequestRealm() {
|
||||
return new Realm.RealmBuilder()
|
||||
.setPrincipal(USERNAME)
|
||||
.setPassword(PASSWORD)
|
||||
.setUsePreemptiveAuth(true)
|
||||
.setScheme(Realm.AuthScheme.BASIC)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotAPI;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class SnapshotGetDocRequest extends SnapshotAPIRequest {
|
||||
|
||||
public static final String API_CALL = "";
|
||||
|
||||
public SnapshotGetDocRequest(String projectName) {
|
||||
super(projectName, API_CALL);
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class SnapshotGetForVersionRequest extends SnapshotAPIRequest {
|
||||
|
||||
public static final String API_CALL = "/snapshots";
|
||||
|
||||
public SnapshotGetForVersionRequest(String projectName, int versionID) {
|
||||
super(projectName, API_CALL + "/" + versionID);
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class SnapshotGetSavedVersRequest extends SnapshotAPIRequest {
|
||||
|
||||
public static final String API_CALL = "/saved_vers";
|
||||
|
||||
public SnapshotGetSavedVersRequest(String projectName) {
|
||||
super(projectName, API_CALL);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public interface JSONSource {
|
||||
public interface JSONModel {
|
||||
|
||||
public void updateFromJSON(JsonElement json);
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* Created by Winston on 03/11/14.
|
||||
*/
|
||||
public class Snapshot implements JSONSource {
|
||||
public class Snapshot implements JSONModel {
|
||||
|
||||
private int versionID;
|
||||
|
||||
+2
-4
@@ -1,15 +1,13 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.ning.http.client.AsyncHttpClient;
|
||||
import com.ning.http.client.Realm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class WLDataModel implements JSONSource {
|
||||
public class WLDataModel implements JSONModel {
|
||||
|
||||
private final Map<String, WLProject> projects;
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class WLProject implements JSONSource {
|
||||
public class WLProject implements JSONModel {
|
||||
|
||||
public static final int VERSION_ID_INVALID = -1;
|
||||
private final Map<Integer, Snapshot> snapshots;
|
||||
Reference in New Issue
Block a user