Skip to content

Commit

Permalink
Nest topComments in abstracts
Browse files Browse the repository at this point in the history
Almost all of a topComment is now nested in an abstract, using IDs to
join other objects. The last piece is getting users to be able to joined
inside of the `subComments` field `commenter`.

The `group` method needs to re-add all fields via `first`, but for now
it's easier to debug without all of those there.

Issue #147 (Create comment object)
Epic #217 (Comment on Abstracts)
Epic #131 (Submission Card View)
  • Loading branch information
michael-small committed Dec 24, 2019
1 parent f1277df commit 24338a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
Expand All @@ -21,6 +22,10 @@
import java.util.Date;
import java.util.Map;

import static com.mongodb.client.model.Accumulators.first;
import static com.mongodb.client.model.Accumulators.push;
import static com.mongodb.client.model.Sorts.*;

public class AbstractController {

private final MongoCollection<Document> abstractCollection;
Expand Down Expand Up @@ -55,10 +60,15 @@ String getAbstractsForUser(String id) {//https://github.com/Megabittron/Deployme
public String getSingleAbstract(String id){
AggregateIterable<Document> singleAbstract = abstractCollection.aggregate(Arrays.asList(
Aggregates.match(new Document("_id", new ObjectId(id))),
Aggregates.lookup("topComments", "topComments", "_id", "topComments")
// Aggregates.unwind("$topComments"),
// Aggregates.lookup("users","topComments.commenter","_id","topComments.commenter"),
// Aggregates.unwind("$topComments.commenter")
Aggregates.lookup("topComments", "topComments", "_id", "topComments"),
Aggregates.unwind("$topComments"),
Aggregates.lookup("users","topComments.commenter","_id","topComments.commenter"),
Aggregates.unwind("$topComments.commenter"),
Aggregates.lookup("subComments", "topComments.subComments", "_id", "topComments.subComments"),
// Aggregates.lookup("users", "topComments.subComments.commenter", "_id", "topComments.subComments.commenter"),
Aggregates.group("$_id", first("userID","$userID"),
first("presentationTitle","$presentationTitle"),
push("topComments", "$topComments"))
));

System.out.println("final result: \n" + toPrettyFormat(singleAbstract.first().toJson()));
Expand Down
47 changes: 27 additions & 20 deletions subComments.seed.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
[
{
"_id": {
"$oid": "5b3524ba76bdf718e137b482"
"$oid": "4d4424ba76bdf718e1374492"
},
"commenter":
{
"_id": {
"$oid": "5b4fafaa7ff1d34e9da88ccb"
},
"SubjectID": "910073864477046231181",
"FirstName": "COMMMMMMMMMMMENTER",
"LastName": "McCOMMMMMMMMMMMMMMMMMMMMMMMMM",
"ShirtSize": "m",
"Role": "user"
"$oid": "5b4fafaa7ff1d34e9da88ccb"
},
"commenterInput": "I just formalized and followed up about Levi's. Look good?",
"resolved": false,
"timestamp": "Wed Feb 15 16:23:20 CST 2020"
},
{
"_id": {
"$oid": "4d4424ba76bdf718e1374444"
"$oid": "5b3524ba76bdf718e137b491"
},
"commenter":
{
"_id": {
"$oid": "6b4fafaa7ff1d34e9da88cca"
},
"SubjectID": "110073864477046231189",
"FirstName": "Travis",
"LastName": "McElroy",
"ShirtSize": "m",
"Role": "reviewer"
"$oid": "6b4fafaa7ff1d34e9da88cca"
},
"commenterInput": "Looks good for the most part. Though you could condense the two sentences about the Levi's tagline into one.",
"timestamp": "Wed Feb 15 17:23:20 CST 2020"
}
},
{
"_id": {
"$oid": "4d4424ba76bdf718e1374494"
},
"commenter":
{
"$oid": "5b4fafaa7ff1d34e9da88ccb"
},
"commenterInput": "Because I am...",
"timestamp": "Wed Feb 15 16:23:20 CST 2020"
},
{
"_id": {
"$oid": "5b3524ba76bdf718e137b493"
},
"commenter":
{
"$oid": "6b4fafaa7ff1d34e9da88cca"
},
"commenterInput": "Cool cool...",
"timestamp": "Wed Feb 15 17:23:20 CST 2020"
}
]
74 changes: 4 additions & 70 deletions topComments.seed.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,10 @@
"subComments":
[
{
"_id": {
"$oid": "5b3524ba76bdf718e137b482"
},
"commenter":
{
"_id": {
"$oid": "5b4fafaa7ff1d34e9da88ccb"
},
"SubjectID": "910073864477046231181",
"FirstName": "Griffin",
"LastName": "McElroy",
"ShirtSize": "m",
"Role": "user"
},
"commenterInput": "I just formalized and followed up about Levi's. Look good?",
"resolved": false,
"timestamp": "Wed Feb 15 16:23:20 CST 2020"
"$oid": "5b3524ba76bdf718e137b491"
},
{
"_id": {
"$oid": "4d4424ba76bdf718e1374444"
},
"commenter":

{
"_id": {
"$oid": "6b4fafaa7ff1d34e9da88cca"
},
"SubjectID": "110073864477046231189",
"FirstName": "Travis",
"LastName": "McElroy",
"ShirtSize": "m",
"Role": "reviewer"
}
,
"commenterInput": "Looks good for the most part. Though you could condense the two sentences about the Levi's tagline into one.",
"timestamp": "Wed Feb 15 17:23:20 CST 2020"
"$oid": "4d4424ba76bdf718e1374492"
}
],
"quotedSnippet": "Denim was-- denim was invented, so that like, cows, when they bit you, it didn't hurt very bad.",
Expand All @@ -63,43 +30,10 @@
"subComments":
[
{
"_id": {
"$oid": "5b3524ba76bdf718e137b482"
},
"commenter":
{
"_id": {
"$oid": "5b4fafaa7ff1d34e9da88ccb"
},
"SubjectID": "910073864477046231181",
"FirstName": "Griffin",
"LastName": "McElroy",
"ShirtSize": "m",
"Role": "user"
},
"commenterInput": "Because I am...",
"resolved": false,
"timestamp": "Wed Feb 15 16:23:20 CST 2020"
"$oid": "5b3524ba76bdf718e137b493"
},
{
"_id": {
"$oid": "4d4424ba76bdf718e1374444"
},
"commenter":

{
"_id": {
"$oid": "6b4fafaa7ff1d34e9da88cca"
},
"SubjectID": "110073864477046231189",
"FirstName": "Travis",
"LastName": "McElroy",
"ShirtSize": "m",
"Role": "reviewer"
}
,
"commenterInput": "Cool cool...",
"timestamp": "Wed Feb 15 17:23:20 CST 2020"
"$oid": "4d4424ba76bdf718e1374494"
}
],
"commenterInput": "Why are you even doing this topic?",
Expand Down

0 comments on commit 24338a3

Please sign in to comment.