Procházet zdrojové kódy

DirectoryNode being created for latest snapshot.

Winston Li před 12 roky
rodič
revize
33f59c3f65

+ 3 - 3
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/getforversion/SnapshotData.java

@@ -17,11 +17,11 @@ public class SnapshotData implements JSONSource {
     public static final String JSON_KEY_ATTS = "atts";
     public static final String JSON_KEY_ATTS = "atts";
 
 
     private List<SnapshotFile> srcs;
     private List<SnapshotFile> srcs;
-    private List<SnapshotFile> atts;
+    private List<SnapshotAttachment> atts;
 
 
     public SnapshotData(JsonElement json) throws FailedConnectionException {
     public SnapshotData(JsonElement json) throws FailedConnectionException {
         srcs = new LinkedList<SnapshotFile>();
         srcs = new LinkedList<SnapshotFile>();
-        atts = new LinkedList<SnapshotFile>();
+        atts = new LinkedList<SnapshotAttachment>();
         fromJSON(json);
         fromJSON(json);
     }
     }
 
 
@@ -47,7 +47,7 @@ public class SnapshotData implements JSONSource {
         return srcs;
         return srcs;
     }
     }
 
 
-    public List<SnapshotFile> getAtts() {
+    public List<SnapshotAttachment> getAtts() {
         return atts;
         return atts;
     }
     }
 }
 }

+ 0 - 32
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/WLDirectoryNode.java

@@ -1,32 +0,0 @@
-package uk.ac.ic.wlgitbridge.writelatex.filestore;
-
-import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
-import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created by Winston on 08/11/14.
- */
-public class WLDirectoryNode {
-
-    private final Map<String, String> srcs;
-    private final Map<String, String> atts;
-    private final String rootGitDirectoryPath;
-
-    public WLDirectoryNode(String rootGitDirectoryPath, String projectName) {
-        this.rootGitDirectoryPath = rootGitDirectoryPath;
-        srcs = new HashMap<String, String>();
-        atts = new HashMap<String, String>();
-    }
-
-    public void updateFromProject(WLProject project) {
-        updateFromLatestSnapshot(project.getLatestSnapshot());
-    }
-
-    private void updateFromLatestSnapshot(Snapshot snapshot) {
-
-    }
-
-}

+ 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;
 package uk.ac.ic.wlgitbridge.writelatex.filestore;
 
 
+import uk.ac.ic.wlgitbridge.writelatex.filestore.node.WLDirectoryNode;
 import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
 import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
@@ -25,7 +26,7 @@ public class WLFileStore {
             directoryNode = new WLDirectoryNode(rootGitDirectoryPath, projectName);
             directoryNode = new WLDirectoryNode(rootGitDirectoryPath, projectName);
             fileStore.put(projectName, directoryNode);
             fileStore.put(projectName, directoryNode);
         }
         }
-        directoryNode.updateFromProject(project);
+        directoryNode.updateFromSnapshot(project.getLatestSnapshot());
     }
     }
 
 
 }
 }

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

@@ -0,0 +1,16 @@
+package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
+
+import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotAttachment;
+
+import java.util.Map;
+
+/**
+ * Created by Winston on 12/11/14.
+ */
+public class AttachmentNode extends FileNode {
+
+    public AttachmentNode(SnapshotAttachment snapshotAttachment, Map<String, FileNode> context) {
+        super(snapshotAttachment, context);
+    }
+
+}

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

@@ -0,0 +1,16 @@
+package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
+
+import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
+
+import java.util.Map;
+
+/**
+ * Created by Winston on 12/11/14.
+ */
+public class BlobNode extends FileNode {
+
+    public BlobNode(SnapshotFile snapshotFile, Map<String, FileNode> context) {
+        super(snapshotFile, context);
+    }
+
+}

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

@@ -0,0 +1,25 @@
+package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
+
+import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
+
+import java.util.Map;
+
+/**
+ * Created by Winston on 12/11/14.
+ */
+public abstract class FileNode {
+
+    private final String filePath;
+    private final boolean unchanged;
+
+    public FileNode(SnapshotFile snapshotFile, Map<String, FileNode> context) {
+        filePath = snapshotFile.getPath();
+        FileNode currentFileNode = context.get(filePath);
+        unchanged = currentFileNode != null && equals(currentFileNode);
+    }
+
+    public String getFilePath() {
+        return filePath;
+    }
+
+}

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

@@ -0,0 +1,54 @@
+package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
+
+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;
+import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
+import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by Winston on 08/11/14.
+ */
+public class WLDirectoryNode {
+
+    private Map<String, FileNode> files;
+    private final FileIndexStore fileIndexes;
+    private final String rootGitDirectoryPath;
+
+    public WLDirectoryNode(String rootGitDirectoryPath, String projectName) {
+        this.rootGitDirectoryPath = rootGitDirectoryPath;
+        files = new HashMap<String, FileNode>();
+        fileIndexes = new FileIndexStore();
+    }
+
+    public void updateFromSnapshot(Snapshot snapshot) {
+        Map<String, FileNode> updatedFiles = new HashMap<String, FileNode>();
+        List<SnapshotFile> srcs = snapshot.getSrcs();
+        List<SnapshotAttachment> atts = snapshot.getAtts();
+        for (SnapshotFile src : srcs) {
+            BlobNode blobNode = new BlobNode(src, files);
+            updatedFiles.put(blobNode.getFilePath(), blobNode);
+        }
+        for (SnapshotAttachment att : atts) {
+            AttachmentNode attachmentNode = new AttachmentNode(att, files);
+            updatedFiles.put(attachmentNode.getFilePath(), attachmentNode);
+        }
+        files = updatedFiles;
+        try {
+            throw new Throwable();
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+        System.out.println(this);
+    }
+
+    @Override
+    public String toString() {
+        return files.toString();
+    }
+
+}

+ 10 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/model/Snapshot.java

@@ -1,6 +1,7 @@
 package uk.ac.ic.wlgitbridge.writelatex.model;
 package uk.ac.ic.wlgitbridge.writelatex.model;
 
 
 import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 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.SnapshotData;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotData;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotFile;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers.SnapshotInfo;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers.SnapshotInfo;
@@ -20,7 +21,7 @@ public class Snapshot {
     private final String userEmail;
     private final String userEmail;
 
 
     private final List<SnapshotFile> srcs;
     private final List<SnapshotFile> srcs;
-    private final List<SnapshotFile> atts;
+    private final List<SnapshotAttachment> atts;
 
 
     public Snapshot(SnapshotInfo info, SnapshotData data) {
     public Snapshot(SnapshotInfo info, SnapshotData data) {
         versionID = info.getVersionId();
         versionID = info.getVersionId();
@@ -58,4 +59,12 @@ public class Snapshot {
         return userEmail;
         return userEmail;
     }
     }
 
 
+    public List<SnapshotFile> getSrcs() {
+        return srcs;
+    }
+
+    public List<SnapshotAttachment> getAtts() {
+        return atts;
+    }
+
 }
 }