Changed equality testing for FileNode.

This commit is contained in:
Winston Li 2014-12-04 19:21:26 +00:00
parent e52ef90e13
commit 4ec7d70eff
8 changed files with 44 additions and 32 deletions

View file

@ -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);
}
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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);
}
}
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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