Coverage Report - org.kuali.student.core.document.dao.impl.DocumentDaoImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentDaoImpl
0%
0/45
0%
0/8
1.857
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.document.dao.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.ListIterator;
 21  
 
 22  
 import javax.persistence.EntityManager;
 23  
 import javax.persistence.PersistenceContext;
 24  
 import javax.persistence.Query;
 25  
 
 26  
 import org.apache.log4j.Logger;
 27  
 import org.kuali.student.common.dao.impl.AbstractSearchableCrudDaoImpl;
 28  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 29  
 import org.kuali.student.core.document.dao.DocumentDao;
 30  
 import org.kuali.student.core.document.entity.Document;
 31  
 import org.kuali.student.core.document.entity.DocumentCategory;
 32  
 import org.kuali.student.core.document.entity.RefDocRelation;
 33  
 
 34  
 /**
 35  
  * This is a description of what this class does - lindholm don't forget to fill this in.
 36  
  * 
 37  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 38  
  */
 39  0
 public class DocumentDaoImpl extends AbstractSearchableCrudDaoImpl implements DocumentDao {
 40  
     
 41  0
     final Logger logger = Logger.getLogger(DocumentDaoImpl.class);
 42  
     
 43  
     @PersistenceContext(unitName = "Document")
 44  
     @Override
 45  
     public void setEm(EntityManager em) {
 46  0
         super.setEm(em);
 47  0
     }
 48  
 
 49  
     @Override
 50  
     public Boolean addDocumentCategoryToDocument(String documentId, String documentCategoryKey) throws DoesNotExistException {
 51  
 
 52  0
         DocumentCategory category = fetch(DocumentCategory.class, documentCategoryKey);
 53  0
         Document doc = fetch(Document.class, documentId);
 54  0
         List<DocumentCategory> categoryList = doc.getCategoryList();
 55  0
         categoryList.add(category);
 56  0
         doc.setCategoryList(categoryList);
 57  0
         update(doc);
 58  0
         return true;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public List<DocumentCategory> getCategoriesByDocument(String documentId) {
 63  
 
 64  0
         Document doc = null;
 65  
         try {
 66  0
             doc = fetch(Document.class, documentId);
 67  0
         } catch (DoesNotExistException e) {
 68  0
             logger.error("Exception occured: ", e);
 69  0
         }
 70  0
         List<DocumentCategory> categories = doc.getCategoryList();
 71  
 
 72  0
         return categories;
 73  
     }
 74  
 
 75  
     @Override
 76  
     public List<Document> getDocumentsByIdList(List<String> documentIdList) throws DoesNotExistException {
 77  0
         List<Document> documents = new ArrayList<Document>();
 78  0
         for (String documentId : documentIdList) {
 79  
             Document document;
 80  0
             document = fetch(Document.class, documentId);
 81  0
             documents.add(document);
 82  0
         }
 83  0
         return documents;
 84  
     }
 85  
 
 86  
     @Override
 87  
     public Boolean removeDocumentCategoryFromDocument(String documentId, String documentCategoryKey) throws DoesNotExistException {
 88  0
         Document document = fetch(Document.class, documentId);
 89  0
         List<DocumentCategory> categories = document.getCategoryList();
 90  0
         ListIterator<DocumentCategory> listIterator = categories.listIterator();
 91  
         //Because there must be atleast one category associated with a document. 
 92  
         //https://test.kuali.org/confluence/display/KULSTU/Document+Service+Description+and+Assumptions
 93  0
         if(categories.size()<=1){
 94  0
             return false;
 95  
         }
 96  0
         for (int intIndex = 0; intIndex < categories.size(); intIndex++) {
 97  
 
 98  0
             DocumentCategory category = listIterator.next();
 99  0
             if (category.getId().equals(documentCategoryKey)) {
 100  0
               listIterator.remove();
 101  
             }
 102  
         }
 103  0
         document.setCategoryList(categories);
 104  0
         update(document);
 105  0
         return true;
 106  
     }
 107  
 
 108  
         @Override
 109  
         public List<RefDocRelation> getRefDocRelationsByRef(
 110  
                         String refObjectTypeKey, String refObjectId) {
 111  0
                 Query query = em.createNamedQuery("RefDocRelation.getRefDocRelationsByRef");
 112  0
                 query.setParameter("refObjectTypeKey", refObjectTypeKey);
 113  0
                 query.setParameter("refObjectId", refObjectId);
 114  
                 @SuppressWarnings("unchecked")
 115  0
                 List<RefDocRelation> resultList = query.getResultList();
 116  0
                 return resultList;
 117  
         }
 118  
 
 119  
         @Override
 120  
         public List<RefDocRelation> getRefDocRelationsByDoc(String documentId) {
 121  0
                 Query query = em.createNamedQuery("RefDocRelation.getRefDocRelationsByDoc");
 122  0
                 query.setParameter("documentId", documentId);
 123  
                 @SuppressWarnings("unchecked")
 124  0
                 List<RefDocRelation> resultList = query.getResultList();
 125  0
                 return resultList;
 126  
         }
 127  
 
 128  
 }