BrightSide Workbench Full Report + Source Code
CommonsLastActivity.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.function.Consumer;
23 import org.turro.assistant.ParticipationInfo;
24 import org.turro.elephant.db.ElephantPU;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.elephant.entities.db.Poll;
27 import org.turro.entities.Entities;
28 import org.turro.jpa.Dao;
29 import org.turro.sql.SqlClause;
30 
35 @LastActivity
36 public class CommonsLastActivity implements ILastActivity {
37 
38  @Override
39  public EntityActivitySet getActivities(Date from, String entityPath, String type) {
41  SqlClause.select("poll").from("Poll poll")
42  .where().greater("poll.deadline", from)
43  .and().equal("poll.entityPath", entityPath)
44  .dao(getDao()).forEach(Poll.class, poll -> {
45  DefaultEntityLastActivity ela = new DefaultEntityLastActivity(
46  poll, poll.getEntityPath(), poll.getDeadline(), "Related polls");
47  ela.setSortPath(Entities.getController(poll).getHierarchicalPath());
48  set.add(ela);
49  });
50  ParticipationInfo pi = new ParticipationInfo(entityPath, null);
51  pi.getAnyParticipations(from, participation -> {
53  participation, participation.getEntityPath(), participation.getParticipationDate(), participation.getReason().toString());
55  set.add(ela);
56  });
57  return set;
58  }
59 
60  @Override
61  public Object getMainEntity(Object entity) {
62  return null;
63  }
64 
65  public void getPolls(String path, Date from, Consumer<Poll> action) {
66  WhereClause wc = new WhereClause();
67  wc.addClause("select poll from Poll as poll");
68  wc.addClause("where poll.deadline >= :date");
69  wc.addNamedValue("date", from);
70  wc.addClause("and poll.entityPath = :path");
71  wc.addNamedValue("path", path);
72  getDao().forEach(Poll.class, wc, action);
73  }
74 
75  /* Dao */
76 
77  private Dao _dao;
78 
79  private Dao getDao() {
80  if(_dao == null) {
81  _dao = new ElephantPU();
82  }
83  return _dao;
84  }
85 
86 }
EntityActivitySet getActivities(Date from, String entityPath, String type)
void getPolls(String path, Date from, Consumer< Poll > action)
List< IEntityParticipation > getAnyParticipations(Date from)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78