BrightSide Workbench Full Report + Source Code
ContactActivity.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.contacts.CommentIt;
22 import org.turro.contacts.Convocation;
23 import org.turro.contacts.StarIt;
24 import org.turro.contacts.VoteIt;
25 import org.turro.contacts.db.ContactsPU;
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 ContactActivity implements IElephantActivity {
37 
38  @Override
39  public void generate() {
40  Activities comacts = Activities.of("Commented");
41  SqlClause.select("comment").from("CommentIt comment")
42  .where().greater("comment.dateCreation", comacts.lastDate())
43  .dao(dao.get()).forEach(CommentIt.class, comment -> {
44  IElephantEntity icom = comment.getOwnerEntity();
45  if(!icom.isEmpty()) {
46  String path = ContactsPU.getObjectPath(comment);
47  comacts.add(comment.getDateCreation(), path, icom.getPath(), icom.getHierarchicalPath());
48  }
49  });
50  Activities staacts = Activities.of("Starred");
51  SqlClause.select("star").from("StarIt star")
52  .where().greater("star.dateCreation", staacts.lastDate())
53  .dao(dao.get()).forEach(StarIt.class, star -> {
54  IElephantEntity istar = star.getOwnerEntity();
55  if(!istar.isEmpty()) {
56  String path = ContactsPU.getObjectPath(star);
57  staacts.add(star.getDateCreation(), path, istar.getPath(), istar.getHierarchicalPath());
58  }
59  });
60  Activities votacts = Activities.of("Voted");
61  SqlClause.select("vote").from("VoteIt vote")
62  .where().greater("vote.dateCreation", votacts.lastDate())
63  .dao(dao.get()).forEach(VoteIt.class, vote -> {
64  IElephantEntity ivote = vote.getOwnerEntity();
65  if(!ivote.isEmpty()) {
66  String path = ContactsPU.getObjectPath(vote);
67  votacts.add(vote.getDateCreation(), path, ivote.getPath(), ivote.getHierarchicalPath());
68  }
69  });
70  Activities conacts = Activities.of("Convoked");
71  SqlClause.select("convo").from("Convocation convo")
72  .where().greater("convo.callDate", conacts.lastDate())
73  .dao(dao.get()).forEach(Convocation.class, convo -> {
74  IElephantEntity iconvo = convo.getEntity();
75  if(!iconvo.isEmpty()) {
76  String path = ContactsPU.getObjectPath(convo);
77  conacts.add(convo.getCallDate(), path, iconvo.getPath(), iconvo.getHierarchicalPath());
78  }
79  });
80  }
81 
82  /* Dao */
83 
84  private final Cached<Dao> dao = Cached.instance(() -> new ContactsPU());
85 
86 }
static Activities of(String reason)