BrightSide Workbench Full Report + Source Code
Students.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.entities;
20 
21 import java.util.List;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.jpa.Dao;
24 import org.turro.plugin.contacts.IContact;
25 import org.turro.students.db.StudentsPU;
26 import org.turro.students.entities.Challenge;
27 import org.turro.students.entities.Response;
28 
33 public class Students {
34 
35  public static long getChallengeCountFromEntity(Object entity) {
37  }
38 
39  public static long getChallengeCountFromEntity(String entityPath) {
40  WhereClause wc = new WhereClause();
41  wc.addClause("select count(distinct c) from Challenge c");
42  wc.addClause("where c.entityPath = :path");
43  wc.addNamedValue("path", entityPath);
44  return (long) new StudentsPU().getSingleResult(wc);
45  }
46 
47  public static List<Challenge> getChallengesFromEntity(Object entity) {
49  }
50 
51  public static List<Challenge> getChallengesFromEntity(String entityPath) {
52  WhereClause wc = new WhereClause();
53  wc.addClause("select c from Challenge c");
54  wc.addClause("where c.entityPath = :path");
55  wc.addNamedValue("path", entityPath);
56  return new StudentsPU().getResultList(wc);
57  }
58 
59  public static long getChallengeCountFrom(IContact contact) {
60  return getChallengeCountFrom(contact.getId());
61  }
62 
63  public static long getChallengeCountFrom(String idContact) {
64  WhereClause wc = new WhereClause();
65  wc.addClause("select count(distinct c) from Challenge c");
66  wc.addClause("where c.idChallenger = :idc");
67  wc.addNamedValue("idc", idContact);
68  return (long) new StudentsPU().getSingleResult(wc);
69  }
70 
71  public static List<Challenge> getChallengesFrom(IContact contact) {
72  return getChallengesFrom(contact.getId());
73  }
74 
75  public static List<Challenge> getChallengesFrom(String idContact) {
76  WhereClause wc = new WhereClause();
77  wc.addClause("select c from Challenge c");
78  wc.addClause("where c.idChallenger = :idc");
79  wc.addNamedValue("idc", idContact);
80  return new StudentsPU().getResultList(wc);
81  }
82 
83  public static long getResponseCountFromEntity(Object entity) {
85  }
86 
87  public static long getResponseCountFromEntity(String entityPath) {
88  WhereClause wc = new WhereClause();
89  wc.addClause("select count(distinct r) from Response r");
90  wc.addClause("where r.challenge.entityPath = :path");
91  wc.addNamedValue("path", entityPath);
92  return (long) new StudentsPU().getSingleResult(wc);
93  }
94 
95  public static List<Response> getResponsesFromEntity(Object entity) {
97  }
98 
99  public static List<Response> getResponsesFromEntity(String entityPath) {
100  WhereClause wc = new WhereClause();
101  wc.addClause("select r from Response r");
102  wc.addClause("where r.challenge.entityPath = :path");
103  wc.addNamedValue("path", entityPath);
104  return new StudentsPU().getResultList(wc);
105  }
106 
107  public static long getResponseCountFrom(IContact contact) {
108  return getResponseCountFrom(contact.getId());
109  }
110 
111  public static long getResponseCountFrom(String idContact) {
112  WhereClause wc = new WhereClause();
113  wc.addClause("select count(distinct r) from Response r");
114  wc.addClause("where :idc member of r.studentIds");
115  wc.addNamedValue("idc", idContact);
116  return (long) new StudentsPU().getSingleResult(wc);
117  }
118 
119  public static List<Response> getResponsesFrom(IContact contact) {
120  return getResponsesFrom(contact.getId());
121  }
122 
123  public static List<Response> getResponsesFrom(String idContact) {
124  WhereClause wc = new WhereClause();
125  wc.addClause("select r from Response r");
126  wc.addClause("where :idc member of r.studentIds");
127  wc.addNamedValue("idc", idContact);
128  return new StudentsPU().getResultList(wc);
129  }
130 
131  public static double getResponseCountFrom(Dao dao, Challenge challenge) {
132  WhereClause wc = new WhereClause();
133  wc.addClause("select count(distinct r) from Response r");
134  wc.addClause("where challenge.id = :idc");
135  wc.addNamedValue("idc", challenge.getId());
136  return (long) dao.getSingleResult(wc);
137  }
138 
139  public static List<Response> getResponsesFrom(Dao dao, Challenge challenge) {
140  WhereClause wc = new WhereClause();
141  wc.addClause("select r from Response r");
142  wc.addClause("where challenge.id = :idc");
143  wc.addNamedValue("idc", challenge.getId());
144  return dao.getResultList(wc);
145  }
146 
147  private Students() {}
148 
149 }
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static List< Response > getResponsesFrom(Dao dao, Challenge challenge)
Definition: Students.java:139
static List< Challenge > getChallengesFrom(String idContact)
Definition: Students.java:75
static long getResponseCountFromEntity(Object entity)
Definition: Students.java:83
static long getChallengeCountFrom(String idContact)
Definition: Students.java:63
static List< Response > getResponsesFromEntity(Object entity)
Definition: Students.java:95
static List< Challenge > getChallengesFrom(IContact contact)
Definition: Students.java:71
static long getResponseCountFromEntity(String entityPath)
Definition: Students.java:87
static long getResponseCountFrom(String idContact)
Definition: Students.java:111
static double getResponseCountFrom(Dao dao, Challenge challenge)
Definition: Students.java:131
static List< Response > getResponsesFrom(IContact contact)
Definition: Students.java:119
static List< Response > getResponsesFromEntity(String entityPath)
Definition: Students.java:99
static long getChallengeCountFromEntity(Object entity)
Definition: Students.java:35
static List< Challenge > getChallengesFromEntity(String entityPath)
Definition: Students.java:51
static long getChallengeCountFromEntity(String entityPath)
Definition: Students.java:39
static long getResponseCountFrom(IContact contact)
Definition: Students.java:107
static List< Challenge > getChallengesFromEntity(Object entity)
Definition: Students.java:47
static long getChallengeCountFrom(IContact contact)
Definition: Students.java:59
static List< Response > getResponsesFrom(String idContact)
Definition: Students.java:123
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380