19 package org.turro.dossier.graph;
22 import org.jgrapht.Graph;
23 import org.jgrapht.Graphs;
24 import org.jgrapht.graph.DefaultEdge;
25 import org.jgrapht.graph.SimpleDirectedGraph;
26 import org.turro.dossier.db.DossierPU;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.Issue;
29 import org.turro.dossier.entity.IssuePredecessor;
30 import org.turro.jpa.Dao;
31 import org.turro.sql.SqlClause;
32 import org.turro.util.Cached;
38 public class IssueGraph extends SimpleDirectedGraph<IssueVertex, IssueEdge> {
42 private void addVertices() {
43 SqlClause.select(
"i").from(
"Issue i")
44 .startIf(onlyPublishable)
45 .where().equal(
"publishable",
true)
47 .startIf(onlyMilestones)
48 .whereOrAnd().equal(
"i.milestone",
true)
50 .startIf(dossier !=
null)
51 .whereOrAnd().equal(
"i.dossier", dossier)
54 .resultList(
Issue.class)
56 addVertex(milestoneOf(issue));
60 private void addEdges() {
62 Graph<Long, DefaultEdge> predecessorGraph =
new SimpleDirectedGraph<>(DefaultEdge.class);
63 SqlClause.select(
"i").from(
"IssuePredecessor i")
64 .startIf(dossier !=
null)
65 .where().equal(
"i.source.dossier", dossier)
66 .and().equal(
"i.target.dossier", dossier)
70 .forEach(predecessor -> {
71 Graphs.addEdgeWithVertices(predecessorGraph, predecessor.getSource().getId(), predecessor.getTarget().getId());
75 Set.copyOf(predecessorGraph.vertexSet()).forEach(vertex -> {
76 if(!containsVertex(milestoneOf(vertex))) {
77 Graphs.removeVertexAndPreserveConnectivity(predecessorGraph, vertex);
82 vertexSet().forEach(m1 -> {
83 vertexSet().forEach(m2 -> {
84 if(predecessorGraph.containsEdge(m1.getItem().getIssueId(), m2.getItem().getIssueId())) {
85 Graphs.addEdgeWithVertices(this, m1, m2);
99 private final Cached<Dao> dao = Cached.instance(() ->
new DossierPU());
104 private final boolean onlyMilestones, onlyPublishable;
133 this.onlyMilestones =
true;
134 this.onlyPublishable = onlyPublishable;
137 private IssueGraph(Dossier dossier,
boolean onlyMilestones,
boolean onlyPublishable) {
138 super(IssueEdge.class);
139 this.dossier = dossier;
140 this.onlyMilestones = onlyMilestones;
141 this.onlyPublishable = onlyPublishable;
static IssueGraph milestones(Dossier dossier)
static IssueGraph loadPublishable(Dossier dossier)
static IssueGraph publishable()
static IssueGraph load(Dossier dossier)
static IssueGraph publishableMilestones(Dossier dossier)