View Javadoc
1   package org.kuali.kpme.edo.reports.dao;
2   
3   
4   import java.math.BigDecimal;
5   import java.util.ArrayList;
6   import java.util.Collection;
7   import java.util.Iterator;
8   import java.util.List;
9   import java.util.Map;
10  
11  import org.apache.ojb.broker.query.Criteria;
12  import org.apache.ojb.broker.query.QueryByCriteria;
13  import org.apache.ojb.broker.query.QueryFactory;
14  import org.apache.ojb.broker.query.ReportQueryByCriteria;
15  import org.kuali.kpme.edo.reports.EdoPromotionAndTenureReport;
16  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
17  import org.kuali.rice.krad.util.ObjectUtils;
18  
19  import static org.kuali.kpme.edo.util.EdoPropertyConstants.EdoPromotionAndTenureReportFields;
20  
21  public class EdoPromotionAndTenureReportViewDaoImpl extends PlatformAwareDaoBaseOjb implements EdoPromotionAndTenureReportViewDao {
22  	
23  	@Override
24  	public List<EdoPromotionAndTenureReport> getAllPromotionAndTenureReports() {
25  		
26          List<EdoPromotionAndTenureReport> reports = new ArrayList<EdoPromotionAndTenureReport>();
27  		
28  		Criteria criteria = new Criteria();		
29  
30  		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, criteria);
31  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.DOSSIER_ID);
32  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.ROUTE_LEVEL);
33  		
34          Collection results = getPersistenceBrokerTemplate().getCollectionByQuery(query);
35          
36          if (ObjectUtils.isNotNull(results) && !results.isEmpty()) {
37          	reports.addAll(results);
38          }
39          
40          return reports;
41  	}
42  
43  	@Override
44  	public List<EdoPromotionAndTenureReport> getPromotionAndTenureReportsByDossierType(String dossierTypeName) {
45  		
46          List<EdoPromotionAndTenureReport> reports = new ArrayList<EdoPromotionAndTenureReport>();
47  		
48  		Criteria criteria = new Criteria();
49  		criteria.addEqualTo(EdoPromotionAndTenureReportFields.DOSSIER_TYPE_NAME, dossierTypeName);
50  		
51  		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, criteria);
52  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.DOSSIER_ID);
53  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.ROUTE_LEVEL);
54  
55          Collection results = getPersistenceBrokerTemplate().getCollectionByQuery(query);
56          
57          if (ObjectUtils.isNotNull(results) && !results.isEmpty()) {
58          	reports.addAll(results);
59          }
60          
61          return reports;
62  	}	
63  	
64  	@Override
65  	public List<EdoPromotionAndTenureReport> getPromotionAndTenureReportsBySearchCriteria(Map<String, ? extends Object> searchCriteria) {
66  		
67          List<EdoPromotionAndTenureReport> reports = new ArrayList<EdoPromotionAndTenureReport>();
68  		
69  		Criteria criteria = new Criteria();
70  		for(String key : searchCriteria.keySet()) {
71  			criteria.addEqualTo(key, searchCriteria.get(key));			
72  		}
73  		
74  		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, criteria);
75  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.DOSSIER_ID);
76  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.ROUTE_LEVEL);
77  
78          Collection results = getPersistenceBrokerTemplate().getCollectionByQuery(query);
79          
80          if (ObjectUtils.isNotNull(results) && !results.isEmpty()) {
81          	reports.addAll(results);
82          }
83          
84          return reports;
85  	}
86  
87  	@Override
88  	public List<String> getDistinctDossierTypeList() {
89  		List<String> dossierTypes = new ArrayList<String>();
90  
91  		//Retrieve the distinct list of dossier types 		
92  		Criteria criteria = new Criteria();
93  		
94  		String[] attributes = new String[] {EdoPromotionAndTenureReportFields.DOSSIER_TYPE_NAME};				
95  		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, attributes, criteria, true);
96  		query.addOrderByAscending(EdoPromotionAndTenureReportFields.DOSSIER_TYPE_NAME);
97  		
98          Iterator results = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
99          while (results.hasNext()) {
100         	Object[] row = (Object[])results.next();
101         	dossierTypes.add((String)row[0]);
102         }
103         
104         return dossierTypes;
105 	}
106 
107 	@Override
108 	public List<String> getDistinctDepartmentList() {
109 		List<String> departments = new ArrayList<String>();
110 
111 		//Retrieve the distinct list of departments 		
112 		Criteria criteria = new Criteria();
113 		
114 		String[] attributes = new String[] {EdoPromotionAndTenureReportFields.DEPARTMENT_ID};				
115 		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, attributes, criteria, true);
116 		query.addOrderByAscending(EdoPromotionAndTenureReportFields.DEPARTMENT_ID);
117 		
118         Iterator results = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
119         while (results.hasNext()) {
120         	Object[] row = (Object[])results.next();
121         	departments.add((String)row[0]);
122         }
123         
124         return departments;
125 	}
126 
127 	@Override
128 	public List<String> getDistinctSchoolList() {
129 		List<String> schools = new ArrayList<String>();
130 
131 		//Retrieve the distinct list of schools 		
132 		Criteria criteria = new Criteria();
133 		
134 		String[] attributes = new String[] {EdoPromotionAndTenureReportFields.SCHOOL_ID};				
135 		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, attributes, criteria, true);
136 		query.addOrderByAscending(EdoPromotionAndTenureReportFields.SCHOOL_ID);
137 		
138         Iterator results = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
139         while (results.hasNext()) {
140         	Object[] row = (Object[])results.next();
141         	schools.add((String)row[0]);
142         }
143         
144         return schools;
145 	}
146 
147 	@Override
148 	public List<String> getDistinctWorkflowList() {
149 		List<String> workflows = new ArrayList<String>();
150 
151 		//Retrieve the distinct list of workflows 		
152 		Criteria criteria = new Criteria();
153 		
154 		String[] attributes = new String[] {EdoPromotionAndTenureReportFields.WORKFLOW_ID};				
155 		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, attributes, criteria, true);
156 		query.addOrderByAscending(EdoPromotionAndTenureReportFields.WORKFLOW_ID);
157 		
158         Iterator results = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
159         while (results.hasNext()) {
160         	Object[] row = (Object[])results.next();
161         	workflows.add((String)row[0]);
162         }
163         
164         return workflows;
165 	}
166 
167 	@Override
168 	public List<Integer> getDistinctVoteRoundList() {
169 		List<Integer> voteRounds = new ArrayList<Integer>();
170 
171 		//Retrieve the distinct list of vote rounds 		
172 		Criteria criteria = new Criteria();
173 		
174 		String[] attributes = new String[] {EdoPromotionAndTenureReportFields.VOTE_ROUND};				
175 		ReportQueryByCriteria query = QueryFactory.newReportQuery(EdoPromotionAndTenureReport.class, attributes, criteria, true);
176 		query.addOrderByAscending(EdoPromotionAndTenureReportFields.VOTE_ROUND);
177 		
178         Iterator results = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
179         while (results.hasNext()) {
180         	Object[] row = (Object[])results.next();
181         	//OJB thinks this is a BigDecimal instead of an Integer, but I don't know why
182         	BigDecimal voteRound = (BigDecimal)row[0];        	
183         	voteRounds.add(new Integer(voteRound.intValue()));
184         }
185         
186         return voteRounds;
187 	}	
188 	
189 }