mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactored test package names and added FileIndexStore and BlobHash classes.
This commit is contained in:
parent
5686590a36
commit
ae5a55747e
29 changed files with 103 additions and 35 deletions
|
@ -0,0 +1,35 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.filestore;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Winston on 08/11/14.
|
||||
*/
|
||||
public class BlobHash {
|
||||
|
||||
private byte[] hash;
|
||||
|
||||
public BlobHash(byte[] blob) {
|
||||
MessageDigest md = null;
|
||||
try {
|
||||
md = MessageDigest.getInstance("SHA-256");
|
||||
hash = md.digest(blob);
|
||||
System.out.println(Arrays.toString(hash));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BlobHash && Arrays.equals(((BlobHash) obj).hash, hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(hash);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.filestore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Winston on 08/11/14.
|
||||
*/
|
||||
public class FileIndexStore {
|
||||
|
||||
private final Map<BlobHash, String> blobHashMappings;
|
||||
private final Map<String, String> urlMappings;
|
||||
|
||||
public FileIndexStore() {
|
||||
blobHashMappings = new HashMap<BlobHash, String>();
|
||||
urlMappings = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.db;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.filestore;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -22,7 +24,11 @@ public class WLDirectoryNode {
|
|||
}
|
||||
|
||||
public void updateFromProject(WLProject project) {
|
||||
Snapshot snapshot = project.getLatestSnapshot();
|
||||
updateFromLatestSnapshot(project.getLatestSnapshot());
|
||||
}
|
||||
|
||||
private void updateFromLatestSnapshot(Snapshot snapshot) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.db;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.filestore;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
|
||||
|
|
@ -4,7 +4,7 @@ import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
|
|||
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.db.WLFileStore;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.WLFileStore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
|
@ -3,7 +3,6 @@ package uk.ac.ic.wlgitbridge.writelatex.model;
|
|||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotFetcher;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.db.WLFileStore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test;
|
||||
package uk.ac.ic.wlgitbridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.application;
|
||||
package uk.ac.ic.wlgitbridge.application;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.application;
|
||||
package uk.ac.ic.wlgitbridge.application;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.application.exception;
|
||||
package uk.ac.ic.wlgitbridge.application.exception;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.application.jetty;
|
||||
package uk.ac.ic.wlgitbridge.application.jetty;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.bridge;
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git;
|
||||
package uk.ac.ic.wlgitbridge.git;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git;
|
||||
package uk.ac.ic.wlgitbridge.git;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git.exception;
|
||||
package uk.ac.ic.wlgitbridge.git.exception;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git.handler;
|
||||
package uk.ac.ic.wlgitbridge.git.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git.handler;
|
||||
package uk.ac.ic.wlgitbridge.git.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git.handler;
|
||||
package uk.ac.ic.wlgitbridge.git.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.git.handler.hook;
|
||||
package uk.ac.ic.wlgitbridge.git.handler.hook;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex;
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.api.request.base;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.base;
|
||||
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.base.Request;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotGetForVersionRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers.SnapshotGetSavedVersRequest;
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.api.request.base;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.base;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.api.request.getdoc;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.api.request.getforversion;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion;
|
||||
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotGetForVersionRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotGetForVersionResult;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
|
@ -1,7 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.api.request.getsavedvers;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers;
|
||||
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers.SnapshotGetSavedVersRequest;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
|
@ -0,0 +1,15 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.filestore;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BlobHashTest {
|
||||
|
||||
private static final String toHash = "\\\\documentclass[a4paper]{article}\\n\\n\\\\usepackage[english]{babel}\\n\\\\usepackage[utf8]{inputenc}\\n\\\\usepackage{graphicx}\\n\\\\usepackage{fullpage}\\n\\\\usepackage{listings}\\n\\\\usepackage{courier}\\n\\\\usepackage{url}\\n\\n\\\\lstset{basicstyle=\\\\ttfamily,breaklines=true}\\n\\n\\\\begin{document}\\n\\\\title{API for the writeLaTeX-Git Bridge}\\n\\\\author{JLM}\\n\\\\date{\\\\today}\\n\\\\maketitle\\n\\n\\\\section{Fetching a Project from WriteLaTeX}\\n\\nThere are three API calls that will likely be of interest. You can run them against this server, \\\\url{radiant-wind-3058.herokuapp.com}, but they're not on the production server yet.\\n\\n\\\\subsection{Get Doc}\\n\\nA ``doc'' is our internal term for a ``project''. At present, this just returns the latest version number.\\n\\n\\\\begin{lstlisting}\\nGET https://.../api/v0/docs/1826rqgsdb\\n# => { latestVerId: 39 }\\n\\\\end{lstlisting}\\n\\n\\\\subsection{Get Saved Vers}\\n\\nA ``saved ver'' is a version of a doc, saved by via the versions menu. Note that this query is not currently paginated.\\n\\n\\\\begin{lstlisting}\\nGET https://.../api/v0/docs/1826rqgsdb/saved_vers\\n# => [\\n {\\\"versionId\\\":39,\\n \\\"comment\\\":\\\"with more files\\\",\\n \\\"user\\\":{\\n \\\"email\\\":\\\"jdleesmiller@gmail.com\\\",\\n \\\"name\\\":\\\"John Lees-Miller\\\"},\\n \\\"createdAt\\\":\\\"2014-11-05T18:02:19Z\\\"},\\n {\\\"versionId\\\":24,\\n \\\"comment\\\":\\\"first draft\\\",\\n \\\"user\\\":{\\n \\\"email\\\":\\\"jdleesmiller@gmail.com\\\",\\n \\\"name\\\":\\\"John Lees-Miller\\\"},\\n \\\"createdAt\\\":\\\"2014-11-05T17:56:58Z\\\"}]\\n\\\\end{lstlisting}\\n\\n\\\\subsection{Get Snapshot for Version}\\n\\nA snapshot contains the content of a project in the given version. You can safely request a snapshot of any version that is, or was at any point in the last 24 hours, (1) a saved version, or (2) the current version. (Older versions may or may not have been moved to cold storage.)\\n\\nThe srcs array contains (content, file name) pairs; the atts array contains (URL, file name) pairs.\\n\\n\\\\begin{lstlisting}\\nGET https://.../api/v0/docs/1826rqgsdb/snapshots/39\\n# => {\\n \\\"srcs\\\":[\\n [\\\"This text is from another file.\\\",\\\"foo/bar/test.tex\\\"],\\n [\\\"\\\\\\\\documentclass[a4paper]{article}\\\\n...\\\",\\\"main.tex\\\"]],\\n \\\"atts\\\":[\\n [\\\"https://writelatex-staging.s3.amazonaws.com/filepicker/1ENnu6zJSGyslI3DuNZD_min_mean_wait_evm_7.eps.150dpi.png\\\",\\\"min_mean_wait_evm_7_eps_150dpi.png\\\"]]}\\n\\\\end{lstlisting}\\n\\n\\\\section{Pushing a Project to WriteLaTeX}\\n\\nTODO still working on this part\\n\\n\\\\section{Test Data}\\n\\nYou can use this project as one of your test projects. I've added an attachment and a file in a subfolder to make it a bit more interesting.\\n\\n\\\\input{foo/bar/test}\\n\\n\\\\includegraphics[width=\\\\linewidth]{min_mean_wait_evm_7_eps_150dpi}\\n\\n\\\\end{document}";
|
||||
|
||||
@Test
|
||||
public void hashesTheBytesGivenInTheConstructorUsingSha256() {
|
||||
BlobHash blobHash = new BlobHash(toHash.getBytes());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.model;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.model;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
package uk.ac.ic.wlgitbridge.test.writelatex.model;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.model;
|
||||
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
Loading…
Reference in a new issue