BrightSide Workbench Full Report + Source Code
DossierLastActivity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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 java.util.Date;
22 import java.util.List;
23 import org.turro.string.Strings;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.dossier.entity.IssueComment;
28 import org.turro.dossier.entity.Participant;
29 import org.turro.dossier.entity.Project;
30 import org.turro.elephant.db.WhereClause;
31 import org.turro.entities.Entities;
32 import org.turro.jpa.Dao;
33 import org.turro.path.Path;
34 
39 @LastActivity
40 public class DossierLastActivity implements ILastActivity {
41 
42  @Override
43  public EntityActivitySet getActivities(Date from, String entityPath, String type) {
45  Path path = Strings.isBlank(entityPath) ? null : new Path(entityPath);
46  if(path == null || "dossier".equals(path.getRoot())) {
47  for(Object obj : getProjects(from, null, "startDate")) {
48  Project project = (Project) obj;
50  project.getDossier(), DossierPU.getObjectPath(project.getDossier()), project.getStartDate(), "Started");
52  set.add(ela);
53  }
54  for(Object obj : getProjects(from, null, "approvedDate")) {
55  Project project = (Project) obj;
57  project.getDossier(), DossierPU.getObjectPath(project.getDossier()), project.getApprovedDate(), "lApproved");
59  set.add(ela);
60  }
61  for(Object obj : getProjects(from, null, "oppositingEndDate")) {
62  Project project = (Project) obj;
64  project.getDossier(), DossierPU.getObjectPath(project.getDossier()), project.getOppositingEndDate(), "lEndOppositing");
66  set.add(ela);
67  }
68  for(Object obj : getProjects(from, null, "endDate")) {
69  Project project = (Project) obj;
71  project.getDossier(), DossierPU.getObjectPath(project.getDossier()), project.getEndDate(), "Ended");
73  set.add(ela);
74  }
75  for(Object obj : getProjects(from, null, "changePhase")) {
76  Project project = (Project) obj;
78  project.getDossier(), DossierPU.getObjectPath(project.getDossier()), project.getChangePhase(), "Changed phase");
80  set.add(ela);
81  }
82  for(Object obj : getDossiers(from, null)) {
83  Dossier dossier = (Dossier) obj;
85  dossier, DossierPU.getObjectPath(dossier), dossier.getCreation(), "Created");
87  set.add(ela);
88  }
89  for(Object obj : getParticipants(from, null)) {
90  Participant participant = (Participant) obj;
92  participant, DossierPU.getObjectPath(participant.getDossier()), participant.getCreation(), "New Participant");
94  set.add(ela);
95  }
96  }
97  if(path == null || "issue".equals(path.getRoot())) {
98 // for(Object obj : getIssues(from, null)) {
99 // Issue issue = (Issue) obj;
100 // DefaultEntityLastActivity ela = new DefaultEntityLastActivity(
101 // issue, DossierPU.getObjectPath(issue), issue.getModification(), "Modified");
102 // set.add(ela);
103 // }
104  for(Object obj : getIssueComments(from, null)) {
105  IssueComment comment = (IssueComment) obj;
107  comment, DossierPU.getObjectPath(comment.getIssue()), comment.getModification(), "Informed");
109  set.add(ela);
110  }
111  }
112  return set;
113  }
114 
115  @Override
116  public Object getMainEntity(Object entity) {
117  if(entity instanceof IssueComment) {
118  return ((IssueComment) entity).getIssue().getDossier();
119  } else if(entity instanceof Project) {
120  return ((Project) entity).getDossier();
121  } else if(entity instanceof Issue) {
122  return ((Issue) entity).getDossier();
123  }
124  return null;
125  }
126 
127  public List getDossiers(Date from, String select) {
128  WhereClause wc = new WhereClause();
129  wc.addClause("select dossier" + check(select) + " from Dossier as dossier");
130  wc.addClause("where dossier.creation >= :date");
131  wc.addNamedValue("date", from);
132  return getDao().getResultList(wc);
133  }
134 
135  public List getProjects(Date from, String select, String field) {
136  WhereClause wc = new WhereClause();
137  wc.addClause("select project" + check(select) + " from Project as project");
138  wc.addClause("where project." + field + " >= :date");
139  wc.addNamedValue("date", from);
140  if("changePhase".equals(field)) {
141  // Dismiss IDEA since they show as Created
142  wc.addClause("and dossier.project.phase != :phase");
143  wc.addNamedValue("phase", 0);
144  }
145  return getDao().getResultList(wc);
146  }
147 
148  public List getParticipants(Date from, String select) {
149  WhereClause wc = new WhereClause();
150  wc.addClause("select participant" + check(select) + " from Participant as participant");
151  wc.addClause("where participant.creation >= :date");
152  wc.addNamedValue("date", from);
153  return getDao().getResultList(wc);
154  }
155 
156  public List getIssues(Date from, String select) {
157  WhereClause wc = new WhereClause();
158  wc.addClause("select issue" + check(select) + " from Issue as issue");
159  wc.addClause("where issue.modification >= :date");
160  wc.addNamedValue("date", from);
161  return getDao().getResultList(wc);
162  }
163 
164  public List getIssueComments(Date from, String select) {
165  WhereClause wc = new WhereClause();
166  wc.addClause("select comment" + check(select) + " from IssueComment as comment");
167  wc.addClause("where comment.modification >= :date");
168  wc.addNamedValue("date", from);
169  return getDao().getResultList(wc);
170  }
171 
172  private String check(String select) {
173  return Strings.isBlank(select) ? "" : select;
174  }
175 
176  /* Dao */
177 
178  private Dao _dao;
179 
180  private Dao getDao() {
181  if(_dao == null) {
182  _dao = new DossierPU();
183  }
184  return _dao;
185  }
186 
187 }
List getDossiers(Date from, String select)
List getIssueComments(Date from, String select)
List getParticipants(Date from, String select)
List getIssues(Date from, String select)
List getProjects(Date from, String select, String field)
EntityActivitySet getActivities(Date from, String entityPath, String type)
static String getObjectPath(Object object)
Definition: DossierPU.java:66
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78