Explorar o código

Fixed test name and added to file store.

Winston Li %!s(int64=12) %!d(string=hai) anos
pai
achega
f3a24603d9

+ 12 - 4
services/git-bridge/src/uk/ac/ic/wlgitbridge/bridge/WLBridgedProject.java

@@ -1,11 +1,13 @@
 package uk.ac.ic.wlgitbridge.bridge;
 
 import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
 import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
+import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
 import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
 
 import java.io.File;
@@ -37,17 +39,23 @@ public class WLBridgedProject {
         }
     }
 
-    private void updateRepositoryFromSnapshots(Repository repository) throws ServiceNotEnabledException {
+    private void updateRepositoryFromSnapshots(Repository repository) throws ServiceNotEnabledException, RepositoryNotFoundException, FailedConnectionException {
+        List<Snapshot> snapshotsToAdd;
+        try {
+            snapshotsToAdd = snapshotDBAPI.getSnapshotsToAddToProject(name);
+        } catch (InvalidProjectException e) {
+            throw new RepositoryNotFoundException(name);
+        }
         try {
-            List<Snapshot> snapshotsToAdd = snapshotDBAPI.getSnapshotsToAddToProject(name);
             for (Snapshot snapshot : snapshotsToAdd) {
                 snapshot.writeToDisk(repositoryDirectory.getAbsolutePath());
                 Git git = new Git(repository);
                 git.add().addFilepattern(".").call();
                 git.commit().setAuthor(snapshot.getUserName(), snapshot.getUserEmail()).setMessage(snapshot.getComment()).call();
             }
-        } catch (Throwable throwable) {
-            throwable.printStackTrace();
+        } catch (GitAPIException e) {
+            throw new ServiceNotEnabledException();
+        } catch (IOException e) {
             throw new ServiceNotEnabledException();
         }
     }

+ 3 - 5
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/SnapshotRepositoryBuilder.java

@@ -30,13 +30,11 @@ public class SnapshotRepositoryBuilder implements RepositorySource {
         Repository repository = null;
         try {
             repository = new FileRepositoryBuilder().setWorkTree(repositoryDirectory).build();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        try {
             new WLBridgedProject(repository, name, repositoryDirectory, snapshotDBAPI).buildRepository();
         } catch (FailedConnectionException e) {
-            e.printStackTrace();
+            throw new ServiceNotEnabledException();
+        } catch (IOException e) {
+            throw new ServiceNotEnabledException();
         }
         return repository;
     }

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

@@ -16,6 +16,8 @@ public class FileIndexStore {
         urlMappings = new HashMap<String, String>();
     }
 
-
+    public void addAttachment(String url, String filePath) {
+        urlMappings.put(url, filePath);
+    }
 
 }

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

@@ -3,8 +3,6 @@ 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.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.Map;
 

+ 1 - 1
services/git-bridge/test/uk/ac/ic/wlgitbridge/git/exception/InvalidRootDirectoryPathException.java → services/git-bridge/test/uk/ac/ic/wlgitbridge/git/exception/InvalidRootDirectoryPathExceptionTest.java

@@ -5,7 +5,7 @@ import org.junit.Test;
 /**
  * Created by Winston on 03/11/14.
  */
-public class InvalidRootDirectoryPathException {
+public class InvalidRootDirectoryPathExceptionTest {
 
     @Test
     public void nothingToTest() {