diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getdoc/GetDocResult.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getdoc/GetDocResult.java index b47f3ccfb5..7ce5e7b14e 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getdoc/GetDocResult.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getdoc/GetDocResult.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import uk.ac.ic.wlgitbridge.snapshot.base.Result; import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException; import uk.ac.ic.wlgitbridge.snapshot.getdoc.exception.InvalidProjectException; +import uk.ac.ic.wlgitbridge.snapshot.getsavedvers.WLUser; import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException; import uk.ac.ic.wlgitbridge.snapshot.base.Request; import uk.ac.ic.wlgitbridge.snapshot.getdoc.exception.ProtectedProjectException; @@ -17,8 +18,7 @@ public class GetDocResult extends Result { private int error; private int versionID; private String createdAt; - private String name; - private String email; + private WLUser user; private SnapshotPostException exception; @@ -34,8 +34,7 @@ public class GetDocResult extends Result { } this.versionID = versionID; this.createdAt = createdAt; - this.name = name; - this.email = email; + this.user = new WLUser(name, email); } @Override @@ -45,8 +44,8 @@ public class GetDocResult extends Result { jsonThis.addProperty("latestVerId", versionID); jsonThis.addProperty("latestVerAt", createdAt); JsonObject latestVerBy = new JsonObject(); - latestVerBy.addProperty("email", email); - latestVerBy.addProperty("name", name); + latestVerBy.addProperty("email", getEmail()); + latestVerBy.addProperty("name", getName()); jsonThis.add("latestVerBy", latestVerBy); } else { jsonThis.addProperty("status", error); @@ -78,15 +77,17 @@ public class GetDocResult extends Result { } else { versionID = jsonObject.get("latestVerId").getAsInt(); createdAt = jsonObject.get("latestVerAt").getAsString(); + String name = null; + String email = null; 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@overleaf.com"; } + + user = new WLUser(name, email); } } @@ -102,11 +103,11 @@ public class GetDocResult extends Result { } public String getName() { - return name; + return user.getName(); } public String getEmail() { - return email; + return user.getEmail(); } } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/SnapshotInfo.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/SnapshotInfo.java index f64665cc71..9fae0a15a2 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/SnapshotInfo.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/SnapshotInfo.java @@ -32,7 +32,7 @@ public class SnapshotInfo implements Comparable { } public WLUser getUser() { - return user; + return user != null ? user : new WLUser(); } public String getCreatedAt() { diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/WLUser.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/WLUser.java index 5a67e05392..8335d6dc43 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/WLUser.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/getsavedvers/WLUser.java @@ -11,12 +11,17 @@ public class WLUser { private final String email; public WLUser() { - this("Anonymous", "anonymous@" + Util.getServiceName().toLowerCase() + ".com"); + this(null, null); } public WLUser(String name, String email) { - this.name = name; - this.email = email; + if (name != null && email != null) { + this.name = name; + this.email = email; + } else { + this.name = "Anonymous"; + this.email = "anonymous@" + Util.getServiceName().toLowerCase() + ".com"; + } } public String getName() {