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