Coverage Report - org.kuali.rice.kim.dao.impl.KimResponsibilityDaoJpa
 
Classes in this File Line Coverage Branch Coverage Complexity
KimResponsibilityDaoJpa
0%
0/46
0%
0/14
2.6
 
 1  
 /*
 2  
  * Copyright 2008 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.kim.dao.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.persistence.EntityManager;
 23  
 import javax.persistence.PersistenceContext;
 24  
 
 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.kim.bo.role.KimResponsibility;
 28  
 import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl;
 29  
 import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl;
 30  
 import org.kuali.rice.kim.dao.KimResponsibilityDao;
 31  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 32  
 import org.kuali.rice.kim.util.KimConstants;
 33  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 34  
 
 35  
 /**
 36  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 37  
  * 
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  *
 40  
  */
 41  0
 public class KimResponsibilityDaoJpa implements KimResponsibilityDao {
 42  
 
 43  
     @PersistenceContext(unitName="kim-unit")
 44  
     private EntityManager entityManager;
 45  
     
 46  
         /**
 47  
          * @see org.kuali.rice.kim.dao.KimResponsibilityDao#getRoleIdsForResponsibilities(java.util.Collection)
 48  
          */
 49  
         @SuppressWarnings("unchecked")
 50  
         public List<String> getRoleIdsForResponsibilities(Collection<? extends KimResponsibility> responsibilities) {
 51  0
                 List<String> responsibilityIds = new ArrayList<String>( responsibilities.size() );
 52  0
                 for ( KimResponsibility kp : responsibilities ) {
 53  0
                         responsibilityIds.add( kp.getResponsibilityId() );
 54  
                 }
 55  0
                 Criteria c = new Criteria(RoleResponsibilityImpl.class.getName());
 56  0
                 c.in( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibilityIds );
 57  0
                 c.eq( KNSPropertyConstants.ACTIVE, true );
 58  
                 
 59  
                 //Query query = QueryFactory.newQuery( RoleResponsibilityImpl.class, c, true );
 60  
                 
 61  0
                 ArrayList<RoleResponsibilityImpl> coll = (ArrayList<RoleResponsibilityImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList();
 62  0
                 List<String> roleIds = new ArrayList<String>( coll.size() );
 63  0
                 for ( RoleResponsibilityImpl rp : coll ) {
 64  0
                         roleIds.add( rp.getRoleId() );
 65  
                 }
 66  0
                 return roleIds;
 67  
         }
 68  
         
 69  
         /**
 70  
          * @see org.kuali.rice.kim.dao.KimResponsibilityDao#getRoleIdsForResponsibility(org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl)
 71  
          */
 72  
         @SuppressWarnings("unchecked")
 73  
         public List<String> getRoleIdsForResponsibility( KimResponsibility responsibility) {
 74  0
                 Criteria c = new Criteria(RoleResponsibilityImpl.class.getName());
 75  0
                 c.eq( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibility.getResponsibilityId() );
 76  0
                 c.eq( KNSPropertyConstants.ACTIVE, true );
 77  
                 
 78  0
                 ArrayList<RoleResponsibilityImpl> coll = (ArrayList<RoleResponsibilityImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList();
 79  0
                 List<String> roleIds = new ArrayList<String>( coll.size() );
 80  0
                 for ( RoleResponsibilityImpl rp : coll ) {
 81  0
                         roleIds.add( rp.getRoleId() );
 82  
                 }
 83  0
                 return roleIds;
 84  
         }
 85  
 
 86  
         /**
 87  
          * @see org.kuali.rice.kim.dao.KimResponsibilityDao#getResponsibilityAction(String, String)
 88  
          */
 89  
         @SuppressWarnings("unchecked")
 90  
         public RoleResponsibilityActionImpl getResponsibilityAction(String roleId, String responsibilityId, String roleMemberId ) {
 91  0
                 if ( roleMemberId == null || responsibilityId == null ) {
 92  0
                         return null;
 93  
                 }
 94  
                 
 95  0
                 Criteria c = new Criteria(RoleResponsibilityActionImpl.class.getName());
 96  0
                 c.eq( "roleResponsibility.responsibilityId", responsibilityId );
 97  0
                 c.eq( "roleResponsibility.roleId", roleId );
 98  0
                 c.eq( "roleResponsibility.active", true );
 99  0
                 Criteria idCriteria = new Criteria(RoleResponsibilityActionImpl.class.getName(), c.getAlias());
 100  0
                 idCriteria.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId );
 101  
                 // also handle when roleMemberId is "*" in table
 102  0
                 Criteria starCrit = new Criteria(RoleResponsibilityActionImpl.class.getName(), c.getAlias());
 103  0
                 starCrit.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, "*" );
 104  0
                 idCriteria.or( starCrit );
 105  0
                 c.and( idCriteria );
 106  
                 
 107  0
                 ArrayList<RoleResponsibilityActionImpl> coll = (ArrayList<RoleResponsibilityActionImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList();
 108  0
                 RoleResponsibilityActionImpl result = null;
 109  0
                 if ( coll.size() == 0 ) {
 110  
                         // ok, an exact match failed, attempt to pull where the role_rsp_id is "*"
 111  
                         // but, at this point, we would require an exact match on the role member ID
 112  0
                         c = new Criteria(RoleResponsibilityActionImpl.class.getName());
 113  0
                         c.eq( "roleResponsibilityId", "*" );
 114  0
                         c.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId );
 115  0
                         coll = (ArrayList<RoleResponsibilityActionImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList();
 116  0
                         if ( coll.size() != 0 ) {
 117  0
                                 result = coll.iterator().next();
 118  
                         }
 119  
                 } else {
 120  0
                         result = coll.iterator().next();
 121  
                 }
 122  0
                 return result;
 123  
         }
 124  
         
 125  
         public EntityManager getEntityManager() {
 126  0
         return this.entityManager;
 127  
     }
 128  
 
 129  
     public void setEntityManager(EntityManager entityManager) {
 130  0
         this.entityManager = entityManager;
 131  0
     }
 132  
 }