BrightSide Workbench Full Report + Source Code
DossierInterestCollector.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.interest;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.CategoryParticipant;
27 import org.turro.dossier.entity.Participant;
28 import org.turro.dossier.entity.ParticipantRole;
29 import org.turro.entities.Entities;
30 import org.turro.jpa.Dao;
31 import org.turro.participation.ParticipationReason;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.sql.SqlClause;
34 import org.turro.util.Cached;
35 
41 
42  @Override
43  public List<Interest> collect(IContact contact, ParticipationReason... reasons) {
44  ArrayList<Interest> list = new ArrayList<>();
45  if(Arrays.binarySearch(reasons, ParticipationReason.REASON_PARTICIPATE) > -1) {
46  SqlClause.select("ep").from("Participant ep")
47  .where().equal("idContact", contact.getId())
48  .and().notEqual("role", ParticipantRole.PARTICIPANT_SUBJECT)
49  .dao(dao.get())
50  .resultList(Participant.class)
51  .forEach(ep -> {
52  if(ep.getDossier() != null) {
53  list.add(new Interest(ParticipationReason.REASON_PARTICIPATE,
54  Entities.getController(ep.getDossier()), false));
55  }
56  });
57  SqlClause.select("ep").from("CategoryParticipant ep")
58  .where().equal("idContact", contact.getId())
59  .and().notEqual("role", ParticipantRole.PARTICIPANT_SUBJECT)
60  .dao(dao.get())
61  .resultList(CategoryParticipant.class)
62  .forEach(ep -> {
63  if(ep.getCategory() != null) {
64  list.add(new Interest(ParticipationReason.REASON_PARTICIPATE,
65  Entities.getController(ep.getCategory()), false));
66  }
67  });
68  }
69  return list;
70  }
71 
72  @Override
73  public List<Interest> reversed(IContact contact, ParticipationReason... reasons) {
74  return Collections.EMPTY_LIST;
75  }
76 
77  /* Dao */
78 
79  private final Cached<Dao> dao = Cached.instance(() -> new DossierPU());
80 
81 }
List< Interest > collect(IContact contact, ParticipationReason... reasons)
List< Interest > reversed(IContact contact, ParticipationReason... reasons)