Coverage Report - org.kuali.rice.kew.stats.dao.impl.StatsDaoJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StatsDaoJpaImpl
0%
0/51
0%
0/22
2.571
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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.kew.stats.Stats;
 31  
 import org.kuali.rice.kew.stats.dao.StatsDAO;
 32  
 import org.kuali.rice.kew.util.KEWConstants;
 33  
 import org.kuali.rice.kew.web.KeyValue;
 34  
 
 35  
 /**
 36  
  * This is a description of what this class does - ddean don't forget to fill this in. 
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  *
 40  
  */
 41  
 // There isn't an obvious place to put these @NamedQueries since they are just doing select count(*) from various tables.
 42  
 // Thus I'm using the query literals in this class, move these NamedQuerys to wherever they need to go.
 43  
 // @NamedQueries({
 44  
 //    @NamedQuery(name="Stats.DocumentsRoutedReport",  query="select count(*) as count, drhv.docRouteStatus from DocumentRouteHeaderValue drhv where drhv.createDate between :beginDate and :endDate group by docRouteStatus"),
 45  
 //    @NamedQuery(name="Stats.NumActiveItemsReport",  query="select count(*) from ActionItem ai"),
 46  
 //    @NamedQuery(name="Stats.NumInitiatedDocsByDocTypeReport",  query="select count(*), dt.name from DocumentRouteHeaderValue drhv, DocumentType dt where drhv.createDate > :createDate and drhv.documentTypeId = dt.documentTypeId group by dt.name"),
 47  
 //    @NamedQuery(name="Stats.NumUsersReport",  query="select count(distinct workflowId) from UserOptions uo"),
 48  
 //    @NamedQuery(name="Stats.NumberOfDocTypesReport",  query="select count(*) from DocumentType dt where dt.currentInd = true")
 49  
 //  })
 50  0
 public class StatsDaoJpaImpl implements StatsDAO {
 51  
 
 52  
     @PersistenceContext
 53  
     private EntityManager entityManager;
 54  
     
 55  
     public void DocumentsRoutedReport(Stats stats, Date begDate, Date endDate) throws SQLException, LookupException {
 56  0
         Query query = entityManager.createQuery("select count(*) as count, drhv.docRouteStatus from DocumentRouteHeaderValue drhv where drhv.createDate between :beginDate and :endDate group by docRouteStatus");
 57  
 //        Query query = entityManager.createNamedQuery("Stats.DocumentsRoutedReport");
 58  0
         query.setParameter("beginDate", begDate.getTime());
 59  0
         query.setParameter("endDate", endDate.getTime());
 60  
         
 61  
         @SuppressWarnings("unchecked")
 62  0
         List<Object[]> resultList = query.getResultList();
 63  
         
 64  0
         for (Object[] result : resultList) {
 65  0
             String actionType = result[1].toString();
 66  0
             String number = result[0].toString();
 67  0
             if (actionType.equals(KEWConstants.ROUTE_HEADER_APPROVED_CD)) {
 68  0
                 stats.setApprovedNumber(number);
 69  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_CANCEL_CD)) {
 70  0
                 stats.setCanceledNumber(number);
 71  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_DISAPPROVED_CD)) {
 72  0
                 stats.setDisapprovedNumber(number);
 73  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_ENROUTE_CD)) {
 74  0
                 stats.setEnrouteNumber(number);
 75  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_EXCEPTION_CD)) {
 76  0
                 stats.setExceptionNumber(number);
 77  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_FINAL_CD)) {
 78  0
                 stats.setFinalNumber(number);
 79  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_INITIATED_CD)) {
 80  0
                 stats.setInitiatedNumber(number);
 81  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_PROCESSED_CD)) {
 82  0
                 stats.setProcessedNumber(number);
 83  0
             } else if (actionType.equals(KEWConstants.ROUTE_HEADER_SAVED_CD)) {
 84  0
                 stats.setSavedNumber(number);
 85  
             }
 86  0
         }
 87  0
     }
 88  
 
 89  
     public void NumActiveItemsReport(Stats stats) throws SQLException, LookupException {
 90  0
         stats.setNumActionItems(entityManager.createNamedQuery("select count(*) from ActionItem ai").getSingleResult().toString());
 91  
 //        stats.setNumActionItems(entityManager.createNamedQuery("Stats.NumActiveItemsReport").getSingleResult().toString());
 92  0
     }
 93  
 
 94  
     public void NumInitiatedDocsByDocTypeReport(Stats stats) throws SQLException, LookupException {
 95  0
         Query query = entityManager.createNamedQuery("select count(*), dt.name from DocumentRouteHeaderValue drhv, DocumentType dt where drhv.createDate > :createDate and drhv.documentTypeId = dt.documentTypeId group by dt.name");
 96  
 //        Query query = entityManager.createNamedQuery("Stats.NumInitiatedDocsByDocTypeReport");
 97  0
         Calendar calendar = Calendar.getInstance();
 98  0
         calendar.add(Calendar.DAY_OF_YEAR, -29);
 99  0
         calendar.set(Calendar.HOUR_OF_DAY, 0);
 100  0
         calendar.set(Calendar.MINUTE, 0);
 101  0
         calendar.set(Calendar.SECOND, 0);
 102  0
         calendar.set(Calendar.MILLISECOND, 0);        
 103  0
         query.setParameter("createDate", new Timestamp(calendar.getTime().getTime()));
 104  
         
 105  
         @SuppressWarnings("unchecked")
 106  0
         List<Object[]> resultList = query.getResultList();
 107  
         
 108  0
         List<KeyValue> numDocs = new ArrayList<KeyValue>(resultList.size());
 109  0
         for (Object[] result : resultList) {
 110  0
             numDocs.add(new KeyValue(result[1].toString(),result[0].toString()));
 111  
         }
 112  
         
 113  0
         stats.setNumInitiatedDocsByDocType(numDocs);
 114  0
     }
 115  
 
 116  
     public void NumUsersReport(Stats stats) throws SQLException, LookupException {
 117  0
         stats.setNumUsers(entityManager.createNamedQuery("select count(distinct workflowId) from UserOptions uo").getSingleResult().toString());
 118  
 //        stats.setNumUsers(entityManager.createNamedQuery("Stats.NumUsersReport").getSingleResult().toString());
 119  0
     }
 120  
 
 121  
     public void NumberOfDocTypesReport(Stats stats) throws SQLException, LookupException {
 122  0
         stats.setNumDocTypes(entityManager.createNamedQuery("select count(*) from DocumentType dt where dt.currentInd = true").getSingleResult().toString());
 123  
 //        stats.setNumDocTypes(entityManager.createNamedQuery("Stats.NumberOfDocTypesReport").getSingleResult().toString());
 124  0
     }
 125  
 
 126  
     public EntityManager getEntityManager() {
 127  0
         return this.entityManager;
 128  
     }
 129  
 
 130  
     public void setEntityManager(EntityManager entityManager) {
 131  0
         this.entityManager = entityManager;
 132  0
     }
 133  
 
 134  
 }