View Javadoc
1   package org.kuali.kpme.edo.group.dao;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.LinkedList;
6   import java.util.List;
7   
8   import org.apache.log4j.Logger;
9   import org.apache.ojb.broker.query.Criteria;
10  import org.apache.ojb.broker.query.Query;
11  import org.apache.ojb.broker.query.QueryFactory;
12  import org.kuali.kpme.edo.group.EdoGroupTrackingBo;
13  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
14  
15  /**
16   * $HeadURL$
17   * $Revision$
18   * Created with IntelliJ IDEA.
19   * User: bradleyt
20   * Date: 1/14/14
21   * Time: 3:31 PM
22   */
23  public class EdoGroupTrackingDaoImpl  extends PlatformAwareDaoBaseOjb implements EdoGroupTrackingDao {
24  
25      private static final Logger LOG = Logger.getLogger(EdoGroupTrackingDaoImpl.class);
26  
27      public EdoGroupTrackingBo getEdoGroupTracking(String edoGroupTrackingId) {
28          Criteria cConditions = new Criteria();
29  
30          cConditions.addEqualTo("edoGroupTrackingId", edoGroupTrackingId);
31  
32          Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
33          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
34  
35          if (c != null && c.size() != 0) {
36              return (EdoGroupTrackingBo)c.toArray()[0];
37          }
38          return null;
39      }
40  
41      public EdoGroupTrackingBo getEdoGroupTrackingByGroupName(String groupName) {
42          Criteria cConditions = new Criteria();
43  
44          cConditions.addEqualTo("groupName", groupName);
45  
46          Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
47          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
48  
49          if (c != null && c.size() != 0) {
50              return (EdoGroupTrackingBo)c.toArray()[0];
51          }
52          return null;
53      }
54  
55      public List<EdoGroupTrackingBo> getEdoGroupTrackingByDepartmentId(String departmentId) {
56          List<EdoGroupTrackingBo> groupList = new ArrayList<EdoGroupTrackingBo>();
57  
58          Criteria cConditions = new Criteria();
59          cConditions.addEqualTo("departmentId", departmentId);
60  
61          Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
62          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
63  
64          if (c != null && c.size() != 0) {
65              groupList.addAll(c);
66          }
67          return groupList;
68  
69      }
70  
71      public List<EdoGroupTrackingBo> getEdoGroupTrackingBySchoolId(String schoolId) {
72          List<EdoGroupTrackingBo> groupList = new ArrayList<EdoGroupTrackingBo>();
73  
74          Criteria cConditions = new Criteria();
75          cConditions.addEqualTo("organizationCode", schoolId);
76  
77          Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
78          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
79  
80          if (c != null && c.size() != 0) {
81              groupList.addAll(c);
82          }
83          return groupList;
84      }
85  
86      public List<EdoGroupTrackingBo> getEdoGroupTrackingByCampusId(String campusId) {
87          List<EdoGroupTrackingBo> groupList = new ArrayList<EdoGroupTrackingBo>();
88  
89          Criteria cConditions = new Criteria();
90          cConditions.addEqualTo("campus_id", campusId);
91  
92          Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
93          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
94  
95          if (c != null && c.size() != 0) {
96              groupList.addAll(c);
97          }
98          return groupList;
99      }
100 
101     public void saveOrUpdate(EdoGroupTrackingBo groupTracking) {
102         this.getPersistenceBrokerTemplate().store(groupTracking);
103     }
104 
105     public List<EdoGroupTrackingBo> findEdoGroupTrackingEntries(String departmentId, String schoolId, String campusId) {
106         List<EdoGroupTrackingBo> groupTrackingList = new ArrayList<EdoGroupTrackingBo>();
107 
108         //String sqlCondition = "(department_id like '%" + departmentId + "%' or department_id is null)";
109         //sqlCondition = sqlCondition.concat(" AND (school_id like '%" + schoolId + "%' or school_id is null)");
110         //sqlCondition = sqlCondition.concat(" AND (campus_id like '%" + campusId + "%' or campus_id is null)");
111 
112         Criteria cConditions = new Criteria();
113 
114         Criteria critDept1 = new Criteria();
115         critDept1.addLike("department_id", departmentId.toUpperCase());
116         if (departmentId.equals("*") || departmentId.equals("%")) {
117             Criteria critDept2 = new Criteria();
118             critDept2.addIsNull("department_id");
119             critDept1.addOrCriteria(critDept2);
120         }
121 
122         Criteria critSchool1 = new Criteria();
123         critSchool1.addLike("organizationCode", schoolId.toUpperCase());
124         if (schoolId.equals("*") || schoolId.equals("%")) {
125             Criteria critSchool2 = new Criteria();
126             critSchool2.addIsNull("organizationCode");
127             critSchool1.addOrCriteria(critSchool2);
128         }
129 
130         Criteria critCampus1 = new Criteria();
131         critCampus1.addLike("campus_id", campusId.toUpperCase());
132         if (campusId.equals("*") || campusId.equals("%")) {
133             Criteria critCampus2 = new Criteria();
134             critCampus2.addIsNull("campus_id");
135             critCampus1.addOrCriteria(critCampus2);
136         }
137 
138         cConditions.addAndCriteria(critDept1);
139         cConditions.addAndCriteria(critSchool1);
140         cConditions.addAndCriteria(critCampus1);
141         //cConditions.addSql(sqlCondition);
142 
143         LOG.info("Query conditions: " + cConditions.toString());
144 
145         Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, cConditions);
146         Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
147 
148         if (c != null && c.size() != 0) {
149             groupTrackingList.addAll(c);
150         }
151         return groupTrackingList;
152     }
153 
154     public List<EdoGroupTrackingBo> getGroupTrackingEntries() {
155 
156         List<EdoGroupTrackingBo> results = new LinkedList<EdoGroupTrackingBo>();
157         Criteria criteria = new Criteria();
158 
159         Query query = QueryFactory.newQuery(EdoGroupTrackingBo.class, criteria, true);
160 
161         Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
162 
163         if (c != null && c.size() != 0 )  {
164             results.addAll(c);
165         }
166 
167         return results;
168     }
169 }