Coverage Report - org.kuali.rice.kew.edl.dao.impl.EDocLiteDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
EDocLiteDAOJpaImpl
0%
0/68
0%
0/18
2.214
 
 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.kew.edl.dao.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.persistence.EntityManager;
 22  
 import javax.persistence.NoResultException;
 23  
 import javax.persistence.PersistenceContext;
 24  
 
 25  
 import org.kuali.rice.core.jpa.criteria.Criteria;
 26  
 import org.kuali.rice.core.jpa.criteria.QueryByCriteria;
 27  
 import org.kuali.rice.core.util.OrmUtils;
 28  
 import org.kuali.rice.kew.edl.bo.EDocLiteAssociation;
 29  
 import org.kuali.rice.kew.edl.bo.EDocLiteDefinition;
 30  
 import org.kuali.rice.kew.edl.bo.EDocLiteStyle;
 31  
 import org.kuali.rice.kew.edl.dao.EDocLiteDAO;
 32  
 
 33  
 /**
 34  
  * JPA implementation of the EDOcLiteDAO
 35  
  *
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  0
 public class EDocLiteDAOJpaImpl implements EDocLiteDAO {
 39  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class);
 40  
 
 41  
     private static final String ACTIVE_IND_CRITERIA = "activeInd";
 42  
     private static final String NAME_CRITERIA = "name";
 43  
 
 44  
     @PersistenceContext(unitName = "kew-unit")
 45  
     private EntityManager entityManager;
 46  
 
 47  
     /**
 48  
      * Save a EDocLiteStyle
 49  
      *
 50  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#saveEDocLiteStyle(org.kuali.rice.kew.edl.bo.EDocLiteStyle)
 51  
      */
 52  
     public void saveEDocLiteStyle(final EDocLiteStyle styleData) {
 53  0
         if (styleData.getEdocLiteStyleId() == null) {
 54  0
             entityManager.persist(styleData);
 55  
         } else {
 56  0
             OrmUtils.merge(entityManager, styleData);
 57  
         }
 58  0
     }
 59  
 
 60  
     /**
 61  
      * Save a EDocLiteDefinition
 62  
      *
 63  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#saveEDocLiteDefinition(org.kuali.rice.kew.edl.bo.EDocLiteDefinition)
 64  
      */
 65  
     public void saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) {
 66  0
         if (edocLiteData.getEDocLiteDefId() == null) {
 67  0
             entityManager.persist(edocLiteData);
 68  
         } else {
 69  0
             OrmUtils.merge(entityManager, edocLiteData);
 70  
         }
 71  0
     }
 72  
 
 73  
     /**
 74  
      * Save a EDocLiteAssocitaion
 75  
      *
 76  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#saveEDocLiteAssociation(org.kuali.rice.kew.edl.bo.EDocLiteAssociation)
 77  
      */
 78  
     public void saveEDocLiteAssociation(final EDocLiteAssociation assoc) {
 79  0
         if (assoc.getEdocLiteAssocId() == null) {
 80  0
             entityManager.persist(assoc);
 81  
         } else {
 82  0
             OrmUtils.merge(entityManager, assoc);
 83  
         }
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Get a EDocLoiteStyle
 88  
      *
 89  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteStyle(java.lang.String)
 90  
      */
 91  
     public EDocLiteStyle getEDocLiteStyle(final String styleName) {
 92  0
         final Criteria crit = new Criteria(EDocLiteStyle.class.getName());
 93  
 
 94  0
         crit.eq(NAME_CRITERIA, styleName);
 95  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 96  
 
 97  
         try {
 98  0
             return (EDocLiteStyle) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 99  0
         } catch (NoResultException e) {
 100  0
             return null;
 101  
         }
 102  
     }
 103  
 
 104  
     /**
 105  
      * Get a EDocLiteDefinition
 106  
      *
 107  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteDefinition(java.lang.String)
 108  
      */
 109  
     public EDocLiteDefinition getEDocLiteDefinition(final String defName) {
 110  0
         final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
 111  0
         crit.eq(NAME_CRITERIA, defName);
 112  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 113  
         try {
 114  0
             return (EDocLiteDefinition) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 115  0
         } catch (NoResultException e) {
 116  0
             return null;
 117  
         }
 118  
     }
 119  
 
 120  
     /**
 121  
      * Get a EDocLiteAssociation
 122  
      *
 123  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteAssociation(java.lang.String)
 124  
      */
 125  
     public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) {
 126  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 127  0
         crit.eq("edlName", docTypeName);
 128  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 129  
         try {
 130  0
             return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 131  0
         } catch (NoResultException e) {
 132  0
             return null;
 133  
         }
 134  
     }
 135  
 
 136  
     /**
 137  
      * Returns names of all active Styles
 138  
      *
 139  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteStyleNames()
 140  
      */
 141  
     public List<String> getEDocLiteStyleNames() {
 142  0
         final List<EDocLiteStyle> styles = getEDocLiteStyles();
 143  0
         final List<String> styleNames = new ArrayList<String>(styles.size());
 144  0
         for (EDocLiteStyle style : styles) {
 145  0
             styleNames.add(style.getName());
 146  
         }
 147  0
         return styleNames;
 148  
     }
 149  
 
 150  
     /**
 151  
      * Returns all active Styles
 152  
      *
 153  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteStyles()
 154  
      */
 155  
     @SuppressWarnings("unchecked")
 156  
     public List<EDocLiteStyle> getEDocLiteStyles() {
 157  0
         final Criteria crit = new Criteria(EDocLiteStyle.class.getName());
 158  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 159  
 
 160  0
         return (List<EDocLiteStyle>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 161  
 
 162  
     }
 163  
 
 164  
     /**
 165  
      * Returns the names of all active Definitions
 166  
      *
 167  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteDefinitions()
 168  
      */
 169  
     @SuppressWarnings("unchecked")
 170  
     public List<String> getEDocLiteDefinitions() {
 171  0
         final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
 172  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 173  
 
 174  0
         final List<EDocLiteDefinition> defs = (List<EDocLiteDefinition>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 175  0
         final ArrayList<String> names = new ArrayList<String>(defs.size());
 176  0
         for (EDocLiteDefinition def : defs) {
 177  0
             names.add(def.getName());
 178  
         }
 179  0
         return names;
 180  
     }
 181  
 
 182  
     /**
 183  
      * Returns all active Definitions
 184  
      *
 185  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteAssociations()
 186  
      */
 187  
     @SuppressWarnings("unchecked")
 188  
     public List<EDocLiteAssociation> getEDocLiteAssociations() {
 189  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 190  0
         crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
 191  0
         return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 192  
     }
 193  
 
 194  
     /**
 195  
      * Finds matching Associations
 196  
      *
 197  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#search(org.kuali.rice.kew.edl.bo.EDocLiteAssociation)
 198  
      */
 199  
     @SuppressWarnings("unchecked")
 200  
     public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) {
 201  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 202  0
         if (edocLite.getActiveInd() != null) {
 203  0
             crit.eq(ACTIVE_IND_CRITERIA, edocLite.getActiveInd());
 204  
         }
 205  0
         if (edocLite.getDefinition() != null) {
 206  0
             crit.like("UPPER(definition)", "%" + edocLite.getDefinition().toUpperCase() + "%");
 207  
         }
 208  0
         if (edocLite.getEdlName() != null) {
 209  0
             crit.like("UPPER(edlName)", "%" + edocLite.getEdlName().toUpperCase() + "%");
 210  
         }
 211  0
         if (edocLite.getStyle() != null) {
 212  0
             crit.like("UPPER(style)", "%" + edocLite.getStyle().toUpperCase() + "%");
 213  
         }
 214  0
         return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 215  
     }
 216  
 
 217  
     /**
 218  
      * Returns a specific Association
 219  
      *
 220  
      * @see org.kuali.rice.kew.edl.dao.EDocLiteDAO#getEDocLiteAssociation(java.lang.Long)
 221  
      */
 222  
     public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) {
 223  0
         final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
 224  0
         crit.eq("edocLiteAssocId", associationId);
 225  
         try {
 226  0
             return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
 227  0
         } catch (NoResultException e) {
 228  0
             return null;
 229  
         }
 230  
     }
 231  
 
 232  
     public EntityManager getEntityManager() {
 233  0
         return this.entityManager;
 234  
     }
 235  
 
 236  
     public void setEntityManager(EntityManager entityManager) {
 237  0
         this.entityManager = entityManager;
 238  0
     }
 239  
 }