Browse Source

Worked on file store.

Winston Li 12 years ago
parent
commit
95a17beef4

+ 10 - 0
services/git-bridge/src/uk/ac/ic/wlgitbridge/bridge/Writable.java

@@ -0,0 +1,10 @@
+package uk.ac.ic.wlgitbridge.bridge;
+
+/**
+ * Created by Winston on 14/11/14.
+ */
+public interface Writable {
+
+    public void write();
+
+}

+ 8 - 6
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/FileIndexStore.java

@@ -1,5 +1,7 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore;
 
+import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -8,16 +10,16 @@ import java.util.Map;
  */
 public class FileIndexStore {
 
-    private final Map<BlobHash, String> blobHashMappings;
-    private final Map<String, String> urlMappings;
+    private final Map<BlobHash, FileNode> blobHashMappings;
+    private final Map<String, FileNode> urlMappings;
 
     public FileIndexStore() {
-        blobHashMappings = new HashMap<BlobHash, String>();
-        urlMappings = new HashMap<String, String>();
+        blobHashMappings = new HashMap<BlobHash, FileNode>();
+        urlMappings = new HashMap<String, FileNode>();
     }
 
-    public void addAttachment(String url, String filePath) {
-        urlMappings.put(url, filePath);
+    public void addAttachment(String url, FileNode fileNode) {
+        urlMappings.put(url, fileNode);
     }
 
 }

+ 2 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/WLFileStore.java

@@ -1,5 +1,6 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore;
 
+import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.node.WLDirectoryNode;
 import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
 
@@ -19,7 +20,7 @@ public class WLFileStore {
         this.rootGitDirectoryPath = rootGitDirectoryPath;
     }
 
-    public void updateForProject(WLProject project) {
+    public void updateForProject(WLProject project) throws FailedConnectionException {
         String projectName = project.getName();
         WLDirectoryNode directoryNode = fileStore.get(projectName);
         if (directoryNode == null) {

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

@@ -1,6 +1,8 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
 
+import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotAttachment;
+import uk.ac.ic.wlgitbridge.writelatex.filestore.FileIndexStore;
 
 import java.util.Map;
 
@@ -9,8 +11,14 @@ import java.util.Map;
  */
 public class AttachmentNode extends FileNode {
 
-    public AttachmentNode(SnapshotAttachment snapshotAttachment, Map<String, FileNode> context) {
+    public AttachmentNode(SnapshotAttachment snapshotAttachment, Map<String, FileNode> context, FileIndexStore fileIndexes) throws FailedConnectionException {
         super(snapshotAttachment, context);
+
+    }
+
+    @Override
+    public byte[] initContents() {
+        return new byte[0];
     }
 
 }

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

@@ -1,6 +1,8 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
 
+import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
+import uk.ac.ic.wlgitbridge.writelatex.filestore.FileIndexStore;
 
 import java.util.Map;
 
@@ -9,8 +11,16 @@ import java.util.Map;
  */
 public class BlobNode extends FileNode {
 
-    public BlobNode(SnapshotFile snapshotFile, Map<String, FileNode> context) {
+    private SnapshotFile snapshotFile;
+
+    public BlobNode(SnapshotFile snapshotFile, Map<String, FileNode> context) throws FailedConnectionException {
         super(snapshotFile, context);
+        this.snapshotFile = snapshotFile;
+    }
+
+    @Override
+    public byte[] initContents() throws FailedConnectionException {
+        return snapshotFile.getContents();
     }
 
 }

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

@@ -1,6 +1,8 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
 
+import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
+import uk.ac.ic.wlgitbridge.writelatex.filestore.FileIndexStore;
 
 import java.util.Map;
 
@@ -11,15 +13,19 @@ public abstract class FileNode {
 
     private final String filePath;
     private final boolean unchanged;
+    private byte[] contents;
 
-    public FileNode(SnapshotFile snapshotFile, Map<String, FileNode> context) {
+    public FileNode(SnapshotFile snapshotFile, Map<String, FileNode> context) throws FailedConnectionException {
         filePath = snapshotFile.getPath();
         FileNode currentFileNode = context.get(filePath);
         unchanged = currentFileNode != null && equals(currentFileNode);
+        contents = initContents();
     }
 
     public String getFilePath() {
         return filePath;
     }
 
+    public abstract byte[] initContents() throws FailedConnectionException;
+
 }

+ 4 - 3
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/WLDirectoryNode.java

@@ -1,5 +1,6 @@
 package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
 
+import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotAttachment;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.FileIndexStore;
@@ -16,7 +17,7 @@ import java.util.Map;
 public class WLDirectoryNode {
 
     private Map<String, FileNode> files;
-    private final FileIndexStore fileIndexes;
+    private FileIndexStore fileIndexes;
     private final String rootGitDirectoryPath;
 
     public WLDirectoryNode(String rootGitDirectoryPath, String projectName) {
@@ -25,7 +26,7 @@ public class WLDirectoryNode {
         fileIndexes = new FileIndexStore();
     }
 
-    public void updateFromSnapshot(Snapshot snapshot) {
+    public void updateFromSnapshot(Snapshot snapshot) throws FailedConnectionException {
         Map<String, FileNode> updatedFiles = new HashMap<String, FileNode>();
         List<SnapshotFile> srcs = snapshot.getSrcs();
         List<SnapshotAttachment> atts = snapshot.getAtts();
@@ -34,7 +35,7 @@ public class WLDirectoryNode {
             updatedFiles.put(blobNode.getFilePath(), blobNode);
         }
         for (SnapshotAttachment att : atts) {
-            AttachmentNode attachmentNode = new AttachmentNode(att, files);
+            AttachmentNode attachmentNode = new AttachmentNode(att, files, fileIndexes);
             updatedFiles.put(attachmentNode.getFilePath(), attachmentNode);
         }
         files = updatedFiles;