19 package org.turro.students.www;
21 import java.util.List;
22 import javax.servlet.ServletContext;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.turro.action.Actions;
26 import org.turro.action.Contacts;
27 import org.turro.action.IEntityCtrl;
28 import org.turro.annotation.ElephantPlugin;
29 import org.turro.assistant.ParticipationInfo;
30 import org.turro.auth.Authentication;
31 import org.turro.collections.KeyValueMap;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.context.IConstructor;
34 import org.turro.elephant.db.WhereClause;
35 import org.turro.elephant.direct.DirectContent;
36 import org.turro.elephant.direct.DirectContents;
37 import org.turro.elephant.direct.IDirectContent;
38 import org.turro.entities.Entities;
39 import org.turro.entities.EntityRole;
40 import org.turro.entities.IElephantEntity;
41 import org.turro.jpa.Dao;
42 import org.turro.marker.ElephantMarker;
43 import org.turro.participation.IEntityParticipation;
44 import org.turro.participation.ParticipationReason;
45 import org.turro.plugin.contacts.ContactList;
46 import org.turro.plugin.contacts.IContact;
47 import org.turro.students.db.StudentsPU;
48 import org.turro.students.entities.Challenge;
54 @ElephantPlugin(label=
"students-ctrl")
55 @DirectContent(identifier=
"students-action")
58 private String entityPath,
template =
"related";
61 private List<IContact> students;
62 private List<Challenge> challenges;
66 this.constructor = constructor;
71 this.entityPath = entityPath;
76 this.
template =
template;
83 getRelatedChallenges();
85 (challenger !=
null && challenger.
isWebUser()) ||
86 !students.isEmpty() || !challenges.isEmpty();
91 getMarker().process(
"students",
template);
96 return getMarker().parse(
"students",
template);
115 marker.
put(
"actions",
this);
116 marker.
put(
"entityPath", entityPath);
117 marker.
put(
"challenger", getChallenger());
118 marker.
put(
"students", getStudents());
119 marker.
put(
"challenges", getRelatedChallenges());
123 private List<IContact> getStudents() {
124 if(students ==
null) {
125 ContactList list =
new ContactList();
126 for(IEntityParticipation participation :
new ParticipationInfo(entityPath, ParticipationReason.REASON_FOLLOW).getParticipations()) {
127 list.add(participation.getContact());
129 students = list.getStudents();
134 private List<Challenge> getRelatedChallenges() {
135 if(challenges ==
null) {
136 WhereClause wc =
new WhereClause();
137 wc.addClause(
"select c from Challenge c");
138 wc.addClause(
"where c.entityPath = :entityPath");
139 wc.addNamedValue(
"entityPath", entityPath);
140 challenges = getDao().getResultList(wc);
145 private IContact getChallenger() {
146 if(challenger ==
null) {
147 IElephantEntity iee = Entities.getController(entityPath);
148 IContact contact = Authentication.getIContact();
149 if(contact.isHHRR() || iee.hasRelatedRole(EntityRole.CHALLENGER, contact)) {
150 challenger = contact;
176 return getIdentifier().equals(
id);
180 public boolean myTurn(HttpServletRequest request) {
185 public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
189 String type = map.get(
"type");
201 wc.
addClause(
"select count(sp) from Response sp");
202 wc.
addClause(
"where :student member of sp.studentIds");
204 return (
long) getDao().getSingleResultOrNull(wc);
211 private Dao getDao() {
static String createRightNowParameter(String values)
static KeyValueMap getRightNowAction(IConstructor constructor)
static String createRightNowAction(String values)
static long getParticipationCount(String root, IContact contact, ParticipationReason reason)
static IContact getIContact()
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static String getRootWebPath()
void addClause(String clause)
void addNamedValue(String name, Object value)
static boolean isYourTurn(HttpServletRequest request, String path)
static final String DIRECT_CONTENT_PATH
static IElephantEntity getController(String path)
Object put(Object key, Object value)
long countParticipations(String root, IContact contact, String reason)
boolean isMine(Challenge challenge)
String parse(IConstructor constructor)
static String createPOST(String values)
void setConstructor(IConstructor constructor)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
void setEntityPath(String entityPath)
void render(IConstructor constructor)
void setTemplate(String template)
static String createURL(String values)
boolean myTurn(HttpServletRequest request)
long countResponses(IContact contact)
static String getIdentifier()
Object getParticipationControl(IConstructor constructor, ParticipationReason reason)