BrightSide Workbench Full Report + Source Code
DossierActivitySet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.dossier;
19 
20 import java.util.Date;
21 import java.util.TreeSet;
22 import java.util.stream.Stream;
23 import org.turro.attach.db.AttachPU;
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.issue.IssueDetailComparator;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.jpa.Dao;
30 
35 public class DossierActivitySet extends TreeSet {
36 
37  public DossierActivitySet(Dossier dossier) {
38  this(dossier, null);
39  }
40 
41  public DossierActivitySet(Dossier dossier, Date date) {
42  super(new IssueDetailComparator());
43  addDetail(dossier, date);
44  }
45 
46  private void addDetail(Dossier dossier, Date date) {
47  Dao dao = new DossierPU();
48  Dao adao = new AttachPU();
49  WhereClause wc = new WhereClause();
50  wc.addClause("select comment from IssueComment as comment");
51  wc.addClause("where comment.issue.dossier = :dossier");
52  wc.addNamedValue("dossier", dossier);
53  if(date != null) {
54  wc.addClause("and comment.modification >= :date");
55  wc.addNamedValue("date", date);
56  }
57  addAll(dao.getResultList(wc));
58  wc = new WhereClause();
59  wc.addClause("select issue from Issue as issue");
60  wc.addClause("where issue.dossier = :dossier");
61  wc.addNamedValue("dossier", dossier);
62  try(Stream<Issue> issues = dao.stream(Issue.class, wc)) {
63  issues.forEach((issue) -> {
64  WhereClause awc = new WhereClause();
65  awc.addClause("select attachment from Attachment as attachment");
66  awc.addClause("where path like :path");
67  awc.addNamedValue("path", DossierPU.getObjectPath(issue) + "/%");
68  if(date != null) {
69  awc.addClause("and attachment.modification >= :date");
70  awc.addNamedValue("date", date);
71  }
72  addAll(adao.getResultList(awc));
73  });
74  }
75  wc = new WhereClause();
76  wc.addClause("select attachment from Attachment as attachment");
77  wc.addClause("where path like :path");
78  wc.addNamedValue("path", DossierPU.getObjectPath(dossier) + "/%");
79  if(date != null) {
80  wc.addClause("and attachment.modification >= :date");
81  wc.addNamedValue("date", date);
82  }
83  addAll(adao.getResultList(wc));
84  }
85 
86 }
void addNamedValue(String name, Object value)