Coverage Report - org.kuali.rice.kew.actionrequest.dao.impl.ActionRequestDAOOjbImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionRequestDAOOjbImpl
0%
0/159
0%
0/24
1.565
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actionrequest.dao.impl;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.ojb.broker.query.Criteria;
 21  
 import org.apache.ojb.broker.query.QueryByCriteria;
 22  
 import org.apache.ojb.broker.query.QueryFactory;
 23  
 import org.apache.ojb.broker.query.ReportQueryByCriteria;
 24  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 25  
 import org.kuali.rice.kew.actionrequest.dao.ActionRequestDAO;
 26  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 27  
 import org.kuali.rice.kew.util.KEWConstants;
 28  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 29  
 
 30  
 import java.sql.Timestamp;
 31  
 import java.util.*;
 32  
 
 33  
 
 34  
 /**
 35  
  * OJB implementation of the {@link ActionRequestDAO}.
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class ActionRequestDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionRequestDAO {
 40  
 
 41  
     public ActionRequestValue getActionRequestByActionRequestId(Long actionRequestId) {
 42  0
         Criteria crit = new Criteria();
 43  0
         crit.addEqualTo("actionRequestId", actionRequestId);
 44  0
         return (ActionRequestValue) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 45  
     }
 46  
 
 47  
     public void saveActionRequest(ActionRequestValue actionRequest) {
 48  0
         if (actionRequest.getActionRequestId() == null) {
 49  0
             loadDefaultValues(actionRequest);
 50  
         }
 51  0
         if ( actionRequest.getAnnotation() != null && actionRequest.getAnnotation().length() > 2000 ) {
 52  0
                 actionRequest.setAnnotation( StringUtils.abbreviate(actionRequest.getAnnotation(), 2000) );
 53  
         }
 54  0
         this.getPersistenceBrokerTemplate().store(actionRequest);
 55  0
     }
 56  
 
 57  
     public List findPendingByResponsibilityIds(Collection responsibilityIds) {
 58  0
         if (responsibilityIds == null || responsibilityIds.size() == 0) return Collections.emptyList();
 59  0
         Criteria crit = new Criteria();
 60  0
         Criteria statusCriteria = new Criteria();
 61  0
         Criteria activatedCriteria = new Criteria();
 62  0
         activatedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
 63  
 
 64  0
         Criteria initializedCriteria = new Criteria();
 65  0
         initializedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
 66  
 
 67  0
         statusCriteria.addOrCriteria(activatedCriteria);
 68  0
         statusCriteria.addOrCriteria(initializedCriteria);
 69  0
         crit.addAndCriteria(statusCriteria);
 70  0
         crit.addIn("responsibilityId", responsibilityIds);
 71  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 72  
     }
 73  
 
 74  
     public List findPendingByActionRequestedAndDocId(String actionRequestedCd, String documentId) {
 75  0
         Criteria crit = new Criteria();
 76  0
         crit.addEqualTo("actionRequested", actionRequestedCd);
 77  0
         crit.addEqualTo("documentId", documentId);
 78  0
         crit.addEqualTo("currentIndicator", Boolean.TRUE);
 79  0
         crit.addAndCriteria(getPendingCriteria());
 80  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 81  
     }
 82  
 
 83  
     @SuppressWarnings("unchecked")
 84  
     public List<ActionRequestValue> findByStatusAndDocId(String statusCd, String documentId) {
 85  0
         Criteria crit = new Criteria();
 86  0
         crit.addEqualTo("status", statusCd);
 87  0
         crit.addEqualTo("documentId", documentId);
 88  0
         crit.addEqualTo("currentIndicator", true);
 89  
 
 90  0
         return (List<ActionRequestValue>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 91  
     }
 92  
 
 93  
     private void loadDefaultValues(ActionRequestValue actionRequest) {
 94  0
         checkNull(actionRequest.getActionRequested(), "action requested");
 95  0
         checkNull(actionRequest.getResponsibilityId(), "responsibility ID");
 96  0
         checkNull(actionRequest.getRouteLevel(), "route level");
 97  0
         checkNull(actionRequest.getDocVersion(), "doc version");
 98  0
         if (actionRequest.getForceAction() == null) {
 99  0
             actionRequest.setForceAction(Boolean.FALSE);
 100  
         }
 101  0
         if (actionRequest.getStatus() == null) {
 102  0
             actionRequest.setStatus(KEWConstants.ACTION_REQUEST_INITIALIZED);
 103  
         }
 104  0
         if (actionRequest.getPriority() == null) {
 105  0
             actionRequest.setPriority(KEWConstants.ACTION_REQUEST_DEFAULT_PRIORITY);
 106  
         }
 107  0
         if (actionRequest.getCurrentIndicator() == null) {
 108  0
             actionRequest.setCurrentIndicator(true);
 109  
         }
 110  0
         actionRequest.setCreateDate(new Timestamp(System.currentTimeMillis()));
 111  0
     }
 112  
 
 113  
     //TODO Runtime might not be the right thing to do here...
 114  
     private void checkNull(Object value, String valueName) throws RuntimeException {
 115  0
         if (value == null) {
 116  0
             throw new RuntimeException("Null value for " + valueName);
 117  
         }
 118  0
     }
 119  
 
 120  
     public List findPendingRootRequestsByDocIdAtRouteLevel(String documentId, Integer routeLevel) {
 121  0
         Criteria crit = new Criteria();
 122  0
         crit.addEqualTo("routeLevel", routeLevel);
 123  0
         crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
 124  0
         crit.addEqualTo("documentId", documentId);
 125  0
         crit.addEqualTo("currentIndicator", Boolean.TRUE);
 126  0
         crit.addIsNull("parentActionRequest");
 127  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 128  
     }
 129  
 
 130  
     public List findPendingByDocIdAtOrBelowRouteLevel(String documentId, Integer routeLevel) {
 131  0
         Criteria crit = new Criteria();
 132  0
         crit.addLessOrEqualThan("routeLevel", routeLevel);
 133  0
         crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
 134  0
         crit.addEqualTo("documentId", documentId);
 135  0
         crit.addEqualTo("currentIndicator", true);
 136  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 137  
     }
 138  
 
 139  
     public List findPendingRootRequestsByDocIdAtOrBelowRouteLevel(String documentId, Integer routeLevel) {
 140  0
         Criteria crit = new Criteria();
 141  0
         crit.addLessOrEqualThan("routeLevel", routeLevel);
 142  0
         crit.addNotEqualTo("status", KEWConstants.ACTION_REQUEST_DONE_STATE);
 143  0
         crit.addEqualTo("documentId", documentId);
 144  0
         crit.addEqualTo("currentIndicator", true);
 145  0
         crit.addIsNull("parentActionRequest");
 146  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 147  
     }
 148  
 
 149  
     public void delete(Long actionRequestId) {
 150  0
             Criteria crit = new Criteria();
 151  0
             crit.addEqualTo("actionRequestId", actionRequestId);
 152  0
             this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 153  0
     }
 154  
 
 155  
     public List findAllPendingByDocId(String documentId) {
 156  0
         Criteria initializedStatCriteria = new Criteria();
 157  0
         initializedStatCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
 158  
 
 159  0
         Criteria activatedStatCriteria = new Criteria();
 160  0
         activatedStatCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
 161  
 
 162  0
         Criteria statusCriteria = new Criteria();
 163  0
         statusCriteria.addOrCriteria(initializedStatCriteria);
 164  0
         statusCriteria.addOrCriteria(activatedStatCriteria);
 165  
 
 166  0
         Criteria crit = new Criteria();
 167  0
         crit.addEqualTo("documentId", documentId);
 168  0
         crit.addEqualTo("currentIndicator", true);
 169  0
         crit.addAndCriteria(statusCriteria);
 170  
 
 171  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 172  
     }
 173  
 
 174  
     public List findAllByDocId(String documentId) {
 175  0
         Criteria crit = new Criteria();
 176  0
         crit.addEqualTo("documentId", documentId);
 177  0
         crit.addEqualTo("currentIndicator", true);
 178  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 179  
     }
 180  
 
 181  
     public List findAllRootByDocId(String documentId) {
 182  0
         Criteria crit = new Criteria();
 183  0
         crit.addEqualTo("documentId", documentId);
 184  0
         crit.addEqualTo("currentIndicator", true);
 185  0
         crit.addIsNull("parentActionRequest");
 186  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 187  
     }
 188  
 
 189  
     public List findByDocumentIdIgnoreCurrentInd(String documentId) {
 190  0
         Criteria crit = new Criteria();
 191  0
         crit.addEqualTo("documentId", documentId);
 192  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 193  
     }
 194  
 
 195  
     
 196  
     private Criteria getPendingCriteria() {
 197  0
         Criteria pendingCriteria = new Criteria();
 198  0
         Criteria activatedCriteria = new Criteria();
 199  0
         activatedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
 200  0
         Criteria initializedCriteria = new Criteria();
 201  0
         initializedCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_INITIALIZED);
 202  0
         pendingCriteria.addOrCriteria(activatedCriteria);
 203  0
         pendingCriteria.addOrCriteria(initializedCriteria);
 204  0
         return pendingCriteria;
 205  
     }
 206  
 
 207  
     public  void deleteByDocumentId(String documentId){
 208  0
         Criteria crit = new Criteria();
 209  0
         crit.addEqualTo("documentId", documentId);
 210  0
         this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 211  0
     }
 212  
 
 213  
     public List findPendingRootRequestsByDocumentType(Long documentTypeId) {
 214  0
             Criteria routeHeaderCrit = new Criteria();
 215  0
             routeHeaderCrit.addEqualTo("documentTypeId", documentTypeId);
 216  0
             Criteria crit = new Criteria();
 217  
         //crit.addEqualTo("routeHeader.documentTypeId", documentTypeId);
 218  0
             crit.addIn("documentId", new ReportQueryByCriteria(DocumentRouteHeaderValue.class, new String[] {"documentId"}, routeHeaderCrit));
 219  0
         crit.addAndCriteria(getPendingCriteria());
 220  0
         crit.addEqualTo("currentIndicator", Boolean.TRUE);
 221  0
         crit.addIsNull("parentActionRequest");
 222  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 223  
     }
 224  
 
 225  
     public List findPendingRootRequestsByDocIdAtRouteNode(String documentId, Long nodeInstanceId) {
 226  0
             Criteria crit = new Criteria();
 227  0
         crit.addEqualTo("documentId", documentId);
 228  0
         crit.addAndCriteria(getPendingCriteria());
 229  0
         crit.addEqualTo("currentIndicator", Boolean.TRUE);
 230  0
         crit.addIsNull("parentActionRequest");
 231  0
         crit.addEqualTo("nodeInstance.routeNodeInstanceId", nodeInstanceId);
 232  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 233  
     }
 234  
 
 235  
     public List findRootRequestsByDocIdAtRouteNode(String documentId, Long nodeInstanceId) {
 236  0
         Criteria crit = new Criteria();
 237  0
         crit.addEqualTo("documentId", documentId);
 238  0
         crit.addEqualTo("currentIndicator", Boolean.TRUE);
 239  0
         crit.addIsNull("parentActionRequest");
 240  0
         crit.addEqualTo("nodeInstance.routeNodeInstanceId", nodeInstanceId);
 241  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 242  
     }
 243  
 
 244  
     public boolean doesDocumentHaveUserRequest(String principalId, String documentId) {
 245  0
             Criteria crit = new Criteria();
 246  0
             crit.addEqualTo("documentId", documentId);
 247  0
             crit.addEqualTo("recipientTypeCd", KEWConstants.ACTION_REQUEST_USER_RECIPIENT_CD);
 248  0
             crit.addEqualTo("principalId", principalId);
 249  0
             crit.addEqualTo("currentIndicator", Boolean.TRUE);
 250  0
             int count = getPersistenceBrokerTemplate().getCount(new QueryByCriteria(ActionRequestValue.class, crit));
 251  0
             return count > 0;
 252  
     }
 253  
 
 254  
     public List<String> getRequestGroupIds(String documentId) {
 255  0
             Criteria crit = new Criteria();
 256  0
             crit.addEqualTo("documentId", documentId);
 257  0
             crit.addEqualTo("recipientTypeCd", KEWConstants.ACTION_REQUEST_GROUP_RECIPIENT_CD);
 258  0
             crit.addEqualTo("currentIndicator", Boolean.TRUE);
 259  
 
 260  0
             ReportQueryByCriteria query = QueryFactory.newReportQuery(ActionRequestValue.class, crit);
 261  0
             query.setAttributes(new String[] { "groupId" });
 262  
 
 263  0
             List<String> groupIds = new ArrayList<String>();
 264  0
             Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
 265  0
             while (iter.hasNext()) {
 266  0
                         Object[] row = (Object[]) iter.next();
 267  0
                         String id = (String)row[0];
 268  0
                         groupIds.add(id);
 269  0
                 }
 270  0
             return groupIds;
 271  
     }
 272  
 
 273  
         /**
 274  
          * @see org.kuali.rice.kew.actionrequest.dao.ActionRequestDAO#findActivatedByGroup(String)
 275  
          */
 276  
         public List findActivatedByGroup(String groupId) {
 277  0
         Criteria statusCriteria = new Criteria();
 278  0
         statusCriteria.addEqualTo("status", KEWConstants.ACTION_REQUEST_ACTIVATED);
 279  0
         Criteria crit = new Criteria();
 280  0
         crit.addEqualTo("groupId", groupId);
 281  0
         crit.addEqualTo("currentIndicator", true);
 282  0
         crit.addAndCriteria(statusCriteria);
 283  
 
 284  0
         return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionRequestValue.class, crit));
 285  
         }
 286  
 }