01: package com.technoetic.xplanner.tags;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05: import java.util.Iterator;
06:
07: import net.sf.hibernate.HibernateException;
08: import net.sf.hibernate.Query;
09: import org.apache.commons.lang.StringUtils;
10:
11: import com.technoetic.xplanner.domain.Person;
12: import com.technoetic.xplanner.security.AuthenticationException;
13:
14: public class PersonOptionsTag extends OptionsTag {
15: private String filtered;
16: private int projectId;
17: public static final String ALL_ACTIVE_PEOPLE_QUERY = "from p in "
18: + Person.class + " order by p.name where p.hidden = false";
19:
20: public void release() {
21: super .release();
22: filtered = null;
23: projectId = 0;
24: }
25:
26: protected List getOptions() throws HibernateException,
27: AuthenticationException {
28: List allPeople = fetchAllPersons();
29: List selectedPeople;
30: int projectId = findProjectId();
31: if (projectId != 0 && isFilteringRequested()) {
32: selectedPeople = new ArrayList();
33: selectedPeople.addAll(getAuthorizer()
34: .getPeopleWithPermissionOnProject(allPeople,
35: projectId));
36: } else {
37: selectedPeople = allPeople;
38: }
39: return selectedPeople;
40: }
41:
42: private List fetchAllPersons() throws HibernateException {
43: Query query = getSession().createQuery(ALL_ACTIVE_PEOPLE_QUERY);
44: //query.setCacheable(true);
45: return query.list();
46: }
47:
48: private boolean isFilteringRequested() {
49: return filtered == null
50: || Boolean.valueOf(filtered).booleanValue();
51: }
52:
53: public String getFiltered() {
54: return filtered;
55: }
56:
57: public void setFiltered(String filtered) {
58: this .filtered = filtered;
59: }
60:
61: public void setProjectId(int projectId) {
62: this .projectId = projectId;
63: }
64:
65: public int getProjectId() {
66: return projectId;
67: }
68:
69: public int findProjectId() {
70: int projectId = this .projectId;
71: if (projectId == 0) {
72: DomainContext context = DomainContext.get(pageContext
73: .getRequest());
74: if (context != null) {
75: projectId = context.getProjectId();
76: }
77: }
78: String id = pageContext.getRequest().getParameter("projectId");
79: if (projectId == 0 && !StringUtils.isEmpty(id)) {
80: projectId = Integer.parseInt(id);
81: }
82: return projectId;
83: }
84:
85: }
|