Coverage Report - org.kuali.rice.edl.impl.extract.dao.impl.ExtractDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtractDAOJpaImpl
0%
0/42
0%
0/6
1.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.edl.impl.extract.dao.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.persistence.EntityManager;
 21  
 import javax.persistence.PersistenceContext;
 22  
 
 23  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 24  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 25  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 26  
 import org.kuali.rice.edl.impl.extract.Dump;
 27  
 import org.kuali.rice.edl.impl.extract.Fields;
 28  
 import org.kuali.rice.edl.impl.extract.dao.ExtractDAO;
 29  
 import org.kuali.rice.kew.notes.Note;
 30  
 
 31  0
 public class ExtractDAOJpaImpl implements ExtractDAO {
 32  
 
 33  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractDAOJpaImpl.class);
 34  
 
 35  
     @PersistenceContext(unitName = "kew-unit")
 36  
     private EntityManager entityManager;
 37  
 
 38  
     public Dump getDumpByDocumentId(String docId) {
 39  0
         LOG.debug("finding Document Extract by documentId " + docId);
 40  0
         Criteria crit = new Criteria(Dump.class.getName());
 41  0
         crit.eq("docId", docId);
 42  0
         return (Dump) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 43  
     }
 44  
 
 45  
     public List<Fields> getFieldsByDocumentId(String docId) {
 46  0
         LOG.debug("finding Extract Fileds by documentId " + docId);
 47  0
         Criteria crit = new Criteria(Fields.class.getName());
 48  0
         crit.eq("documentId", docId);
 49  0
         crit.orderBy("docId", true);
 50  
 
 51  0
         return (List<Fields>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 52  
     }
 53  
 
 54  
     public void saveDump(Dump dump) {
 55  0
         LOG.debug("check for null values in Extract document");
 56  0
         checkNull(dump.getDocId(), "Document ID");
 57  0
         checkNull(dump.getDocCreationDate(), "Creation Date");
 58  0
         checkNull(dump.getDocCurrentNodeName(), "Current Node Name");
 59  0
         checkNull(dump.getDocModificationDate(), "Modification Date");
 60  0
         checkNull(dump.getDocRouteStatusCode(), "Route Status Code");
 61  0
         checkNull(dump.getDocInitiatorId(), "Initiator ID");
 62  0
         checkNull(dump.getDocTypeName(), "Doc Type Name");
 63  0
         LOG.debug("saving EDocLite document: routeHeader " + dump.getDocId());
 64  0
         if (dump.getDocId() == null) {
 65  0
             entityManager.persist(dump);
 66  
         } else {
 67  0
             OrmUtils.merge(entityManager, dump);
 68  
         }
 69  0
     }
 70  
 
 71  
     public void saveField(Fields field) {
 72  0
         LOG.debug("saving EDocLite Extract fields");
 73  0
         checkNull(field.getDocId(), "Document ID");
 74  0
         checkNull(field.getFieldValue(), "Field Value");
 75  0
         checkNull(field.getFiledName(), "Field Name");
 76  0
         LOG.debug("saving Fields: routeHeader " + field.getFieldId());
 77  
 
 78  0
         if (field.getFieldId() == null) {
 79  0
             entityManager.persist(field);
 80  
         } else {
 81  0
             OrmUtils.merge(entityManager, field);
 82  
         }
 83  0
     }
 84  
 
 85  
     private void checkNull(Object value, String valueName) throws RuntimeException {
 86  0
         if (value == null) {
 87  0
             throw new RuntimeException("Null value for " + valueName);
 88  
         }
 89  0
     }
 90  
 
 91  
     public void deleteDump(String documentId) {
 92  0
         LOG.debug("deleting record form Extract Dump table");
 93  0
         entityManager.remove(entityManager.find(Note.class, documentId));
 94  0
     }
 95  
 
 96  
     public EntityManager getEntityManager() {
 97  0
         return this.entityManager;
 98  
     }
 99  
 
 100  
     public void setEntityManager(EntityManager entityManager) {
 101  0
         this.entityManager = entityManager;
 102  0
     }
 103  
 }