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