001 /*
002 * Copyright 2008 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kim.impl.permission;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020 import java.util.List;
021
022 import org.apache.ojb.broker.query.Criteria;
023 import org.apache.ojb.broker.query.Query;
024 import org.apache.ojb.broker.query.QueryFactory;
025 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
026 import org.kuali.rice.kim.api.permission.Permission;
027 import org.kuali.rice.kim.impl.role.RolePermissionBo;
028
029 /**
030 * This is a description of what this class does - kellerj don't forget to fill this in.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 *
034 */
035 public class PermissionDaoOjb extends PlatformAwareDaoBaseOjb implements PermissionDao {
036
037 @SuppressWarnings("unchecked")
038 public List<String> getRoleIdsForPermissions(Collection<Permission> permissions) {
039 if ( permissions.isEmpty() ) {
040 return new ArrayList<String>(0);
041 }
042 List<String> permissionIds = new ArrayList<String>( permissions.size() );
043 for ( Permission permission : permissions ) {
044 permissionIds.add( permission.getId() );
045 }
046 Criteria c = new Criteria();
047 c.addIn( "permissionId", permissionIds );
048 c.addEqualTo( "active", true );
049
050 Query query = QueryFactory.newQuery( RolePermissionBo.class, c, true );
051 Collection<RolePermissionBo> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);
052 List<String> roleIds = new ArrayList<String>( coll.size() );
053 for ( RolePermissionBo rp : coll ) {
054 roleIds.add( rp.getRoleId() );
055 }
056 return roleIds;
057 }
058
059 }