mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 23:55:33 -05:00
Changed equality testing for FileNode.
This commit is contained in:
parent
e52ef90e13
commit
4ec7d70eff
8 changed files with 44 additions and 32 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
package uk.ac.ic.wlgitbridge.application;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.server.Request;
|
||||||
|
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Winston on 04/12/14.
|
||||||
|
*/
|
||||||
|
public class AttsResourceHandler extends ResourceHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||||
|
System.out.println(baseRequest);
|
||||||
|
super.handle(target, baseRequest, request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
|
||||||
if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) {
|
if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) {
|
||||||
String contents = getContentsOfReader(request.getReader());
|
String contents = getContentsOfReader(request.getReader());
|
||||||
String projectName = request.getRequestURI().split("/")[1];
|
String projectName = request.getRequestURI().split("/")[1];
|
||||||
|
System.out.println("Postback received for project: " + projectName);
|
||||||
SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, contents);
|
SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, contents);
|
||||||
try {
|
try {
|
||||||
postbackContents.processPostback();
|
postbackContents.processPostback();
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class WLGitBridgeServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Handler initResourceHandler() {
|
private Handler initResourceHandler() {
|
||||||
ResourceHandler resourceHandler = new ResourceHandler();
|
ResourceHandler resourceHandler = new AttsResourceHandler();
|
||||||
resourceHandler.setResourceBase(new File(rootGitDirectoryPath, ".wlgb/atts").getAbsolutePath());
|
resourceHandler.setResourceBase(new File(rootGitDirectoryPath, ".wlgb/atts").getAbsolutePath());
|
||||||
return resourceHandler;
|
return resourceHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionExc
|
||||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
||||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreUpdater;
|
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreUpdater;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Winston on 14/11/14.
|
* Created by Winston on 14/11/14.
|
||||||
*/
|
*/
|
||||||
|
@ -11,4 +13,17 @@ public abstract class Blob implements PersistentStoreUpdater<AttachmentNode> {
|
||||||
|
|
||||||
public abstract byte[] getContents() throws FailedConnectionException;
|
public abstract byte[] getContents() throws FailedConnectionException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (!(obj instanceof Blob)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ByteBlob that = (ByteBlob) obj;
|
||||||
|
try {
|
||||||
|
return Arrays.equals(getContents(), that.getContents());
|
||||||
|
} catch (FailedConnectionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ package uk.ac.ic.wlgitbridge.writelatex.filestore.blob;
|
||||||
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.AttachmentNode;
|
||||||
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreAPI;
|
import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreAPI;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Winston on 14/11/14.
|
* Created by Winston on 14/11/14.
|
||||||
*/
|
*/
|
||||||
|
@ -21,15 +19,6 @@ public class ByteBlob extends Blob {
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof ByteBlob)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ByteBlob that = (ByteBlob) obj;
|
|
||||||
return Arrays.equals(contents, that.contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePersistentStore(PersistentStoreAPI persistentStore, AttachmentNode node) {
|
public void updatePersistentStore(PersistentStoreAPI persistentStore, AttachmentNode node) {
|
||||||
persistentStore.addFileNodeBlob(node.getProjectName(), node.getFilePath(), node.isChanged(), contents);
|
persistentStore.addFileNodeBlob(node.getProjectName(), node.getFilePath(), node.isChanged(), contents);
|
||||||
|
|
|
@ -43,15 +43,6 @@ public class AttachmentNode extends FileNode {
|
||||||
this.blob = new ByteBlob(blob);
|
this.blob = new ByteBlob(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof AttachmentNode)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
AttachmentNode that = (AttachmentNode) obj;
|
|
||||||
return super.equals(obj) && url.equals(that.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexWith(FileNodeIndexer fileNodeIndexer) {
|
public void indexWith(FileNodeIndexer fileNodeIndexer) {
|
||||||
fileNodeIndexer.index(this);
|
fileNodeIndexer.index(this);
|
||||||
|
|
|
@ -35,16 +35,6 @@ public class BlobNode extends FileNode {
|
||||||
this.blob = new ByteBlob(blob);
|
this.blob = new ByteBlob(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof BlobNode)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BlobNode that = (BlobNode) obj;
|
|
||||||
System.out.println("that: " + that + ", blob: " + blob + ", that.blob: " + that.blob);
|
|
||||||
return super.equals(that) && blob.equals(that.blob);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexWith(FileNodeIndexer fileNodeIndexer) {
|
public void indexWith(FileNodeIndexer fileNodeIndexer) {
|
||||||
fileNodeIndexer.index(this);
|
fileNodeIndexer.index(this);
|
||||||
|
|
|
@ -66,7 +66,11 @@ public abstract class FileNode implements PersistentStoreUpdater<String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj instanceof FileNode && filePath.equals(((FileNode) obj).filePath);
|
if (!(obj instanceof FileNode)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
FileNode that = (FileNode) obj;
|
||||||
|
return filePath.equals(that.filePath) && getBlob().equals(that.getBlob());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue