Coverage Report - org.kuali.rice.kns.dao.impl.DocumentDaoOjb
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentDaoOjb
0%
0/33
0%
0/8
1.444
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.kns.dao.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.log4j.Logger;
 23  
 import org.apache.ojb.broker.query.Criteria;
 24  
 import org.apache.ojb.broker.query.QueryByCriteria;
 25  
 import org.apache.ojb.broker.query.QueryFactory;
 26  
 import org.kuali.rice.kim.bo.Group;
 27  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 28  
 import org.kuali.rice.kns.bo.AdHocRoutePerson;
 29  
 import org.kuali.rice.kns.bo.AdHocRouteWorkgroup;
 30  
 import org.kuali.rice.kns.bo.PersistableBusinessObject;
 31  
 import org.kuali.rice.kns.dao.BusinessObjectDao;
 32  
 import org.kuali.rice.kns.dao.DocumentDao;
 33  
 import org.kuali.rice.kns.document.Document;
 34  
 import org.kuali.rice.kns.service.DocumentAdHocService;
 35  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 36  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 37  
 import org.kuali.rice.kns.util.OjbCollectionAware;
 38  
 import org.springframework.dao.DataAccessException;
 39  
 
 40  
 /**
 41  
  * This class is the OJB implementation of the DocumentDao interface.
 42  
  */
 43  
 public class DocumentDaoOjb extends PlatformAwareDaoBaseOjb implements DocumentDao, OjbCollectionAware{
 44  0
     private static final Logger LOG = Logger.getLogger(DocumentDaoOjb.class);
 45  
     protected BusinessObjectDao businessObjectDao;
 46  
     protected DocumentAdHocService documentAdHocService;
 47  
 
 48  
 
 49  
     public DocumentDaoOjb(BusinessObjectDao businessObjectDao, DocumentAdHocService documentAdHocService) {
 50  0
         super();
 51  0
         this.businessObjectDao = businessObjectDao;
 52  0
         this.documentAdHocService = documentAdHocService;
 53  0
     }
 54  
 
 55  
     /*
 56  
      * (non-Javadoc)
 57  
      *
 58  
      * @see org.kuali.dao.DocumentDao#save(null)
 59  
      */
 60  
     public void save(Document document) throws DataAccessException {
 61  0
             if ( LOG.isDebugEnabled() ) {
 62  0
                     LOG.debug( "About to store document: " + document, new Throwable() );
 63  
             }
 64  0
         Document retrievedDocument = findByDocumentHeaderId(document.getClass(),document.getDocumentNumber());
 65  0
         KNSServiceLocator.getOjbCollectionHelper().processCollections(this, document, retrievedDocument);
 66  0
         this.getPersistenceBrokerTemplate().store(document);
 67  0
     }
 68  
 
 69  
     /**
 70  
      * Retrieve a Document of a specific type with a given document header ID.
 71  
      *
 72  
      * @param clazz
 73  
      * @param id
 74  
      * @return Document with given id
 75  
      */
 76  
     public Document findByDocumentHeaderId(Class clazz, String id) throws DataAccessException {
 77  0
         List idList = new ArrayList();
 78  0
         idList.add(id);
 79  
 
 80  0
         List documentList = findByDocumentHeaderIds(clazz, idList);
 81  
 
 82  0
         Document document = null;
 83  0
         if ((null != documentList) && (documentList.size() > 0)) {
 84  0
             document = (Document) documentList.get(0);
 85  
         }
 86  
 
 87  0
         return document;
 88  
     }
 89  
 
 90  
     /**
 91  
      * Retrieve a List of Document instances with the given ids
 92  
      *
 93  
      * @param clazz
 94  
      * @param idList
 95  
      * @return List
 96  
      */
 97  
     public List findByDocumentHeaderIds(Class clazz, List idList) throws DataAccessException {
 98  0
         Criteria criteria = new Criteria();
 99  0
         criteria.addIn(KNSPropertyConstants.DOCUMENT_NUMBER, idList);
 100  
 
 101  0
         QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
 102  0
         ArrayList <Document> tempList = new ArrayList(this.getPersistenceBrokerTemplate().getCollectionByQuery(query));
 103  0
         for (Document doc : tempList) documentAdHocService.addAdHocs(doc);
 104  0
         return tempList;
 105  
     }
 106  
 
 107  
     /**
 108  
      *
 109  
      * Deprecated method. Should use BusinessObjectService.linkAndSave() instead.
 110  
      *
 111  
      */
 112  
     @Deprecated
 113  
     public void saveMaintainableBusinessObject(PersistableBusinessObject businessObject) {
 114  
         /*
 115  
          * this call is to assure all the object fk values are in sync and the fk fields is set in the main object
 116  
          */
 117  0
         KNSServiceLocator.getPersistenceService().linkObjects(businessObject);
 118  0
         this.getPersistenceBrokerTemplate().store(businessObject);
 119  0
     }
 120  
 
 121  
     /**
 122  
      * Returns the {@link BusinessObjectDao}
 123  
      * @see org.kuali.rice.kns.dao.DocumentDao#getBusinessObjectDao()
 124  
      * @return the {@link BusinessObjectDao}
 125  
      */
 126  
     public BusinessObjectDao getBusinessObjectDao() {
 127  0
         return businessObjectDao;
 128  
     }
 129  
 
 130  
     /**
 131  
      * Sets the {@link BusinessObjectDao}
 132  
      * @param businessObjectDao ths {@link BusinessObjectDao}
 133  
      */
 134  
     public void setBusinessObjectDao(BusinessObjectDao businessObjectDao) {
 135  0
         this.businessObjectDao = businessObjectDao;
 136  0
     }
 137  
 
 138  
     /**
 139  
          * @return the documentAdHocService
 140  
          */
 141  
         public DocumentAdHocService getDocumentAdHocService() {
 142  0
                 return this.documentAdHocService;
 143  
         }
 144  
 
 145  
     /**
 146  
      * Setter for injecting the DocumentAdHocService
 147  
      * @param dahs
 148  
      */
 149  
     public void setDocumentAdHocService(DocumentAdHocService dahs) {
 150  0
             this.documentAdHocService = dahs;
 151  0
     }
 152  
 
 153  
 
 154  
 
 155  
 }