Getting new createdAt info.

This commit is contained in:
Winston Li
2014-12-05 00:26:10 +00:00
parent 044f67ea49
commit 682f8a290c
8 changed files with 67 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ 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.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
@@ -10,6 +11,7 @@ import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProje
import java.io.IOException;
import java.util.List;
import java.util.TimeZone;
/**
* Created by Winston on 05/11/14.
@@ -44,13 +46,12 @@ public class WLBridgedProject {
throw new RepositoryNotFoundException(name);
}
try {
for (WritableRepositoryContents writableRepositoryContents : writableRepositories) {
writableRepositoryContents.write();
for (WritableRepositoryContents contents : writableRepositories) {
contents.write();
Git git = new Git(repository);
git.add().addFilepattern(".").call();
git.commit().setAuthor(writableRepositoryContents.getUserName(),
writableRepositoryContents.getUserEmail())
.setMessage(writableRepositoryContents.getCommitMessage())
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
.setMessage(contents.getCommitMessage())
.call();
}
} catch (GitAPIException e) {

View File

@@ -3,6 +3,7 @@ package uk.ac.ic.wlgitbridge.bridge;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import java.io.IOException;
import java.util.Date;
/**
* Created by Winston on 14/11/14.
@@ -14,5 +15,6 @@ public interface WritableRepositoryContents {
public String getUserName();
public String getUserEmail();
public String getCommitMessage();
public Date getWhen();
}

View File

@@ -2,6 +2,7 @@ package uk.ac.ic.wlgitbridge.writelatex;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocRequest;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocResult;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotData;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotGetForVersionRequest;
@@ -90,8 +91,9 @@ public class SnapshotFetcher implements PersistentStoreSource {
}
private int putLatestDoc(SnapshotGetDocRequest getDoc, Set<Integer> fetchedIDs, Map<Integer, SnapshotInfo> fetchedSnapshotInfos) throws FailedConnectionException, InvalidProjectException {
int latestVersionID = getDoc.getResult().getVersionID();
putFetchedResult(new SnapshotInfo(latestVersionID), fetchedIDs, fetchedSnapshotInfos);
SnapshotGetDocResult result = getDoc.getResult();
int latestVersionID = result.getVersionID();
putFetchedResult(new SnapshotInfo(latestVersionID, result.getCreatedAt(), result.getName(), result.getEmail()), fetchedIDs, fetchedSnapshotInfos);
return latestVersionID;
}

View File

@@ -13,6 +13,9 @@ import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProje
public class SnapshotGetDocResult extends Result {
private int versionID;
private String createdAt;
private String name;
private String email;
private InvalidProjectException invalidProjectException;
@@ -26,7 +29,17 @@ public class SnapshotGetDocResult extends Result {
if (jsonObject.has("status") && jsonObject.get("status").getAsInt() == 404) {
invalidProjectException = new InvalidProjectException();
} else {
versionID = json.getAsJsonObject().get("latestVerId").getAsInt();
versionID = jsonObject.get("latestVerId").getAsInt();
createdAt = jsonObject.get("latestVerAt").getAsString();
JsonElement latestVerBy = jsonObject.get("latestVerBy");
if (latestVerBy.isJsonObject()) {
JsonObject userObject = latestVerBy.getAsJsonObject();
name = userObject.get("name").getAsString();
email = userObject.get("email").getAsString();
} else {
name = "Anonymous";
email = "anonymous@writelatex.com";
}
}
}
@@ -37,4 +50,16 @@ public class SnapshotGetDocResult extends Result {
return versionID;
}
public String getCreatedAt() {
return createdAt;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
}

View File

@@ -10,10 +10,11 @@ public class SnapshotInfo {
private WLUser user;
private String createdAt;
public SnapshotInfo(int versionID) {
public SnapshotInfo(int versionID, String createdAt, String name, String email) {
this.versionId = versionID;
comment = "Update on WriteLatex.com.";
user = new WLUser();
user = new WLUser(name, email);
this.createdAt = createdAt;
}
public int getVersionId() {

View File

@@ -5,12 +5,16 @@ package uk.ac.ic.wlgitbridge.writelatex.api.request.getsavedvers;
*/
public class WLUser {
private String name;
private String email;
private final String name;
private final String email;
public WLUser() {
name = "Anonymous";
email = "anonymous@writelatex.com";
this("Anonymous", "anonymous@writelatex.com");
}
public WLUser(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() {

View File

@@ -8,6 +8,7 @@ import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
/**
@@ -20,6 +21,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
private final String userName;
private final String userEmail;
private final String commitMessage;
private final Date when;
public GitDirectoryContents(List<FileNode> fileNodes, File rootGitDirectory, String projectName, Snapshot snapshot) {
this.fileNodes = fileNodes;
@@ -27,6 +29,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
userName = snapshot.getUserName();
userEmail = snapshot.getUserEmail();
commitMessage = snapshot.getComment();
when = snapshot.getCreatedAt();
}
@Override
@@ -52,4 +55,9 @@ public class GitDirectoryContents implements WritableRepositoryContents {
return commitMessage;
}
@Override
public Date getWhen() {
return when;
}
}

View File

@@ -6,6 +6,7 @@ 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.WLUser;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -18,6 +19,7 @@ public class Snapshot implements Comparable<Snapshot> {
private final String comment;
private final String userName;
private final String userEmail;
private final Date createdAt;
private final List<SnapshotFile> srcs;
private final List<SnapshotAttachment> atts;
@@ -28,6 +30,7 @@ public class Snapshot implements Comparable<Snapshot> {
WLUser user = info.getUser();
userName = user.getName();
userEmail = user.getEmail();
createdAt = new Date();
srcs = data.getSrcs();
atts = data.getAtts();
@@ -35,9 +38,11 @@ public class Snapshot implements Comparable<Snapshot> {
public Snapshot(int versionID) {
this.versionID = versionID;
comment = "Pushed update";
comment = "Most recent update";
userName = "Anonymous";
userEmail = "anonymous@writelatex.com";
createdAt = new Date();
srcs = new LinkedList<SnapshotFile>();
atts = new LinkedList<SnapshotAttachment>();
}
@@ -66,6 +71,10 @@ public class Snapshot implements Comparable<Snapshot> {
return atts;
}
public Date getCreatedAt() {
return createdAt;
}
@Override
public int compareTo(Snapshot snapshot) {
return Integer.compare(versionID, snapshot.versionID);