BrightSide Workbench Full Report + Source Code
EntityInterestCollector.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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.assistant;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import org.turro.elephant.db.ElephantPU;
25 import org.turro.elephant.entities.db.EntityParticipation;
26 import org.turro.entities.Entities;
27 import org.turro.interest.Interest;
28 import org.turro.interest.InterestCollector;
29 import org.turro.jpa.Dao;
30 import org.turro.participation.ParticipationReason;
31 import org.turro.plugin.contacts.IContact;
32 import org.turro.sql.SqlClause;
33 import org.turro.util.Cached;
34 
39 public class EntityInterestCollector implements InterestCollector {
40 
41  @Override
42  public List<Interest> collect(IContact contact, ParticipationReason... reasons) {
43  ArrayList<Interest> list = new ArrayList<>();
44  SqlClause.select("ep").from("EntityParticipation ep")
45  .where().equal("participatorPath", Entities.getController(contact.getContact()).getPath())
46  .and().in("reason", Arrays.asList(reasons))
47  .dao(dao.get())
48  .resultList(EntityParticipation.class)
49  .forEach(ep -> {
50  if(!ep.getEntity().isEmpty()) {
51  list.add(new Interest(ep.getReason(), ep.getEntity(), false));
52  }
53  });
54  return list;
55  }
56 
57  @Override
58  public List<Interest> reversed(IContact contact, ParticipationReason... reasons) {
59  ArrayList<Interest> list = new ArrayList<>();
60  SqlClause.select("ep").from("EntityParticipation ep")
61  .where().equal("entityPath", Entities.getController(contact.getContact()).getPath())
62  .and().in("reason", Arrays.asList(reasons))
63  .dao(dao.get())
64  .resultList(EntityParticipation.class)
65  .forEach(ep -> {
66  if(!ep.getEntity().isEmpty()) {
67  list.add(new Interest(ep.getReason(), ep.getParticipator(), true));
68  }
69  });
70  return list;
71  }
72 
73  /* Dao */
74 
75  private final Cached<Dao> dao = Cached.instance(() -> new ElephantPU());
76 
77 }
List< Interest > collect(IContact contact, ParticipationReason... reasons)
List< Interest > reversed(IContact contact, ParticipationReason... reasons)
static IElephantEntity getController(String path)
Definition: Entities.java:78