Merge bug fixes with oauth2 skipping

This commit is contained in:
Winston Li
2016-01-04 04:34:26 +00:00
8 changed files with 183 additions and 72 deletions

View File

@@ -12,6 +12,7 @@ import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
import uk.ac.ic.wlgitbridge.data.model.db.SqlitePersistentStore;
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.snapshot.getforversion.SnapshotAttachment;
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
@@ -33,7 +34,7 @@ public class DataStore {
public DataStore(String rootGitDirectoryPath) {
rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
persistentStore = new PersistentStore(rootGitDirectory);
persistentStore = new SqlitePersistentStore(rootGitDirectory);
List<String> excludedFromDeletion = persistentStore.getProjectNames();
excludedFromDeletion.add(".wlgb");
Util.deleteInDirectoryApartFrom(rootGitDirectory, excludedFromDeletion.toArray(new String[] {}));
@@ -44,10 +45,12 @@ public class DataStore {
public void updateProjectWithName(Credential oauth2, String name, Repository repository) throws IOException, SnapshotPostException, GitAPIException, ForbiddenException {
LinkedList<Snapshot> snapshots = snapshotFetcher.getSnapshotsForProjectAfterVersion(oauth2, name, persistentStore.getLatestVersionForProject(name));
makeCommitsFromSnapshots(name, repository, snapshots);
if (!snapshots.isEmpty()) {
persistentStore.setLatestVersionForProject(name, snapshots.getLast().getVersionID());
}
makeCommitsFromSnapshots(name, repository, snapshots);
}
private void makeCommitsFromSnapshots(String name, Repository repository, List<Snapshot> snapshots) throws IOException, GitAPIException {

View File

@@ -42,9 +42,15 @@ public class ResourceFetcher {
if (contents == null) {
RawFile rawFile = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path);
if (rawFile == null) {
throw new IllegalStateException("file was not in the current commit, or the git tree, yet path was not null");
Util.sout(
"WARNING: " +
"File " + path + " was not in the current commit, or the git tree, yet path was not null. " +
"File url is: " + url
);
contents = fetch(projectName, url, path);
} else {
contents = rawFile.getContents();
}
contents = rawFile.getContents();
}
}
return new RepositoryFile(newPath, contents);
@@ -83,5 +89,4 @@ public class ResourceFetcher {
persistentStore.addURLIndexForProject(projectName, url, path);
return contents;
}
}

View File

@@ -1,72 +1,20 @@
package uk.ac.ic.wlgitbridge.data.model.db;
import uk.ac.ic.wlgitbridge.data.model.db.sql.SQLiteWLDatabase;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
/**
* Created by Winston on 19/11/14.
* Created by m on 20/11/15.
*/
public class PersistentStore {
public interface PersistentStore {
List<String> getProjectNames();
private final SQLiteWLDatabase database;
void setLatestVersionForProject(String project, int versionID);
public PersistentStore(File rootGitDirectory) {
try {
database = new SQLiteWLDatabase(rootGitDirectory);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
int getLatestVersionForProject(String project);
public List<String> getProjectNames() {
try {
return database.getProjectNames();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void setLatestVersionForProject(String project, int versionID) {
try {
database.setVersionIDForProject(project, versionID);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void addURLIndexForProject(String projectName, String url, String path);
public int getLatestVersionForProject(String project) {
try {
return database.getVersionIDForProjectName(project);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void addURLIndexForProject(String projectName, String url, String path) {
try {
database.addURLIndex(projectName, url, path);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void deleteFilesForProject(String project, String... files) {
try {
database.deleteFilesForProject(project, files);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public String getPathForURLInProject(String projectName, String url) {
try {
return database.getPathForURLInProject(projectName, url);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
void deleteFilesForProject(String project, String... files);
String getPathForURLInProject(String projectName, String url);
}

View File

@@ -0,0 +1,78 @@
package uk.ac.ic.wlgitbridge.data.model.db;
import uk.ac.ic.wlgitbridge.data.model.db.sql.SQLiteWLDatabase;
import java.io.File;
import java.sql.SQLException;
import java.util.List;
/**
* Created by Winston on 19/11/14.
*/
public class SqlitePersistentStore implements PersistentStore {
private final SQLiteWLDatabase database;
public SqlitePersistentStore(File rootGitDirectory) {
try {
database = new SQLiteWLDatabase(rootGitDirectory);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public List<String> getProjectNames() {
try {
return database.getProjectNames();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void setLatestVersionForProject(String project, int versionID) {
try {
database.setVersionIDForProject(project, versionID);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public int getLatestVersionForProject(String project) {
try {
return database.getVersionIDForProjectName(project);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void addURLIndexForProject(String projectName, String url, String path) {
try {
database.addURLIndex(projectName, url, path);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public void deleteFilesForProject(String project, String... files) {
try {
database.deleteFilesForProject(project, files);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@Override
public String getPathForURLInProject(String projectName, String url) {
try {
return database.getPathForURLInProject(projectName, url);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -67,6 +67,7 @@ public class GetDocResult extends Result {
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("status")) {
switch (jsonObject.get("status").getAsInt()) {
case 401:
case 403:
forbidden = new ForbiddenException();
break;