mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 22:25:27 +00:00
Implemented WriteLatexDataSource with WriteLatexAPI instead of WLDataModel.
This commit is contained in:
parent
abc698085a
commit
f96a29bc45
3 changed files with 62 additions and 35 deletions
|
@ -10,6 +10,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import uk.ac.ic.wlgitbridge.application.jetty.NullLogger;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
|
||||
import uk.ac.ic.wlgitbridge.git.servlet.WLGitServlet;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLDataModel;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -78,7 +79,7 @@ public class WLGitBridgeServer {
|
|||
servletContextHandler.setContextPath("/");
|
||||
servletContextHandler.addServlet(
|
||||
new ServletHolder(
|
||||
new WLGitServlet(servletContextHandler, new WLDataModel(rootGitDirectoryPath), rootGitDirectoryPath)),
|
||||
new WLGitServlet(servletContextHandler, new WriteLatexAPI(new WLDataModel(rootGitDirectoryPath)), rootGitDirectoryPath)),
|
||||
"/*"
|
||||
);
|
||||
return servletContextHandler;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLDataModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 16/11/14.
|
||||
*/
|
||||
public class WriteLatexAPI implements WriteLatexDataSource {
|
||||
|
||||
private final WLDataModel dataModel;
|
||||
|
||||
public WriteLatexAPI(WLDataModel dataModel) {
|
||||
this.dataModel = dataModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repositoryExists(String projectName) throws FailedConnectionException {
|
||||
SnapshotGetDocRequest snapshotGetDocRequest = new SnapshotGetDocRequest(projectName);
|
||||
snapshotGetDocRequest.request();
|
||||
try {
|
||||
snapshotGetDocRequest.getResult().getVersionID();
|
||||
} catch (InvalidProjectException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException {
|
||||
return dataModel.updateProjectWithName(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException {
|
||||
dataModel.put(projectName, directoryContents);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,10 +2,8 @@ package uk.ac.ic.wlgitbridge.writelatex.model;
|
|||
|
||||
import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.WLDirectoryNode;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
|
||||
|
@ -18,7 +16,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
*/
|
||||
public class WLDataModel implements WriteLatexDataSource {
|
||||
public class WLDataModel {
|
||||
|
||||
private final Map<String, WLProject> projects;
|
||||
private final WLFileStore fileStore;
|
||||
|
@ -28,25 +26,22 @@ public class WLDataModel implements WriteLatexDataSource {
|
|||
fileStore = new WLFileStore(rootGitDirectoryPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repositoryExists(String projectName) throws FailedConnectionException {
|
||||
SnapshotGetDocRequest snapshotGetDocRequest = new SnapshotGetDocRequest(projectName);
|
||||
snapshotGetDocRequest.request();
|
||||
try {
|
||||
snapshotGetDocRequest.getResult().getVersionID();
|
||||
} catch (InvalidProjectException e) {
|
||||
return false;
|
||||
public List<WritableRepositoryContents> updateProjectWithName(String name) throws FailedConnectionException, InvalidProjectException {
|
||||
return fileStore.updateForProject(getProjectWithName(name));
|
||||
}
|
||||
|
||||
public WLProject getProjectWithName(String name) {
|
||||
WLProject project;
|
||||
if (projects.containsKey(name)) {
|
||||
project = projects.get(name);
|
||||
} else {
|
||||
project = new WLProject(name);
|
||||
projects.put(name, project);
|
||||
}
|
||||
return true;
|
||||
return project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException {
|
||||
return updateProjectWithName(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException {
|
||||
public void put(String projectName, RawDirectoryContents directoryContents) throws SnapshotPostException {
|
||||
WLDirectoryNode dn = fileStore.createCandidateDirectoryNodeForProjectWithContents(getProjectWithName(projectName), directoryContents);
|
||||
System.out.println("Pushing project with name: " + projectName);
|
||||
System.out.println(dn);
|
||||
|
@ -64,19 +59,4 @@ public class WLDataModel implements WriteLatexDataSource {
|
|||
};
|
||||
}
|
||||
|
||||
private List<WritableRepositoryContents> updateProjectWithName(String name) throws FailedConnectionException, InvalidProjectException {
|
||||
return fileStore.updateForProject(getProjectWithName(name));
|
||||
}
|
||||
|
||||
private WLProject getProjectWithName(String name) {
|
||||
WLProject project;
|
||||
if (projects.containsKey(name)) {
|
||||
project = projects.get(name);
|
||||
} else {
|
||||
project = new WLProject(name);
|
||||
projects.put(name, project);
|
||||
}
|
||||
return project;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue