1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.stats.dao.impl; |
17 | |
|
18 | |
import java.sql.SQLException; |
19 | |
import java.sql.Timestamp; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Calendar; |
22 | |
import java.util.Date; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import javax.persistence.EntityManager; |
26 | |
import javax.persistence.PersistenceContext; |
27 | |
import javax.persistence.Query; |
28 | |
|
29 | |
import org.apache.ojb.broker.accesslayer.LookupException; |
30 | |
import org.kuali.rice.core.util.KeyValue; |
31 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
32 | |
import org.kuali.rice.kew.stats.Stats; |
33 | |
import org.kuali.rice.kew.stats.dao.StatsDAO; |
34 | |
import org.kuali.rice.kew.util.KEWConstants; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class StatsDaoJpaImpl implements StatsDAO { |
52 | |
|
53 | |
@PersistenceContext |
54 | |
private EntityManager entityManager; |
55 | |
|
56 | |
@Override |
57 | |
public void DocumentsRoutedReport(Stats stats, Date begDate, Date endDate) throws SQLException, LookupException { |
58 | 0 | Query query = entityManager.createQuery("select count(*) as count, drhv.docRouteStatus from DocumentRouteHeaderValue drhv where drhv.createDate between :beginDate and :endDate group by docRouteStatus"); |
59 | |
|
60 | 0 | query.setParameter("beginDate", new Timestamp(begDate.getTime())); |
61 | 0 | query.setParameter("endDate", new Timestamp(endDate.getTime())); |
62 | |
|
63 | |
@SuppressWarnings("unchecked") |
64 | 0 | List<Object[]> resultList = query.getResultList(); |
65 | |
|
66 | 0 | for (Object[] result : resultList) { |
67 | 0 | String actionType = result[1].toString(); |
68 | 0 | String number = result[0].toString(); |
69 | 0 | if (actionType.equals(KEWConstants.ROUTE_HEADER_APPROVED_CD)) { |
70 | 0 | stats.setApprovedNumber(number); |
71 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_CANCEL_CD)) { |
72 | 0 | stats.setCanceledNumber(number); |
73 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_DISAPPROVED_CD)) { |
74 | 0 | stats.setDisapprovedNumber(number); |
75 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_ENROUTE_CD)) { |
76 | 0 | stats.setEnrouteNumber(number); |
77 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_EXCEPTION_CD)) { |
78 | 0 | stats.setExceptionNumber(number); |
79 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_FINAL_CD)) { |
80 | 0 | stats.setFinalNumber(number); |
81 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_INITIATED_CD)) { |
82 | 0 | stats.setInitiatedNumber(number); |
83 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_PROCESSED_CD)) { |
84 | 0 | stats.setProcessedNumber(number); |
85 | 0 | } else if (actionType.equals(KEWConstants.ROUTE_HEADER_SAVED_CD)) { |
86 | 0 | stats.setSavedNumber(number); |
87 | |
} |
88 | 0 | } |
89 | 0 | } |
90 | |
|
91 | |
@Override |
92 | |
public void NumActiveItemsReport(Stats stats) throws SQLException, LookupException { |
93 | 0 | stats.setNumActionItems(entityManager.createQuery("select count(*) from ActionItem ai").getSingleResult().toString()); |
94 | |
|
95 | 0 | } |
96 | |
|
97 | |
@Override |
98 | |
public void NumInitiatedDocsByDocTypeReport(Stats stats) throws SQLException, LookupException { |
99 | 0 | Query query = entityManager.createQuery("select count(*), dt.name from DocumentRouteHeaderValue drhv, DocumentType dt where drhv.createDate > :createDate and drhv.documentTypeId = dt.documentTypeId group by dt.name"); |
100 | |
|
101 | 0 | Calendar calendar = Calendar.getInstance(); |
102 | 0 | calendar.add(Calendar.DAY_OF_YEAR, -29); |
103 | 0 | calendar.set(Calendar.HOUR_OF_DAY, 0); |
104 | 0 | calendar.set(Calendar.MINUTE, 0); |
105 | 0 | calendar.set(Calendar.SECOND, 0); |
106 | 0 | calendar.set(Calendar.MILLISECOND, 0); |
107 | 0 | query.setParameter("createDate", new Timestamp(calendar.getTime().getTime())); |
108 | |
|
109 | |
@SuppressWarnings("unchecked") |
110 | 0 | List<Object[]> resultList = query.getResultList(); |
111 | |
|
112 | 0 | List<KeyValue> numDocs = new ArrayList<KeyValue>(resultList.size()); |
113 | 0 | for (Object[] result : resultList) { |
114 | 0 | numDocs.add(new ConcreteKeyValue(result[1].toString(),result[0].toString())); |
115 | |
} |
116 | |
|
117 | 0 | stats.setNumInitiatedDocsByDocType(numDocs); |
118 | 0 | } |
119 | |
|
120 | |
@Override |
121 | |
public void NumUsersReport(Stats stats) throws SQLException, LookupException { |
122 | 0 | stats.setNumUsers(entityManager.createQuery("select count(distinct uo.workflowId) from UserOptions uo").getSingleResult().toString()); |
123 | |
|
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public void NumberOfDocTypesReport(Stats stats) throws SQLException, LookupException { |
128 | 0 | stats.setNumDocTypes(entityManager.createQuery("select count(*) from DocumentType dt where dt.currentInd = true").getSingleResult().toString()); |
129 | |
|
130 | 0 | } |
131 | |
|
132 | |
public EntityManager getEntityManager() { |
133 | 0 | return this.entityManager; |
134 | |
} |
135 | |
|
136 | |
public void setEntityManager(EntityManager entityManager) { |
137 | 0 | this.entityManager = entityManager; |
138 | 0 | } |
139 | |
|
140 | |
} |