Skip to content
Snippets Groups Projects
Commit d2fe3d8f authored by Jack MacLauchlan CS2015's avatar Jack MacLauchlan CS2015
Browse files

reset point before json only in treebuildeer

parent e32073c3
No related branches found
No related tags found
1 merge request!2Commit tree
......@@ -10,4 +10,6 @@ when github central server gets pushed send emails, subscribers get emailed, pos
edit time on merge
truncate the input
\ No newline at end of file
truncate the input
filter comments by time
\ No newline at end of file
package git;
import com.fasterxml.jackson.databind.ObjectMapper;
import issueData.Comment;
import issueData.Issue;
import org.eclipse.jgit.lib.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
class IssueTreeBuilder {
private final ObjectInserter oi;
private ObjectMapper mapper = new ObjectMapper();
IssueTreeBuilder(Repository repository) {
this.oi = new ObjectInserter(repository);
}
ObjectId buildIssueTree(Issue issue) throws IOException {
TreeFormatter issueTreeFormatter = new TreeFormatter();
ObjectId title = oi.insert(Constants.OBJ_BLOB, issue.getTitle().getBytes());
ObjectId description = oi.insert(Constants.OBJ_BLOB, issue.getDescription().getBytes());
ObjectId creator = oi.insert(Constants.OBJ_BLOB, (issue.getCreator().name + "\n" + issue.getCreator().email).getBytes());
ObjectId status = oi.insert(Constants.OBJ_BLOB, String.valueOf(issue.isOpen()).getBytes());
ObjectId creationTime = oi.insert(Constants.OBJ_BLOB, String.valueOf(issue.getCreationTime()).getBytes());
ObjectId editTime = oi.insert(Constants.OBJ_BLOB, String.valueOf(issue.getEdited()).getBytes());
ObjectId tags = oi.insert(Constants.OBJ_BLOB, buildTagString(issue.getTags()).getBytes());
byte[] titleJson = mapper.writeValueAsBytes(issue.getTitle());
byte[] descriptionJson = mapper.writeValueAsBytes(issue.getDescription());
byte[] creatorJson = mapper.writeValueAsBytes(issue.getCreator());
byte[] statusJson = mapper.writeValueAsBytes(issue.isOpen());
byte[] creationTimeJson = mapper.writeValueAsBytes(issue.getCreationTime());
byte[] editTimeJson = mapper.writeValueAsBytes(issue.getEdited());
byte[] tagsJsonBytes = mapper.writeValueAsBytes(issue.getTags());
ObjectId title = oi.insert(Constants.OBJ_BLOB, titleJson);
ObjectId description = oi.insert(Constants.OBJ_BLOB, descriptionJson);
ObjectId creator = oi.insert(Constants.OBJ_BLOB, creatorJson);
ObjectId status = oi.insert(Constants.OBJ_BLOB, statusJson);
ObjectId creationTime = oi.insert(Constants.OBJ_BLOB, creationTimeJson);
ObjectId editTime = oi.insert(Constants.OBJ_BLOB, editTimeJson);
ObjectId tags = oi.insert(Constants.OBJ_BLOB, tagsJsonBytes);
ObjectId comments = buildCommentTree(issue.getComments());
......@@ -48,9 +57,14 @@ class IssueTreeBuilder {
for (Comment comment : comments) {
TreeFormatter commentTreeFormatter = new TreeFormatter();
ObjectId author = oi.insert(Constants.OBJ_BLOB, (comment.getAuthor().name + "\n" + comment.getAuthor().name).getBytes());
ObjectId message = oi.insert(Constants.OBJ_BLOB, comment.getMessage().getBytes());
ObjectId commentTime = oi.insert(Constants.OBJ_BLOB, String.valueOf(comment.getCreationTime()).getBytes());
byte[] authorJson = mapper.writeValueAsBytes(comment.getAuthor());
byte[] messageJson = mapper.writeValueAsBytes(comment.getMessage());
byte[] commentTimeJson = mapper.writeValueAsBytes(comment.getCreationTime());
ObjectId author = oi.insert(Constants.OBJ_BLOB, authorJson);
ObjectId message = oi.insert(Constants.OBJ_BLOB, messageJson);
ObjectId commentTime = oi.insert(Constants.OBJ_BLOB, commentTimeJson);
commentTreeFormatter.append("author", FileMode.REGULAR_FILE, author);
commentTreeFormatter.append("commentTime", FileMode.REGULAR_FILE, commentTime);
......@@ -64,23 +78,5 @@ class IssueTreeBuilder {
return oi.insert(Constants.OBJ_TREE, allCommentTreeFormatter.toByteArray());
}
private String buildTagString(Set<String> tags) {
StringBuilder stringBuilder = new StringBuilder();
Iterator<String> iterator = tags.iterator();
if (!iterator.hasNext()) {
return "";
}
for (; ; ) {
stringBuilder.append(iterator.next());
if (!iterator.hasNext()) {
return stringBuilder.toString();
}
stringBuilder.append(", ");
}
}
}
......@@ -8,6 +8,8 @@ public class Issue {
private final Set<String> tags;
private final List<Comment> comments;
private List<User> assignees;
private List<User> watchers;
private String title;
private String description;
private User creator;
......@@ -26,11 +28,15 @@ public class Issue {
this.originalHash = DigestUtils.sha256Hex(title + description + creationTime);
this.comments = new ArrayList<>();
this.tags = new HashSet<>();
this.assignees = new ArrayList<>();
this.watchers = new ArrayList<>();
}
public Issue() {
comments = new ArrayList<>();
tags = new HashSet<>();
assignees = new ArrayList<>();
watchers = new ArrayList<>();
}
public void edited() {
......@@ -69,6 +75,30 @@ public class Issue {
return comments;
}
public void addWatcher(User user) {
watchers.add(user);
}
public List<User> getWatchers(){
return watchers;
}
public void removeWatcher(User user){
watchers.remove(user);
}
public void addAssignee(User user) {
assignees.add(user);
}
public List<User> getAssignees(){
return assignees;
}
public void removeAssignee(User user){
assignees.remove(user);
}
public void addTag(String tag) {
List<String> strings = Arrays.asList(tag.split("\\s*,\\s*"));
strings.forEach(t -> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment