From 4ec7d70eff5c856a04587426a1e60ec29124afbc Mon Sep 17 00:00:00 2001 From: Winston Li Date: Thu, 4 Dec 2014 19:21:26 +0000 Subject: [PATCH] Changed equality testing for FileNode. --- .../application/AttsResourceHandler.java | 22 +++++++++++++++++++ .../SnapshotPushPostbackHandler.java | 1 + .../application/WLGitBridgeServer.java | 2 +- .../writelatex/filestore/blob/Blob.java | 15 +++++++++++++ .../writelatex/filestore/blob/ByteBlob.java | 11 ---------- .../filestore/node/AttachmentNode.java | 9 -------- .../writelatex/filestore/node/BlobNode.java | 10 --------- .../writelatex/filestore/node/FileNode.java | 6 ++++- 8 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 services/git-bridge/src/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java new file mode 100644 index 0000000000..02279e542b --- /dev/null +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java @@ -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); + } + +} diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java index b347762c7c..56985926e0 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java @@ -31,6 +31,7 @@ public class SnapshotPushPostbackHandler extends AbstractHandler { if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) { String contents = getContentsOfReader(request.getReader()); String projectName = request.getRequestURI().split("/")[1]; + System.out.println("Postback received for project: " + projectName); SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, contents); try { postbackContents.processPostback(); diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java index cd1a7d5715..c6695c5d31 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java @@ -90,7 +90,7 @@ public class WLGitBridgeServer { } private Handler initResourceHandler() { - ResourceHandler resourceHandler = new ResourceHandler(); + ResourceHandler resourceHandler = new AttsResourceHandler(); resourceHandler.setResourceBase(new File(rootGitDirectoryPath, ".wlgb/atts").getAbsolutePath()); return resourceHandler; } diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/Blob.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/Blob.java index 6c2dc02f2f..fdc0579bf1 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/Blob.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/Blob.java @@ -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.model.db.PersistentStoreUpdater; +import java.util.Arrays; + /** * Created by Winston on 14/11/14. */ @@ -11,4 +13,17 @@ public abstract class Blob implements PersistentStoreUpdater { 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); + } + } + } diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/ByteBlob.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/ByteBlob.java index 990f0140e5..32fdc948b0 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/ByteBlob.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/blob/ByteBlob.java @@ -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.model.db.PersistentStoreAPI; -import java.util.Arrays; - /** * Created by Winston on 14/11/14. */ @@ -21,15 +19,6 @@ public class ByteBlob extends Blob { 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 public void updatePersistentStore(PersistentStoreAPI persistentStore, AttachmentNode node) { persistentStore.addFileNodeBlob(node.getProjectName(), node.getFilePath(), node.isChanged(), contents); diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/AttachmentNode.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/AttachmentNode.java index af445e222b..faee96fb9a 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/AttachmentNode.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/AttachmentNode.java @@ -43,15 +43,6 @@ public class AttachmentNode extends FileNode { 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 public void indexWith(FileNodeIndexer fileNodeIndexer) { fileNodeIndexer.index(this); diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/BlobNode.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/BlobNode.java index 9797cc86ca..863d5f425d 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/BlobNode.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/BlobNode.java @@ -35,16 +35,6 @@ public class BlobNode extends FileNode { 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 public void indexWith(FileNodeIndexer fileNodeIndexer) { fileNodeIndexer.index(this); diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java index f2ba9ff4ec..13a4270614 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java @@ -66,7 +66,11 @@ public abstract class FileNode implements PersistentStoreUpdater { @Override 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