19 package org.turro.dossier.gantt;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
25 import java.util.stream.Collectors;
26 import org.amic.util.date.CheckDate;
27 import org.turro.dossier.db.DossierPU;
28 import org.turro.dossier.entity.Dossier;
29 import org.turro.dossier.entity.Issue;
30 import org.turro.dossier.entity.IssuePredecessor;
31 import org.turro.dossier.task.Tasks;
32 import org.turro.jpa.Dao;
33 import org.turro.sql.SqlClause;
34 import org.turro.util.Cached;
35 import org.turro.util.Comparison;
36 import org.turro.util.Converter;
37 import org.turro.web.gantt.GanttWrapper;
46 private final List<Issue> issues;
48 private boolean publishable =
true;
51 this.dossier = dossier;
52 this.issues =
new ArrayList<>();
56 return !SqlClause.select(
"i").from(
"Issue i")
57 .where().equal(
"i.milestone",
true)
59 .and().equal(
"i.publishable",
true)
61 .startIf(dossier !=
null)
62 .and().equal(
"i.dossier", dossier)
64 .and().group().isNotNull(
"i.startDate")
65 .or().isNotNull(
"i.delivery").endGroup()
67 SqlClause.select(
"p").from(
"IssuePredecessor p")
68 .where(
"p.source = i.id")
72 .resultList(
Issue.class)
77 getIssues().forEach(i -> {
83 private List<Issue> getIssues() {
84 return SqlClause.select(
"i").from(
"Issue i")
85 .where().equal(
"i.milestone",
true)
87 .and().equal(
"i.publishable",
true)
89 .startIf(dossier !=
null)
90 .and().equal(
"i.dossier", dossier)
92 .and().group().isNotNull(
"i.startDate")
93 .or().isNotNull(
"i.delivery").endGroup()
95 SqlClause.select(
"p").from(
"IssuePredecessor p")
96 .where(
"p.source = i.id")
99 .resultList(
Issue.class);
102 private void addItem(Issue issue) {
103 Set<IssuePredecessor> incoming = issue.getSources();
104 String dependencies = incoming.stream()
105 .map(i -> i.getSource().getId().toString())
106 .collect(Collectors.joining(
","));
107 Date start = getStart(issue, issue.getStartDate());
109 issue.getDescription(), dependencies,
110 getStart(issue, issue.getStartDate()),
111 getDelivery(start, issue.getDelivery()),
112 Converter.STANDARD.convert(
percentDone(issue), Integer.class),
115 .map(p -> p.getSource())
116 .sorted((i1, i2) -> compare(i1, i2))
117 .forEach(i -> addItem(i));
120 private int compare(Issue i1, Issue i2) {
121 return Comparison.ascendant()
122 .compare(i1.getStartDate(), i2.getStartDate())
123 .compare(i1.getDescription(), i2.getDescription())
127 private Date getStart(Issue issue, Date startDate) {
128 if(startDate ==
null) {
129 for(IssuePredecessor p : issue.getTargets()) {
130 Date tmp = p.getTarget().getStartDate();
134 startDate = getStart(p.getTarget(), tmp);
136 if(startDate !=
null) {
137 startDate =
new CheckDate(startDate).addDays(-1).getDate();
145 private Date getDelivery(Date start, Date delivery) {
146 if(delivery ==
null) {
147 delivery =
new CheckDate(start).addDays(1).getDate();
152 private String getCssClass(Issue issue) {
153 String css =
"gantt-task";
154 if(issue.isMilestone()) {
157 if(issue.getStatus().isFinished()) {
171 private final Cached<Dao> dao = Cached.instance(() ->
new DossierPU());
DossierGanttWrapper(Dossier dossier)
double percentDone(Issue issue)
static Tasks from(Dossier dossier, boolean onlyOpen, boolean sameDossier)
double getPercentTasksDone()
void addItem(String id, String name, List< String > dependencies, Date start, Date end, int progress)