Просмотр исходного кода

Changed equality testing for FileNode.

Winston Li 12 лет назад
Родитель
Сommit
4ec7d70eff

+ 22 - 0
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);
+    }
+
+}

+ 1 - 0
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();

+ 1 - 1
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;
     }

+ 15 - 0
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<AttachmentNode> {
 
     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);
+        }
+    }
+
 }

+ 0 - 11
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);

+ 0 - 9
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);

+ 0 - 10
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);

+ 5 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java

@@ -66,7 +66,11 @@ public abstract class FileNode implements PersistentStoreUpdater<String> {
 
     @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