|
|
@@ -1,8 +1,10 @@
|
|
|
package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
|
|
|
|
|
|
+import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
|
|
|
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.RepositoryFile;
|
|
|
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
|
|
|
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
|
|
|
|
|
|
@@ -10,6 +12,7 @@ import java.util.HashMap;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
|
|
|
/**
|
|
|
* Created by Winston on 08/11/14.
|
|
|
@@ -20,8 +23,12 @@ public class WLDirectoryNode {
|
|
|
private FileIndexStore fileIndexStore;
|
|
|
|
|
|
public WLDirectoryNode() {
|
|
|
- fileNodeTable = new HashMap<String, FileNode>();
|
|
|
- fileIndexStore = new FileIndexStore();
|
|
|
+ this(new HashMap<String, FileNode>(), new FileIndexStore());
|
|
|
+ }
|
|
|
+
|
|
|
+ public WLDirectoryNode(Map<String, FileNode> fileNodeTable, FileIndexStore fileIndexStore) {
|
|
|
+ this.fileNodeTable = fileNodeTable;
|
|
|
+ this.fileIndexStore = fileIndexStore;
|
|
|
}
|
|
|
|
|
|
public List<FileNode> updateFromSnapshot(Snapshot snapshot) throws FailedConnectionException {
|
|
|
@@ -36,12 +43,22 @@ public class WLDirectoryNode {
|
|
|
AttachmentNode attachmentNode = new AttachmentNode(att, fileNodeTable, fileIndexStore);
|
|
|
updatedFileNodeTable.put(attachmentNode.getFilePath(), attachmentNode);
|
|
|
}
|
|
|
- fileNodeTable = updatedFileNodeTable;
|
|
|
LinkedList<FileNode> fileNodes = new LinkedList<FileNode>(updatedFileNodeTable.values());
|
|
|
+ fileNodeTable = updatedFileNodeTable;
|
|
|
fileIndexStore = new FileIndexStore(fileNodes);
|
|
|
return fileNodes;
|
|
|
}
|
|
|
|
|
|
+ public WLDirectoryNode createFromRawDirectoryContents(RawDirectoryContents rawDirectoryContents) {
|
|
|
+ Map<String, FileNode> candidateFileNodeTable = new HashMap<String, FileNode>();
|
|
|
+ for (Entry<String, byte[]> fileContents : rawDirectoryContents.getFileContentsTable().entrySet()) {
|
|
|
+ BlobNode blobNode = new BlobNode(new RepositoryFile(fileContents), fileNodeTable);
|
|
|
+ candidateFileNodeTable.put(blobNode.getFilePath(), blobNode);
|
|
|
+ }
|
|
|
+ return new WLDirectoryNode(candidateFileNodeTable,
|
|
|
+ new FileIndexStore(new LinkedList<FileNode>(candidateFileNodeTable.values())));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
return fileNodeTable.toString();
|