BrightSide Workbench Full Report + Source Code
DossierVertexProvider.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.entitites.graph;
20 
21 import java.util.HashSet;
22 import java.util.Set;
23 import java.util.stream.Collectors;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Category;
26 import org.turro.dossier.entity.CategoryParticipant;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.Participant;
29 import org.turro.entities.graph.EntityEdge;
30 import org.turro.entities.graph.IVertexProvider;
31 import org.turro.jpa.Dao;
32 import org.turro.sql.SqlClause;
33 
38 public class DossierVertexProvider implements IVertexProvider {
39 
40  @Override
41  public Set<EntityEdge> getEdges() {
42  Dao dao = new DossierPU();
43  Set<EntityEdge> set = new HashSet<>();
44  set.addAll(SqlClause.select("cp").from("CategoryParticipant cp")
45  .dao(dao)
46  .resultList(CategoryParticipant.class)
47  .stream()
48  .map(cp -> new EntityEdge(
49  convert("contact", cp.getIContact()),
50  convert("dossier-category", cp.getCategory().getId(), cp.getCategory().getDescription())))
51  .collect(Collectors.toSet()));
52  set.addAll(SqlClause.select("p").from("Participant p")
53  .dao(dao)
54  .resultList(Participant.class)
55  .stream()
56  .map(cp -> new EntityEdge(
57  convert("contact", cp.getIContact()),
58  convert("dossier", cp.getDossier().getId(), cp.getDossier().getDescription())))
59  .collect(Collectors.toSet()));
60  set.addAll(SqlClause.select("c").from("Category c")
61  .where().isNotNull("c.parent")
62  .dao(dao)
63  .resultList(Category.class)
64  .stream()
65  .map(c -> new EntityEdge(
66  convert("dossier-category", c.getId(), c.getDescription()),
67  convert("dossier-category", c.getParent().getId(), c.getParent().getDescription())))
68  .collect(Collectors.toSet()));
69  set.addAll(SqlClause.select("d").from("Dossier d")
70  .dao(dao)
71  .resultList(Dossier.class)
72  .stream()
73  .map(d -> new EntityEdge(
74  convert("dossier", d.getId(), d.getDescription()),
75  convert("dossier-category", d.getCategory().getId(), d.getCategory().getDescription())))
76  .collect(Collectors.toSet()));
77 // set.addAll(SqlClause.select("ip").from("IssueParticipant ip")
78 // .dao(dao)
79 // .resultList(IssueParticipant.class)
80 // .stream()
81 // .map(cp -> new EntityEdge(
82 // convert("contact", cp.getIContact()),
83 // convert("issue", cp.getIssue().getId(), cp.getIssue().getDescription())))
84 // .collect(Collectors.toSet()));
85 // set.addAll(SqlClause.select("i").from("Issue i")
86 // .dao(dao)
87 // .resultList(Issue.class)
88 // .stream()
89 // .map(i -> new EntityEdge(
90 // convert("issue", i.getId(), i.getDescription()),
91 // convert("dossier", i.getDossier().getId(), i.getDossier().getDescription())))
92 // .collect(Collectors.toSet()));
93  return set;
94  }
95 
96 }
default EntityVertex convert(String root, String id, String name)