I have a collection of documents: List listDocs. The document has the structure of the form:
id, level, aoguid, parentguid, formalname, currstatus
. This structure allows you to create a tree structure of addresses. That is: a country - level 1, a city - level 2, a street - level 3, and so on up to level 7. Some levels may or may not be. My task: to form json containing the full address and an array of parts making up the full address.
{
"full Address": "Country city street house",
"parts": [
{
"id": 1,
"aoguid": 1,
"parentguid": 0,
"formalname": "country",
"currstatus": 0
},
{
"id": 2,
"aoguid": 2,
"parentguid": 1,
"formalname": "city",
"currstatus": 0
},
{
"id": 3,
"aoguid": 3,
"parentguid": 2,
"formalname": "street",
"currstatus": 0
},
{
"id": 4,
"aoguid": 4,
"parentguid": 3,
"formalname": "house",
"currstatus": 0
}
]
}
The task is complicated by the fact that the project uses mongoDb, not a relational database. But I found that using the JOOL framework, you can make JAVA queries like SQL. I wrote this code:
Seq<Document> seq1 = Seq.seq(listDocs).filter(
it -> isNull(it.get("currstatus")) || "0".equals(it.get("currstatus"))
);
Seq<Document> seq2 = seq1;
Seq<Document> seq3 = seq1;
Seq<Document> seq4 = seq1;
Seq<Document> seq5 = seq1;
Seq<Document> seq6 = seq1;
Seq<Document> seq7 = seq1;
seq1
.leftOuterJoin(seq2, (l1, l2) -> Objects.equals(l1.get("aoguid"), l2.get("parentguid")))
.leftOuterJoin(seq3, (l2, l3) -> Objects.equals(l2.v2.get("aoguid"), l3.get("parentguid")))
.leftOuterJoin(seq4, (l3, l4) -> Objects.equals(l3.v3.get("aoguid"), l4.get("parentguid")))
.leftOuterJoin(seq5, (l4, l5) -> Objects.equals(l4.v4.get("aoguid"), l5.get("parentguid")))
.leftOuterJoin(seq6, (l5, l6) -> Objects.equals(l5.v5.get("aoguid"), l6.get("parentguid")))
.leftOuterJoin(seq7, (l6, l7) -> Objects.equals(l6.v6.get("aoguid"), l7.get("parentguid")))
.parallel()
.forEach(it -> {
System.out.println("Some actions....");
});
But this code does not compile. How can I fix it so that everything works?