BrightSide Workbench Full Report + Source Code
EntityParticipationUtils.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.Date;
22 import org.turro.elephant.db.ElephantPU;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.elephant.entities.db.EntityParticipation;
25 import org.turro.jpa.Dao;
26 import org.turro.participation.ParticipationReason;
27 
32 @Deprecated
34 
35  public static EntityParticipation addParticipation(String participatorPath, String entityPath, ParticipationReason reason) {
36  return addParticipation(new ElephantPU(), participatorPath, entityPath, reason);
37  }
38 
39  public static EntityParticipation addParticipation(Dao dao, String participatorPath, String entityPath, ParticipationReason reason) {
40  EntityParticipation ea = getParticipation(dao, participatorPath, entityPath, reason);
41  if(ea == null) {
42  ea = new EntityParticipation();
43  ea.setParticipatorPath(participatorPath);
44  ea.setEntityPath(entityPath);
45  ea.setReason(reason);
46  ea.setParticipationDate(new Date());
47  return dao.saveObject(ea);
48  } else {
49  return ea;
50  }
51  }
52 
53  public static EntityParticipation getParticipation(String participatorPath, String entityPath, ParticipationReason reason) {
54  return getParticipation(new ElephantPU(), participatorPath, entityPath, reason);
55  }
56 
57  public static EntityParticipation getParticipation(Dao dao, String participatorPath, String entityPath, ParticipationReason reason) {
58  WhereClause wc = new WhereClause();
59  wc.addClause("select ep from EntityParticipation ep");
60  wc.addClause("where ep.participatorPath = :participatorPath");
61  wc.addNamedValue("participatorPath", participatorPath);
62  wc.addClause("and ep.entityPath = :entityPath");
63  wc.addNamedValue("entityPath", entityPath);
64  wc.addClause("and ep.reason = :reason");
65  wc.addNamedValue("reason", reason);
67  }
68 
69  private EntityParticipationUtils() {
70  }
71 
72 }
static EntityParticipation getParticipation(String participatorPath, String entityPath, ParticipationReason reason)
static EntityParticipation getParticipation(Dao dao, String participatorPath, String entityPath, ParticipationReason reason)
static EntityParticipation addParticipation(String participatorPath, String entityPath, ParticipationReason reason)
static EntityParticipation addParticipation(Dao dao, String participatorPath, String entityPath, ParticipationReason reason)
void addNamedValue(String name, Object value)
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419