BrightSide Workbench Full Report + Source Code
DossierActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.activity;
20 
21 import org.turro.dossier.db.DossierPU;
22 import org.turro.dossier.entity.Dossier;
23 import org.turro.dossier.entity.IssueComment;
24 import org.turro.dossier.entity.Participant;
25 import org.turro.entities.Entities;
26 import org.turro.entities.IElephantEntity;
27 import org.turro.jpa.Dao;
28 import org.turro.sql.SqlClause;
29 import org.turro.util.Cached;
30 
35 @ElephantActivity
36 public class DossierActivity implements IElephantActivity {
37 
38  @Override
39  public void generate() {
40  Activities staacts = Activities.of("Started");
41  SqlClause.select("project.dossier").from("Project project")
42  .where().greater("project.startDate", staacts.lastDate())
43  .dao(dao.get()).forEach(Dossier.class, dossier -> {
44  IElephantEntity idossier = Entities.getController(dossier);
45  if(!idossier.isEmpty()) {
46  staacts.add(dossier.getProject().getStartDate(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
47  }
48  });
49  Activities apracts = Activities.of("Approved");
50  SqlClause.select("project.dossier").from("Project project")
51  .where().greater("project.approvedDate", apracts.lastDate())
52  .dao(dao.get()).forEach(Dossier.class, dossier -> {
53  IElephantEntity idossier = Entities.getController(dossier);
54  if(!idossier.isEmpty()) {
55  apracts.add(dossier.getProject().getApprovedDate(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
56  }
57  });
58  Activities opoacts = Activities.of("End oppositing");
59  SqlClause.select("project.dossier").from("Project project")
60  .where().greater("project.oppositingEndDate", opoacts.lastDate())
61  .dao(dao.get()).forEach(Dossier.class, dossier -> {
62  IElephantEntity idossier = Entities.getController(dossier);
63  if(!idossier.isEmpty()) {
64  opoacts.add(dossier.getProject().getOppositingEndDate(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
65  }
66  });
67  Activities endacts = Activities.of("Ended");
68  SqlClause.select("project.dossier").from("Project project")
69  .where().greater("project.endDate", endacts.lastDate())
70  .dao(dao.get()).forEach(Dossier.class, dossier -> {
71  IElephantEntity idossier = Entities.getController(dossier);
72  if(!idossier.isEmpty()) {
73  endacts.add(dossier.getProject().getEndDate(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
74  }
75  });
76  Activities chaacts = Activities.of("Changed phase");
77  SqlClause.select("project.dossier").from("Project project")
78  .where().greater("project.changePhase", chaacts.lastDate())
79  .dao(dao.get()).forEach(Dossier.class, dossier -> {
80  IElephantEntity idossier = Entities.getController(dossier);
81  if(!idossier.isEmpty()) {
82  chaacts.add(dossier.getProject().getChangePhase(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
83  }
84  });
85  Activities creacts = Activities.of("Created");
86  SqlClause.select("dossier").from("Dossier dossier")
87  .where().greater("dossier.creation", creacts.lastDate())
88  .dao(dao.get()).forEach(Dossier.class, dossier -> {
89  IElephantEntity idossier = Entities.getController(dossier);
90  if(!idossier.isEmpty()) {
91  creacts.add(dossier.getCreation(), idossier.getPath(), idossier.getPath(), idossier.getHierarchicalPath());
92  }
93  });
94  Activities newacts = Activities.of("New participant");
95  SqlClause.select("par").from("Participant par")
96  .where().greater("par.creation", newacts.lastDate())
97  .dao(dao.get()).forEach(Participant.class, par -> {
98  IElephantEntity idossier = Entities.getController(par.getDossier());
99  if(!idossier.isEmpty()) {
100  String path = DossierPU.getObjectPath(par);
101  newacts.add(par.getCreation(), path, idossier.getPath(), idossier.getHierarchicalPath());
102  }
103  });
104  Activities icoacts = Activities.of("Informed");
105  SqlClause.select("icom").from("IssueComment icom")
106  .where().greater("icom.modification", icoacts.lastDate())
107  .dao(dao.get()).forEach(IssueComment.class, icom -> {
108  IElephantEntity iissue = Entities.getController(icom.getIssue());
109  if(!iissue.isEmpty()) {
110  String path = DossierPU.getObjectPath(icom);
111  icoacts.add(icom.getModification(), path, iissue.getPath(), iissue.getHierarchicalPath());
112  }
113  });
114  }
115 
116  /* Dao */
117 
118  private final Cached<Dao> dao = Cached.instance(() -> new DossierPU());
119 
120 }
static Activities of(String reason)