Coverage Report - org.kuali.rice.edl.impl.dao.impl.EDocLiteDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
EDocLiteDAOJpaImpl
0%
0/44
0%
0/14
1.7
 
 1  
 /*
 2  
  * Copyright 2009 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.dao.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.persistence.EntityManager;
 22  
 import javax.persistence.PersistenceContext;
 23  
 
 24  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 25  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 26  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 27  
 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
 28  
 import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
 29  
 import org.kuali.rice.edl.impl.dao.EDocLiteDAO;
 30  
 
 31  
 /**
 32  
  * JPA implementation of the EDOcLiteDAO
 33  
  *
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  */
 36  0
 public class EDocLiteDAOJpaImpl implements EDocLiteDAO {
 37  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class);
 38  
 
 39  
     private static final String ACTIVE_IND_CRITERIA = "activeInd";
 40  
     private static final String NAME_CRITERIA = "name";
 41  
 
 42  
     @PersistenceContext(unitName = "kew-unit")
 43  
     private EntityManager entityManager;
 44  
 
 45  
     /**
 46  
      * Save a EDocLiteDefinition
 47  
      *
 48  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#saveEDocLiteDefinition(org.kuali.rice.edl.impl.bo.EDocLiteDefinition)
 49  
      */
 50  
     public void saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) {
 51  0
         if (edocLiteData.getEDocLiteDefId() == null) {
 52  0
             entityManager.persist(edocLiteData);
 53  
         } else {
 54  0
             OrmUtils.merge(entityManager, edocLiteData);
 55  
         }
 56  0
     }
 57  
 
 58  
     /**
 59  
      * Save a EDocLiteAssocitaion
 60  
      *
 61  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#saveEDocLiteAssociation(org.kuali.rice.edl.impl.bo.EDocLiteAssociation)
 62  
      */
 63  
     public void saveEDocLiteAssociation(final EDocLiteAssociation assoc) {
 64  0
         if (assoc.getEdocLiteAssocId() == null) {
 65  0
             entityManager.persist(assoc);
 66  
         } else {
 67  0
             OrmUtils.merge(entityManager, assoc);
 68  
         }
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Get a EDocLiteDefinition
 73  
      *
 74  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#getEDocLiteDefinition(java.lang.String)
 75  
      */
 76  
     public EDocLiteDefinition getEDocLiteDefinition(final String defName) {
 77  0
         final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
 78  0
         crit.eq(NAME_CRITERIA, defName);
 79  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 80  0
         return (EDocLiteDefinition) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 81  
     }
 82  
 
 83  
     /**
 84  
      * Get a EDocLiteAssociation
 85  
      *
 86  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#getEDocLiteAssociation(java.lang.String)
 87  
      */
 88  
     public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) {
 89  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 90  0
         crit.eq("edlName", docTypeName);
 91  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 92  0
         return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 93  
     }
 94  
 
 95  
     /**
 96  
      * Returns the names of all active Definitions
 97  
      *
 98  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#getEDocLiteDefinitions()
 99  
      */
 100  
     @SuppressWarnings("unchecked")
 101  
     public List<String> getEDocLiteDefinitions() {
 102  0
         final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
 103  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 104  
 
 105  0
         final List<EDocLiteDefinition> defs = (List<EDocLiteDefinition>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 106  0
         final ArrayList<String> names = new ArrayList<String>(defs.size());
 107  0
         for (EDocLiteDefinition def : defs) {
 108  0
             names.add(def.getName());
 109  
         }
 110  0
         return names;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Returns all active Definitions
 115  
      *
 116  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#getEDocLiteAssociations()
 117  
      */
 118  
     @SuppressWarnings("unchecked")
 119  
     public List<EDocLiteAssociation> getEDocLiteAssociations() {
 120  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 121  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 122  0
         return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 123  
     }
 124  
 
 125  
     /**
 126  
      * Finds matching Associations
 127  
      *
 128  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#search(org.kuali.rice.edl.impl.bo.EDocLiteAssociation)
 129  
      */
 130  
     @SuppressWarnings("unchecked")
 131  
     public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) {
 132  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 133  0
         if (edocLite.getActiveInd() != null) {
 134  0
             crit.eq(ACTIVE_IND_CRITERIA, edocLite.getActiveInd());
 135  
         }
 136  0
         if (edocLite.getDefinition() != null) {
 137  0
             crit.like("UPPER(definition)", "%" + edocLite.getDefinition().toUpperCase() + "%");
 138  
         }
 139  0
         if (edocLite.getEdlName() != null) {
 140  0
             crit.like("UPPER(edlName)", "%" + edocLite.getEdlName().toUpperCase() + "%");
 141  
         }
 142  0
         if (edocLite.getStyle() != null) {
 143  0
             crit.like("UPPER(style)", "%" + edocLite.getStyle().toUpperCase() + "%");
 144  
         }
 145  0
         return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 146  
     }
 147  
 
 148  
     /**
 149  
      * Returns a specific Association
 150  
      *
 151  
      * @see org.kuali.rice.edl.impl.dao.EDocLiteDAO#getEDocLiteAssociation(java.lang.Long)
 152  
      */
 153  
     public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) {
 154  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 155  0
         crit.eq("edocLiteAssocId", associationId);
 156  0
         return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 157  
     }
 158  
 
 159  
     public EntityManager getEntityManager() {
 160  0
         return this.entityManager;
 161  
     }
 162  
 
 163  
     public void setEntityManager(EntityManager entityManager) {
 164  0
         this.entityManager = entityManager;
 165  0
     }
 166  
 }