Fixed test name and added to file store.

This commit is contained in:
Winston Li 2014-11-12 12:20:43 +00:00
parent ae5a55747e
commit f3a24603d9
5 changed files with 19 additions and 13 deletions

View file

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

View file

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

View file

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

View file

@ -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.Snapshot;
import uk.ac.ic.wlgitbridge.writelatex.model.WLProject; import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

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