|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kim.dao.impl;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.util.ArrayList;  | 
  |  19 |     | 
   import java.util.Collection;  | 
  |  20 |     | 
   import java.util.HashMap;  | 
  |  21 |     | 
   import java.util.List;  | 
  |  22 |     | 
   import java.util.Map;  | 
  |  23 |     | 
   import java.util.Map.Entry;  | 
  |  24 |     | 
     | 
  |  25 |     | 
   import org.apache.commons.collections.CollectionUtils;  | 
  |  26 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  27 |     | 
   import org.apache.ojb.broker.query.Criteria;  | 
  |  28 |     | 
   import org.apache.ojb.broker.query.Query;  | 
  |  29 |     | 
   import org.apache.ojb.broker.query.QueryFactory;  | 
  |  30 |     | 
   import org.apache.ojb.broker.query.ReportQueryByCriteria;  | 
  |  31 |     | 
   import org.kuali.rice.core.xml.dto.AttributeSet;  | 
  |  32 |     | 
   import org.kuali.rice.kim.bo.Role;  | 
  |  33 |     | 
   import org.kuali.rice.kim.bo.entity.KimPrincipal;  | 
  |  34 |     | 
   import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;  | 
  |  35 |     | 
   import org.kuali.rice.kim.bo.group.dto.GroupMembershipInfo;  | 
  |  36 |     | 
   import org.kuali.rice.kim.bo.impl.RoleImpl;  | 
  |  37 |     | 
   import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo;  | 
  |  38 |     | 
   import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo;  | 
  |  39 |     | 
   import org.kuali.rice.kim.bo.role.dto.RoleMemberCompleteInfo;  | 
  |  40 |     | 
   import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;  | 
  |  41 |     | 
   import org.kuali.rice.kim.bo.role.impl.KimDelegationImpl;  | 
  |  42 |     | 
   import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberImpl;  | 
  |  43 |     | 
   import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl;  | 
  |  44 |     | 
   import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl;  | 
  |  45 |     | 
   import org.kuali.rice.kim.dao.KimRoleDao;  | 
  |  46 |     | 
   import org.kuali.rice.kim.service.KIMServiceLocator;  | 
  |  47 |     | 
   import org.kuali.rice.kim.util.KIMPropertyConstants;  | 
  |  48 |     | 
   import org.kuali.rice.kim.util.KimConstants;  | 
  |  49 |     | 
   import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;  | 
  |  50 |     | 
     | 
  |  51 |     | 
     | 
  |  52 |     | 
     | 
  |  53 |     | 
     | 
  |  54 |     | 
     | 
  |  55 |     | 
     | 
  |  56 |     | 
     | 
  |  57 |     | 
     | 
  |  58 |    0 |    public class KimRoleDaoOjb extends PlatformAwareDaoBaseOjb implements KimRoleDao { | 
  |  59 |     | 
     | 
  |  60 |     | 
             | 
  |  61 |     | 
     | 
  |  62 |     | 
     | 
  |  63 |     | 
     | 
  |  64 |     | 
     | 
  |  65 |     | 
     | 
  |  66 |     | 
           private void addSubCriteriaBasedOnRoleQualification(Criteria c, AttributeSet qualification) { | 
  |  67 |    0 |                    if(qualification != null && CollectionUtils.isNotEmpty(qualification.keySet())) { | 
  |  68 |    0 |                            for(Map.Entry<String, String> qualifier : qualification.entrySet()) { | 
  |  69 |    0 |                            Criteria subCrit = new Criteria();  | 
  |  70 |    0 |                            if(StringUtils.isNotEmpty(qualifier.getValue())) { | 
  |  71 |    0 |                                            String value = (qualifier.getValue()).replace('*', '%'); | 
  |  72 |    0 |                                            subCrit.addLike("attributeValue", value); | 
  |  73 |    0 |                                            subCrit.addEqualTo("kimAttributeId", qualifier.getKey()); | 
  |  74 |    0 |                                            ReportQueryByCriteria subQuery = QueryFactory.newReportQuery(RoleMemberAttributeDataImpl.class, subCrit);  | 
  |  75 |    0 |                                            c.addExists(subQuery);  | 
  |  76 |     | 
                           }  | 
  |  77 |    0 |                            }  | 
  |  78 |     | 
                   }  | 
  |  79 |    0 |            }  | 
  |  80 |     | 
             | 
  |  81 |     | 
             | 
  |  82 |     | 
     | 
  |  83 |     | 
     | 
  |  84 |     | 
     | 
  |  85 |     | 
           @SuppressWarnings("unchecked") | 
  |  86 |     | 
           public List<RoleMemberImpl> getRolePrincipalsForPrincipalIdAndRoleIds( Collection<String> roleIds, String principalId, AttributeSet qualification) { | 
  |  87 |     | 
     | 
  |  88 |    0 |                    Criteria c = new Criteria();  | 
  |  89 |     | 
     | 
  |  90 |    0 |                    if ( roleIds != null ) { | 
  |  91 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds);  | 
  |  92 |     | 
                   }  | 
  |  93 |    0 |                    if(principalId!=null)  | 
  |  94 |    0 |                            c.addEqualTo(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId);  | 
  |  95 |    0 |                    c.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE );  | 
  |  96 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  97 |     | 
                     | 
  |  98 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  99 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  100 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  101 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  102 |    0 |                            if ( rm.isActive() ) { | 
  |  103 |    0 |                                    results.add(rm);  | 
  |  104 |     | 
                           }  | 
  |  105 |     | 
                   }  | 
  |  106 |    0 |                    return results;  | 
  |  107 |     | 
           }  | 
  |  108 |     | 
     | 
  |  109 |     | 
             | 
  |  110 |     | 
     | 
  |  111 |     | 
     | 
  |  112 |     | 
     | 
  |  113 |     | 
           public List<GroupMembershipInfo> getGroupPrincipalsForPrincipalIdAndGroupIds( Collection<String> groupIds, String principalId) { | 
  |  114 |    0 |                List<String> groupIdValues = new ArrayList<String>();  | 
  |  115 |    0 |                List<GroupMembershipInfo> groupPrincipals = new ArrayList<GroupMembershipInfo>();  | 
  |  116 |    0 |                if (groupIds != null  | 
  |  117 |     | 
                       && principalId == null) { | 
  |  118 |    0 |                    groupIdValues = new ArrayList<String>(groupIds);  | 
  |  119 |    0 |                } else if (principalId != null) { | 
  |  120 |    0 |                    groupIdValues = KIMServiceLocator.getGroupService().getGroupIdsForPrincipal(principalId);  | 
  |  121 |     | 
               }  | 
  |  122 |    0 |                if (groupIdValues != null  | 
  |  123 |     | 
                       && groupIdValues.size() > 0) { | 
  |  124 |    0 |                    Collection<GroupMembershipInfo> groupMembershipInfos = KIMServiceLocator.getGroupService().getGroupMembers(groupIdValues);  | 
  |  125 |    0 |                for (GroupMembershipInfo groupMembershipInfo : groupMembershipInfos) { | 
  |  126 |    0 |                    if (principalId != null) { | 
  |  127 |    0 |                        if (StringUtils.equals(groupMembershipInfo.getMemberTypeCode(), Role.PRINCIPAL_MEMBER_TYPE)  | 
  |  128 |     | 
                               && StringUtils.equals(principalId, groupMembershipInfo.getMemberId())  | 
  |  129 |     | 
                               && groupMembershipInfo.isActive()) { | 
  |  130 |    0 |                            groupPrincipals.add(groupMembershipInfo);  | 
  |  131 |     | 
                       }  | 
  |  132 |     | 
                   } else { | 
  |  133 |    0 |                        groupPrincipals.add(groupMembershipInfo);  | 
  |  134 |     | 
                   }  | 
  |  135 |     | 
               }  | 
  |  136 |     | 
               }  | 
  |  137 |    0 |                return groupPrincipals;  | 
  |  138 |     | 
           }  | 
  |  139 |     | 
     | 
  |  140 |     | 
             | 
  |  141 |     | 
     | 
  |  142 |     | 
     | 
  |  143 |     | 
     | 
  |  144 |     | 
           public List<GroupMembershipInfo> getGroupMembers(Collection<String> groupIds) { | 
  |  145 |    0 |                List<String> groupIdValues = new ArrayList<String>();  | 
  |  146 |    0 |                List<GroupMembershipInfo> groupMembers = new ArrayList<GroupMembershipInfo>();  | 
  |  147 |    0 |                if (groupIds != null) { | 
  |  148 |    0 |                    groupIdValues = new ArrayList<String>(groupIds);  | 
  |  149 |     | 
     | 
  |  150 |    0 |                    if (groupIdValues != null  | 
  |  151 |     | 
                           && groupIdValues.size() > 0) { | 
  |  152 |    0 |                        Collection<GroupMembershipInfo> groupMembershipInfos = KIMServiceLocator.getGroupService().getGroupMembers(groupIdValues);  | 
  |  153 |    0 |                        if (groupMembershipInfos != null) { | 
  |  154 |    0 |                            groupMembers = new ArrayList<GroupMembershipInfo>(groupMembershipInfos);  | 
  |  155 |     | 
                       }  | 
  |  156 |     | 
                         | 
  |  157 |     | 
                         | 
  |  158 |     | 
                         | 
  |  159 |     | 
                   }  | 
  |  160 |     | 
               }  | 
  |  161 |    0 |                return groupMembers;  | 
  |  162 |     | 
           }  | 
  |  163 |     | 
     | 
  |  164 |     | 
             | 
  |  165 |     | 
     | 
  |  166 |     | 
     | 
  |  167 |     | 
     | 
  |  168 |     | 
           @SuppressWarnings("unchecked") | 
  |  169 |     | 
           public List<RoleMemberImpl> getRoleGroupsForGroupIdsAndRoleIds( Collection<String> roleIds, Collection<String> groupIds, AttributeSet qualification ) { | 
  |  170 |    0 |                    Criteria c = new Criteria();  | 
  |  171 |    0 |                    if(roleIds!=null && !roleIds.isEmpty())  | 
  |  172 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds);  | 
  |  173 |    0 |                    if(groupIds!=null && !groupIds.isEmpty())  | 
  |  174 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds);  | 
  |  175 |    0 |                    c.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE );  | 
  |  176 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  177 |     | 
                     | 
  |  178 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  179 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  180 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  181 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  182 |    0 |                            if ( rm.isActive() ) { | 
  |  183 |    0 |                                    results.add(rm);  | 
  |  184 |     | 
                           }  | 
  |  185 |     | 
                   }  | 
  |  186 |    0 |                    return results;  | 
  |  187 |     | 
           }  | 
  |  188 |     | 
     | 
  |  189 |     | 
           @SuppressWarnings("unchecked") | 
  |  190 |     | 
           public Map<String,KimDelegationImpl> getDelegationImplMapFromRoleIds(Collection<String> roleIds) { | 
  |  191 |    0 |                    HashMap<String,KimDelegationImpl> results = new HashMap<String, KimDelegationImpl>();  | 
  |  192 |    0 |                    if ( roleIds != null && !roleIds.isEmpty() ) { | 
  |  193 |    0 |                            Criteria c = new Criteria();  | 
  |  194 |    0 |                            c.addIn(KIMPropertyConstants.Delegation.ROLE_ID, roleIds);  | 
  |  195 |    0 |                            c.addEqualTo(KIMPropertyConstants.Delegation.ACTIVE, Boolean.TRUE);  | 
  |  196 |    0 |                            Query query = QueryFactory.newQuery(KimDelegationImpl.class, c);  | 
  |  197 |    0 |                            Collection<KimDelegationImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  198 |    0 |                            for ( KimDelegationImpl dele : coll ) { | 
  |  199 |    0 |                                    results.put( dele.getDelegationId(), dele);  | 
  |  200 |     | 
                           }  | 
  |  201 |     | 
                   }  | 
  |  202 |    0 |                    return results;  | 
  |  203 |     | 
           }  | 
  |  204 |     | 
     | 
  |  205 |     | 
           @SuppressWarnings("unchecked") | 
  |  206 |     | 
           public List<KimDelegationImpl> getDelegationImplsForRoleIds(Collection<String> roleIds) { | 
  |  207 |    0 |                    List<KimDelegationImpl> results = new ArrayList<KimDelegationImpl>();  | 
  |  208 |    0 |                    if ( roleIds != null && !roleIds.isEmpty() ) { | 
  |  209 |    0 |                            Criteria c = new Criteria();  | 
  |  210 |    0 |                            c.addIn(KIMPropertyConstants.Delegation.ROLE_ID, roleIds);  | 
  |  211 |    0 |                            c.addEqualTo(KIMPropertyConstants.Delegation.ACTIVE, Boolean.TRUE);  | 
  |  212 |    0 |                            Query query = QueryFactory.newQuery(KimDelegationImpl.class, c);  | 
  |  213 |    0 |                            Collection<KimDelegationImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  214 |    0 |                            for ( KimDelegationImpl dele : coll ) { | 
  |  215 |    0 |                                    results.add(dele);  | 
  |  216 |     | 
                           }  | 
  |  217 |     | 
                   }  | 
  |  218 |    0 |                    return results;  | 
  |  219 |     | 
           }  | 
  |  220 |     | 
     | 
  |  221 |     | 
             | 
  |  222 |     | 
     | 
  |  223 |     | 
     | 
  |  224 |     | 
     | 
  |  225 |     | 
     | 
  |  226 |     | 
     | 
  |  227 |     | 
           @SuppressWarnings("unchecked") | 
  |  228 |     | 
           public List<KimDelegationMemberImpl> getDelegationPrincipalsForPrincipalIdAndDelegationIds(  | 
  |  229 |     | 
                           Collection<String> delegationIds, String principalId) { | 
  |  230 |    0 |                    Criteria c = new Criteria();  | 
  |  231 |     | 
     | 
  |  232 |    0 |                    if(principalId!=null)  | 
  |  233 |    0 |                            c.addEqualTo(KIMPropertyConstants.DelegationMember.MEMBER_ID, principalId);  | 
  |  234 |    0 |                    c.addEqualTo( KIMPropertyConstants.DelegationMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE );  | 
  |  235 |    0 |                    if(delegationIds!=null && !delegationIds.isEmpty())  | 
  |  236 |    0 |                            c.addIn(KIMPropertyConstants.DelegationMember.DELEGATION_ID, delegationIds);  | 
  |  237 |    0 |                    Query query = QueryFactory.newQuery(KimDelegationMemberImpl.class, c);  | 
  |  238 |    0 |                    Collection<KimDelegationMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  239 |    0 |                    ArrayList<KimDelegationMemberImpl> results = new ArrayList<KimDelegationMemberImpl>( coll.size() );  | 
  |  240 |    0 |                    for ( KimDelegationMemberImpl rm : coll ) { | 
  |  241 |    0 |                            if ( rm.isActive() ) { | 
  |  242 |    0 |                                    results.add(rm);  | 
  |  243 |     | 
                           }  | 
  |  244 |     | 
                   }  | 
  |  245 |    0 |                    return results;  | 
  |  246 |     | 
           }  | 
  |  247 |     | 
     | 
  |  248 |     | 
             | 
  |  249 |     | 
     | 
  |  250 |     | 
     | 
  |  251 |     | 
     | 
  |  252 |     | 
     | 
  |  253 |     | 
     | 
  |  254 |     | 
           @SuppressWarnings("unchecked") | 
  |  255 |     | 
           public List<KimDelegationMemberImpl> getDelegationGroupsForGroupIdsAndDelegationIds(  | 
  |  256 |     | 
                           Collection<String> delegationIds, List<String> groupIds) { | 
  |  257 |    0 |                    Criteria c = new Criteria();  | 
  |  258 |    0 |                    if(delegationIds!=null && !delegationIds.isEmpty())  | 
  |  259 |    0 |                            c.addIn(KIMPropertyConstants.DelegationMember.DELEGATION_ID, delegationIds);  | 
  |  260 |    0 |                    if(groupIds!=null && !groupIds.isEmpty())  | 
  |  261 |    0 |                            c.addIn(KIMPropertyConstants.DelegationMember.MEMBER_ID, groupIds);  | 
  |  262 |    0 |                    c.addEqualTo( KIMPropertyConstants.DelegationMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE );  | 
  |  263 |    0 |                    Query query = QueryFactory.newQuery(KimDelegationMemberImpl.class, c);  | 
  |  264 |    0 |                    Collection<KimDelegationMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  265 |    0 |                    ArrayList<KimDelegationMemberImpl> results = new ArrayList<KimDelegationMemberImpl>( coll.size() );  | 
  |  266 |    0 |                    for ( KimDelegationMemberImpl rm : coll ) { | 
  |  267 |    0 |                            if ( rm.isActive() ) { | 
  |  268 |    0 |                                    results.add(rm);  | 
  |  269 |     | 
                           }  | 
  |  270 |     | 
                   }  | 
  |  271 |    0 |                    return results;  | 
  |  272 |     | 
           }  | 
  |  273 |     | 
     | 
  |  274 |     | 
             | 
  |  275 |     | 
     | 
  |  276 |     | 
     | 
  |  277 |     | 
           @SuppressWarnings("unchecked") | 
  |  278 |     | 
           public List<RoleMemberImpl> getRoleMembersForRoleIds( Collection<String> roleIds, String memberTypeCode, AttributeSet qualification ) { | 
  |  279 |    0 |                    Criteria c = new Criteria();  | 
  |  280 |     | 
     | 
  |  281 |    0 |                    if(roleIds!=null && !roleIds.isEmpty())  | 
  |  282 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds);  | 
  |  283 |    0 |                    if ( memberTypeCode != null ) { | 
  |  284 |    0 |                            c.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, memberTypeCode );  | 
  |  285 |     | 
                   }  | 
  |  286 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  287 |     | 
                     | 
  |  288 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  289 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  290 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  291 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  292 |    0 |                            if ( rm.isActive() ) { | 
  |  293 |    0 |                                    results.add(rm);  | 
  |  294 |     | 
                           }  | 
  |  295 |     | 
                   }  | 
  |  296 |    0 |                    return results;  | 
  |  297 |     | 
           }  | 
  |  298 |     | 
     | 
  |  299 |     | 
             | 
  |  300 |     | 
     | 
  |  301 |     | 
     | 
  |  302 |     | 
           @SuppressWarnings("unchecked") | 
  |  303 |     | 
           public List<RoleMemberImpl> getRoleMembershipsForRoleIdsAsMembers( Collection<String> roleIds, AttributeSet qualification) { | 
  |  304 |    0 |                    Criteria c = new Criteria();  | 
  |  305 |     | 
     | 
  |  306 |    0 |                    if(roleIds!=null && !roleIds.isEmpty())  | 
  |  307 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, roleIds);  | 
  |  308 |    0 |                    c.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE);  | 
  |  309 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  310 |     | 
                     | 
  |  311 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  312 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  313 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  314 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  315 |    0 |                            if ( rm.isActive() ) { | 
  |  316 |    0 |                                    results.add(rm);  | 
  |  317 |     | 
                           }  | 
  |  318 |     | 
                   }  | 
  |  319 |    0 |                    return results;  | 
  |  320 |     | 
           }  | 
  |  321 |     | 
             | 
  |  322 |     | 
             | 
  |  323 |     | 
     | 
  |  324 |     | 
     | 
  |  325 |     | 
           @SuppressWarnings("unchecked") | 
  |  326 |     | 
           public List<RoleMemberImpl> getRoleMembershipsForMemberId(String memberType, String memberId, AttributeSet qualification) { | 
  |  327 |    0 |                    Criteria c = new Criteria();  | 
  |  328 |    0 |                    List<RoleMemberImpl> parentRoleMembers = new ArrayList<RoleMemberImpl>();  | 
  |  329 |     | 
     | 
  |  330 |    0 |                    if(StringUtils.isEmpty(memberId)  | 
  |  331 |     | 
                                   || StringUtils.isEmpty(memberType)) { | 
  |  332 |    0 |                            return parentRoleMembers;  | 
  |  333 |     | 
                   }  | 
  |  334 |     | 
                     | 
  |  335 |    0 |                    c.addEqualTo(KIMPropertyConstants.RoleMember.MEMBER_ID, memberId);  | 
  |  336 |    0 |                    c.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, memberType);  | 
  |  337 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  338 |     | 
                     | 
  |  339 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  340 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  341 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  342 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  343 |    0 |                            if ( rm.isActive() ) { | 
  |  344 |    0 |                                    results.add(rm);  | 
  |  345 |     | 
                           }  | 
  |  346 |     | 
                   }  | 
  |  347 |    0 |                    return results;  | 
  |  348 |     | 
           }  | 
  |  349 |     | 
     | 
  |  350 |     | 
           @SuppressWarnings("unchecked") | 
  |  351 |     | 
           public List<RoleMemberImpl> getRoleMembersForRoleIdsWithFilters( Collection<String> roleIds, String principalId, List<String> groupIds, AttributeSet qualification) { | 
  |  352 |    0 |                    Criteria c = new Criteria();  | 
  |  353 |     | 
     | 
  |  354 |    0 |                    if(roleIds!=null && !roleIds.isEmpty())  | 
  |  355 |    0 |                            c.addIn(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds);  | 
  |  356 |    0 |                    Criteria orSet = new Criteria();  | 
  |  357 |    0 |                    orSet.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.ROLE_MEMBER_TYPE );  | 
  |  358 |    0 |                    Criteria principalCheck = new Criteria();  | 
  |  359 |    0 |                    if(principalId!=null)  | 
  |  360 |    0 |                            principalCheck.addEqualTo(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId);  | 
  |  361 |    0 |                    principalCheck.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE );  | 
  |  362 |    0 |                    orSet.addOrCriteria( principalCheck );  | 
  |  363 |    0 |                    Criteria groupCheck = new Criteria();  | 
  |  364 |    0 |                    if(groupIds!=null && !groupIds.isEmpty())  | 
  |  365 |    0 |                            groupCheck.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds);  | 
  |  366 |    0 |                    groupCheck.addEqualTo( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE );  | 
  |  367 |    0 |                    orSet.addOrCriteria( groupCheck );  | 
  |  368 |    0 |                    c.addAndCriteria( orSet );  | 
  |  369 |    0 |                    addSubCriteriaBasedOnRoleQualification(c, qualification);  | 
  |  370 |     | 
                     | 
  |  371 |    0 |                    Query query = QueryFactory.newQuery(RoleMemberImpl.class, c);  | 
  |  372 |    0 |                    Collection<RoleMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  373 |    0 |                    ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() );  | 
  |  374 |    0 |                    for ( RoleMemberImpl rm : coll ) { | 
  |  375 |    0 |                            if ( rm.isActive() ) { | 
  |  376 |    0 |                                    results.add(rm);  | 
  |  377 |     | 
                           }  | 
  |  378 |     | 
                   }  | 
  |  379 |    0 |                    return results;  | 
  |  380 |     | 
           }  | 
  |  381 |     | 
     | 
  |  382 |     | 
             | 
  |  383 |     | 
     | 
  |  384 |     | 
     | 
  |  385 |     | 
           @SuppressWarnings("unchecked") | 
  |  386 |     | 
           public Map<String,List<KimDelegationMemberImpl>> getDelegationMembersForDelegationIds(  | 
  |  387 |     | 
                           List<String> delegationIds) { | 
  |  388 |    0 |                    Criteria c = new Criteria();  | 
  |  389 |    0 |                    if(delegationIds!=null && !delegationIds.isEmpty())  | 
  |  390 |    0 |                            c.addIn(KIMPropertyConstants.DelegationMember.DELEGATION_ID, delegationIds);  | 
  |  391 |    0 |                    Query query = QueryFactory.newQuery(KimDelegationMemberImpl.class, c);  | 
  |  392 |    0 |                    Collection<KimDelegationMemberImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query);  | 
  |  393 |    0 |                    HashMap<String,List<KimDelegationMemberImpl>> result = new HashMap<String,List<KimDelegationMemberImpl>>();  | 
  |  394 |    0 |                    for ( KimDelegationMemberImpl dp : coll ) { | 
  |  395 |    0 |                            if ( dp.isActive() ) { | 
  |  396 |    0 |                                    if ( !result.containsKey( dp.getDelegationId() ) ) { | 
  |  397 |    0 |                                            result.put( dp.getDelegationId(), new ArrayList<KimDelegationMemberImpl>() );  | 
  |  398 |     | 
                                   }  | 
  |  399 |    0 |                                    result.get( dp.getDelegationId() ).add( dp );  | 
  |  400 |     | 
                           }  | 
  |  401 |     | 
                   }  | 
  |  402 |    0 |                    return result;  | 
  |  403 |     | 
           }  | 
  |  404 |     | 
     | 
  |  405 |     | 
       public List<RoleImpl> getRoles(Map<String,String> fieldValues) { | 
  |  406 |    0 |            Criteria crit = new Criteria();  | 
  |  407 |    0 |            Map<String,Map<String,String>> critMap = setupCritMaps(fieldValues);  | 
  |  408 |     | 
     | 
  |  409 |     | 
     | 
  |  410 |     | 
     | 
  |  411 |    0 |            Map<String,String> lookupNames = critMap.get("lookupNames"); | 
  |  412 |    0 |            for (Entry<String, String> entry : lookupNames.entrySet()) { | 
  |  413 |    0 |                    if (StringUtils.isNotBlank(entry.getValue())) { | 
  |  414 |    0 |                                    if (!entry.getKey().equals(KIMPropertyConstants.Principal.PRINCIPAL_NAME)) { | 
  |  415 |    0 |                                            addLikeToCriteria(crit, entry.getKey(), entry.getValue());  | 
  |  416 |     | 
                                   } else { | 
  |  417 |    0 |                                                    List roleIds = getRoleIdsForPrincipalName(entry.getValue());  | 
  |  418 |    0 |                                            if (roleIds!=null && !roleIds.isEmpty()) { | 
  |  419 |    0 |                                                    crit.addIn(KIMPropertyConstants.Role.ROLE_ID, roleIds);  | 
  |  420 |     | 
                                           } else { | 
  |  421 |     | 
                                             | 
  |  422 |    0 |                                                    roleIds.add("NOTFOUND"); | 
  |  423 |    0 |                                                    crit.addIn(KIMPropertyConstants.Role.ROLE_ID, roleIds);  | 
  |  424 |     | 
                                           }  | 
  |  425 |    0 |                            }  | 
  |  426 |     | 
                   }  | 
  |  427 |     | 
           }  | 
  |  428 |    0 |                    if (!critMap.get("attr").isEmpty()) { | 
  |  429 |    0 |                        String kimTypeId=null;  | 
  |  430 |    0 |                    for (Map.Entry<String,String> entry : fieldValues.entrySet()) { | 
  |  431 |    0 |                            if (entry.getKey().equals("kimTypeId")) { | 
  |  432 |    0 |                                    kimTypeId=entry.getValue();  | 
  |  433 |    0 |                                    break;  | 
  |  434 |     | 
                           }  | 
  |  435 |     | 
                   }  | 
  |  436 |    0 |                            setupAttrCriteria(crit, critMap.get("attr"),kimTypeId); | 
  |  437 |     | 
                   }  | 
  |  438 |    0 |                    if (!critMap.get("perm").isEmpty()) { | 
  |  439 |    0 |                            crit.addExists(setupPermCriteria(critMap.get("perm"))); | 
  |  440 |     | 
                   }  | 
  |  441 |    0 |                    if (!critMap.get("resp").isEmpty()) { | 
  |  442 |    0 |                            crit.addExists(setupRespCriteria(critMap.get("resp"))); | 
  |  443 |     | 
                   }  | 
  |  444 |    0 |                    if (!critMap.get("group").isEmpty()) { | 
  |  445 |    0 |                            crit.addExists(setupGroupCriteria(critMap.get("group"))); | 
  |  446 |     | 
                   }  | 
  |  447 |     | 
     | 
  |  448 |    0 |            Query q = QueryFactory.newQuery(RoleImpl.class, crit);  | 
  |  449 |     | 
     | 
  |  450 |    0 |            return (List)getPersistenceBrokerTemplate().getCollectionByQuery(q);  | 
  |  451 |     | 
       }  | 
  |  452 |     | 
     | 
  |  453 |     | 
         | 
  |  454 |     | 
       private List<String> getPrincipalIdsForPrincipalName(String principalName){ | 
  |  455 |    0 |                Map<String, String> criteria = new HashMap<String, String>();  | 
  |  456 |    0 |            criteria.put("principals.principalName", principalName); | 
  |  457 |    0 |            List<? extends KimEntityDefaultInfo> entities = KIMServiceLocator.getIdentityService().lookupEntityDefaultInfo(criteria, false);  | 
  |  458 |     | 
     | 
  |  459 |    0 |            List<String> principalIds = new ArrayList<String>();  | 
  |  460 |    0 |            for (KimEntityDefaultInfo entity : entities) { | 
  |  461 |    0 |                for (KimPrincipal principal : entity.getPrincipals()) { | 
  |  462 |    0 |                    principalIds.add(principal.getPrincipalId());  | 
  |  463 |     | 
               }  | 
  |  464 |     | 
           }  | 
  |  465 |     | 
     | 
  |  466 |    0 |            return principalIds;  | 
  |  467 |     | 
     | 
  |  468 |     | 
       }  | 
  |  469 |     | 
     | 
  |  470 |     | 
       private List<String> getRoleIdsForPrincipalName(String value) { | 
  |  471 |    0 |                String principalName = value.replace('*', '%'); | 
  |  472 |    0 |                    List<String> roleIds = new ArrayList<String>();  | 
  |  473 |    0 |                    Criteria memberSubCrit = new Criteria();  | 
  |  474 |    0 |            Map<String, String> criteria = new HashMap<String, String>();  | 
  |  475 |    0 |            criteria.put("principals.principalName", principalName); | 
  |  476 |    0 |            List<? extends KimEntityDefaultInfo> entities = KIMServiceLocator.getIdentityService().lookupEntityDefaultInfo(criteria, false);  | 
  |  477 |    0 |            if (entities == null  | 
  |  478 |     | 
                   || entities.size() == 0) { | 
  |  479 |    0 |                return roleIds;  | 
  |  480 |     | 
           }  | 
  |  481 |     | 
     | 
  |  482 |    0 |            List<String> principalIds = new ArrayList<String>();  | 
  |  483 |    0 |            for (KimEntityDefaultInfo entity : entities) { | 
  |  484 |    0 |                for (KimPrincipal principal : entity.getPrincipals()) { | 
  |  485 |    0 |                    principalIds.add(principal.getPrincipalId());  | 
  |  486 |     | 
               }  | 
  |  487 |     | 
           }  | 
  |  488 |    0 |            if(principalIds!=null && !principalIds.isEmpty()){ | 
  |  489 |    0 |                    memberSubCrit.addEqualTo(KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE);  | 
  |  490 |    0 |                    memberSubCrit.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, principalIds);  | 
  |  491 |     | 
     | 
  |  492 |    0 |                            ReportQueryByCriteria memberSubQuery = QueryFactory.newReportQuery(RoleMemberImpl.class, memberSubCrit);  | 
  |  493 |    0 |                            for (RoleMemberImpl roleMbr : (List<RoleMemberImpl>)getPersistenceBrokerTemplate().getCollectionByQuery(memberSubQuery)) { | 
  |  494 |    0 |                                    if (roleMbr.isActive() && !roleIds.contains(roleMbr.getRoleId())) { | 
  |  495 |    0 |                                            roleIds.add(roleMbr.getRoleId());  | 
  |  496 |     | 
                                   }  | 
  |  497 |     | 
                           }  | 
  |  498 |     | 
           }  | 
  |  499 |     | 
     | 
  |  500 |    0 |                    List<String> groupIds = new ArrayList<String>();  | 
  |  501 |    0 |                    for (String principalId : principalIds) { | 
  |  502 |    0 |                        List<String> principalGroupIds = KIMServiceLocator.getGroupService().getGroupIdsForPrincipal(principalId);  | 
  |  503 |    0 |                        for (String groupId : principalGroupIds) { | 
  |  504 |    0 |                            if (!groupIds.contains(groupId)) { | 
  |  505 |    0 |                                groupIds.add(groupId);  | 
  |  506 |     | 
                           }  | 
  |  507 |     | 
                       }  | 
  |  508 |    0 |                    }  | 
  |  509 |     | 
     | 
  |  510 |    0 |            if(groupIds!=null && !groupIds.isEmpty()){ | 
  |  511 |    0 |                    Criteria grpRoleCrit = new Criteria();  | 
  |  512 |    0 |                    grpRoleCrit.addEqualTo(KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE);  | 
  |  513 |    0 |                    grpRoleCrit.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds);  | 
  |  514 |     | 
     | 
  |  515 |    0 |                    ReportQueryByCriteria memberSubQuery = QueryFactory.newReportQuery(RoleMemberImpl.class, grpRoleCrit);  | 
  |  516 |     | 
     | 
  |  517 |    0 |                            for (RoleMemberImpl roleMbr : (List<RoleMemberImpl>)getPersistenceBrokerTemplate().getCollectionByQuery(memberSubQuery)) { | 
  |  518 |    0 |                                    if (roleMbr.isActive() && !roleIds.contains(roleMbr.getRoleId()) ) { | 
  |  519 |    0 |                                            roleIds.add(roleMbr.getRoleId());  | 
  |  520 |     | 
                                   }  | 
  |  521 |     | 
                           }  | 
  |  522 |     | 
           }  | 
  |  523 |     | 
     | 
  |  524 |    0 |                return roleIds;  | 
  |  525 |     | 
       }  | 
  |  526 |     | 
     | 
  |  527 |     | 
       private Map setupCritMaps(Map<String,String> fieldValues) { | 
  |  528 |    0 |                Map <String, Map> critMap = new HashMap();  | 
  |  529 |    0 |            List permFieldName = new ArrayList();  | 
  |  530 |    0 |            permFieldName.add("permName"); | 
  |  531 |    0 |            permFieldName.add("permNamespaceCode"); | 
  |  532 |    0 |            permFieldName.add("permTmplName"); | 
  |  533 |    0 |            permFieldName.add("permTmplNamespaceCode"); | 
  |  534 |    0 |            List respFieldName = new ArrayList();  | 
  |  535 |    0 |            respFieldName.add("respName"); | 
  |  536 |    0 |            respFieldName.add("respNamespaceCode"); | 
  |  537 |    0 |            respFieldName.add("respTmplName"); | 
  |  538 |    0 |            respFieldName.add("respTmplNamespaceCode"); | 
  |  539 |    0 |            Map<String,String> permFieldMap = new HashMap<String,String>();  | 
  |  540 |    0 |            Map<String,String> respFieldMap = new HashMap<String,String>();  | 
  |  541 |    0 |            Map<String,String> attrFieldMap = new HashMap<String,String>();  | 
  |  542 |    0 |            Map<String,String> groupFieldMap = new HashMap<String,String>();  | 
  |  543 |    0 |            Map<String,String> lookupNamesMap = new HashMap<String,String>();  | 
  |  544 |     | 
     | 
  |  545 |    0 |            for (Entry<String, String> entry : fieldValues.entrySet()) { | 
  |  546 |    0 |                    if (StringUtils.isNotBlank(entry.getValue())) { | 
  |  547 |    0 |                                String nameValue = entry.getValue().replace('*', '%'); | 
  |  548 |    0 |                            if (permFieldName.contains(entry.getKey())) { | 
  |  549 |    0 |                                    permFieldMap.put(entry.getKey(), nameValue);  | 
  |  550 |    0 |                            } else if (respFieldName.contains(entry.getKey())) { | 
  |  551 |    0 |                                    respFieldMap.put(entry.getKey(), nameValue);  | 
  |  552 |    0 |                            } else if (entry.getKey().startsWith(KimConstants.AttributeConstants.GROUP_NAME)) { | 
  |  553 |    0 |                                    groupFieldMap.put(entry.getKey(), nameValue);  | 
  |  554 |    0 |                            } else if (entry.getKey().contains(".")) { | 
  |  555 |    0 |                                    attrFieldMap.put(entry.getKey(), nameValue);  | 
  |  556 |     | 
                           } else { | 
  |  557 |    0 |                                    lookupNamesMap.put(entry.getKey(), nameValue);  | 
  |  558 |     | 
                           }  | 
  |  559 |    0 |                    }  | 
  |  560 |     | 
           }  | 
  |  561 |     | 
     | 
  |  562 |    0 |            critMap.put("perm", permFieldMap); | 
  |  563 |    0 |            critMap.put("resp", respFieldMap); | 
  |  564 |    0 |            critMap.put("group", groupFieldMap); | 
  |  565 |    0 |            critMap.put("attr", attrFieldMap); | 
  |  566 |    0 |            critMap.put("lookupNames", lookupNamesMap); | 
  |  567 |    0 |            return critMap;  | 
  |  568 |     | 
       }  | 
  |  569 |     | 
     | 
  |  570 |     | 
     | 
  |  571 |     | 
       private void setupAttrCriteria(Criteria crit, Map<String,String> attrCrit, String kimTypeId) { | 
  |  572 |    0 |            for (Entry<String, String> entry : attrCrit.entrySet()) { | 
  |  573 |    0 |                            Criteria subCrit = new Criteria();  | 
  |  574 |    0 |                            addLikeToCriteria(subCrit, "attributes.attributeValue",entry.getValue());  | 
  |  575 |    0 |                            addEqualToCriteria(subCrit, "attributes.kimAttributeId",entry.getKey().substring(entry.getKey().indexOf(".")+1, entry.getKey().length())); | 
  |  576 |    0 |                            addEqualToCriteria(subCrit, "attributes.kimTypeId", kimTypeId);  | 
  |  577 |    0 |                            subCrit.addEqualToField("roleId", Criteria.PARENT_QUERY_PREFIX + "roleId"); | 
  |  578 |    0 |                            crit.addExists(QueryFactory.newReportQuery(RoleMemberImpl.class, subCrit));  | 
  |  579 |    0 |            }  | 
  |  580 |    0 |        }  | 
  |  581 |     | 
     | 
  |  582 |     | 
       private ReportQueryByCriteria setupPermCriteria(Map<String,String> permCrit) { | 
  |  583 |     | 
     | 
  |  584 |    0 |                Map<String,String> searchCrit = new HashMap<String, String>();  | 
  |  585 |     | 
     | 
  |  586 |    0 |            for (Entry<String, String> entry : permCrit.entrySet()) { | 
  |  587 |    0 |                    if (entry.getKey().equals("permTmplName") || entry.getKey().equals("permTmplNamespaceCode")) { | 
  |  588 |    0 |                            if (entry.getKey().equals("permTmplName")) { | 
  |  589 |    0 |                                    searchCrit.put("template." + KimConstants.UniqueKeyConstants.PERMISSION_TEMPLATE_NAME,entry.getValue()); | 
  |  590 |     | 
     | 
  |  591 |     | 
                           } else { | 
  |  592 |    0 |                                    searchCrit.put("template." + KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); | 
  |  593 |     | 
                           }  | 
  |  594 |     | 
                   }  | 
  |  595 |     | 
     | 
  |  596 |    0 |                    if (entry.getKey().equals("permName") || entry.getKey().equals("permNamespaceCode")) { | 
  |  597 |    0 |                            if (entry.getKey().equals("permName")) { | 
  |  598 |    0 |                                    searchCrit.put(KimConstants.UniqueKeyConstants.PERMISSION_NAME, entry.getValue());  | 
  |  599 |     | 
                           } else { | 
  |  600 |    0 |                                    searchCrit.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue());  | 
  |  601 |     | 
     | 
  |  602 |     | 
                           }  | 
  |  603 |     | 
                   }  | 
  |  604 |     | 
           }  | 
  |  605 |     | 
     | 
  |  606 |    0 |            List<KimPermissionInfo> permList = KIMServiceLocator.getPermissionService().lookupPermissions(searchCrit, true);  | 
  |  607 |    0 |            List<String> roleIds = null;  | 
  |  608 |     | 
     | 
  |  609 |    0 |            if(permList != null && !permList.isEmpty()){ | 
  |  610 |    0 |                    roleIds = KIMServiceLocator.getPermissionService().getRoleIdsForPermissions(permList);  | 
  |  611 |     | 
           }  | 
  |  612 |     | 
     | 
  |  613 |    0 |            if(roleIds == null || roleIds.isEmpty()){ | 
  |  614 |    0 |                    roleIds = new ArrayList<String>();  | 
  |  615 |    0 |                    roleIds.add("-1");  | 
  |  616 |     | 
           }  | 
  |  617 |     | 
     | 
  |  618 |    0 |            Criteria memberSubCrit = new Criteria();  | 
  |  619 |    0 |            memberSubCrit.addIn("roleId", roleIds); | 
  |  620 |    0 |            memberSubCrit.addEqualToField("roleId", Criteria.PARENT_QUERY_PREFIX + "roleId"); | 
  |  621 |    0 |                    return QueryFactory.newReportQuery(RoleImpl.class, memberSubCrit);  | 
  |  622 |     | 
     | 
  |  623 |     | 
       }  | 
  |  624 |     | 
     | 
  |  625 |     | 
       private ReportQueryByCriteria setupRespCriteria(Map<String,String> respCrit) { | 
  |  626 |     | 
     | 
  |  627 |     | 
               try{ | 
  |  628 |     | 
                 | 
  |  629 |     | 
               }catch(Exception ex){ | 
  |  630 |     | 
                       ex.printStackTrace();  | 
  |  631 |    0 |                }  | 
  |  632 |    0 |                Map<String,String> searchCrit = new HashMap<String, String>();  | 
  |  633 |     | 
     | 
  |  634 |    0 |            for (Entry<String, String> entry : respCrit.entrySet()) { | 
  |  635 |    0 |                    if (entry.getKey().equals("respTmplName") || entry.getKey().equals("respTmplNamespaceCode")) { | 
  |  636 |    0 |                            if (entry.getKey().equals("respTmplName")) { | 
  |  637 |    0 |                                    searchCrit.put("template." + KimConstants.UniqueKeyConstants.RESPONSIBILITY_TEMPLATE_NAME,entry.getValue()); | 
  |  638 |     | 
     | 
  |  639 |     | 
                           } else { | 
  |  640 |    0 |                                    searchCrit.put("template." + KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); | 
  |  641 |     | 
                           }  | 
  |  642 |     | 
                   }  | 
  |  643 |     | 
     | 
  |  644 |    0 |                    if (entry.getKey().equals("respName") || entry.getKey().equals("respNamespaceCode")) { | 
  |  645 |    0 |                            if (entry.getKey().equals("respName")) { | 
  |  646 |    0 |                                    searchCrit.put(KimConstants.UniqueKeyConstants.RESPONSIBILITY_NAME, entry.getValue());  | 
  |  647 |     | 
                           } else { | 
  |  648 |    0 |                                    searchCrit.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue());  | 
  |  649 |     | 
     | 
  |  650 |     | 
                           }  | 
  |  651 |     | 
                   }  | 
  |  652 |     | 
           }  | 
  |  653 |     | 
     | 
  |  654 |    0 |            List<? extends KimResponsibilityInfo> kriList = KIMServiceLocator.getResponsibilityService().lookupResponsibilityInfo(searchCrit, true);  | 
  |  655 |    0 |            List<String> roleIds = new ArrayList<String>();  | 
  |  656 |     | 
     | 
  |  657 |    0 |            for(KimResponsibilityInfo kri : kriList){ | 
  |  658 |    0 |                    roleIds.addAll(KIMServiceLocator.getResponsibilityService().getRoleIdsForResponsibility(kri, null));  | 
  |  659 |     | 
           }  | 
  |  660 |     | 
     | 
  |  661 |    0 |            if(roleIds == null || roleIds.isEmpty()){ | 
  |  662 |    0 |                    roleIds = new ArrayList<String>();  | 
  |  663 |    0 |                    roleIds.add("-1");  | 
  |  664 |     | 
           }  | 
  |  665 |     | 
     | 
  |  666 |    0 |            Criteria memberSubCrit = new Criteria();  | 
  |  667 |    0 |            memberSubCrit.addIn("roleId", roleIds); | 
  |  668 |    0 |            memberSubCrit.addEqualToField("roleId", Criteria.PARENT_QUERY_PREFIX + "roleId"); | 
  |  669 |    0 |                    return QueryFactory.newReportQuery(RoleImpl.class, memberSubCrit);  | 
  |  670 |     | 
     | 
  |  671 |     | 
       }  | 
  |  672 |     | 
     | 
  |  673 |     | 
       private ReportQueryByCriteria setupGroupCriteria(Map<String,String> groupCrit) { | 
  |  674 |     | 
     | 
  |  675 |    0 |                Map<String,String> searchCrit = new HashMap<String, String>();  | 
  |  676 |    0 |            for (Entry<String, String> entry : groupCrit.entrySet()) { | 
  |  677 |    0 |                            if (entry.getKey().equals(KimConstants.AttributeConstants.GROUP_NAME)) { | 
  |  678 |    0 |                                    searchCrit.put(entry.getKey(), entry.getValue());  | 
  |  679 |     | 
                           } else {  | 
  |  680 |    0 |                                    searchCrit.put(KimConstants.AttributeConstants.NAMESPACE_CODE, entry.getValue());  | 
  |  681 |     | 
                           }  | 
  |  682 |     | 
           }  | 
  |  683 |     | 
     | 
  |  684 |    0 |            Criteria crit = new Criteria();  | 
  |  685 |     | 
     | 
  |  686 |    0 |            List<String> groupIds = KIMServiceLocator.getGroupService().lookupGroupIds(searchCrit);  | 
  |  687 |     | 
     | 
  |  688 |    0 |            if(groupIds == null || groupIds.isEmpty()){ | 
  |  689 |    0 |                    groupIds = new ArrayList<String>();  | 
  |  690 |    0 |                    groupIds.add("-1");   | 
  |  691 |     | 
           }  | 
  |  692 |    0 |            crit.addIn("memberId", groupIds); | 
  |  693 |    0 |            crit.addEqualToField("roleId", Criteria.PARENT_QUERY_PREFIX + "roleId"); | 
  |  694 |     | 
     | 
  |  695 |    0 |                    return QueryFactory.newReportQuery(RoleMemberImpl.class, crit);  | 
  |  696 |     | 
     | 
  |  697 |     | 
       }  | 
  |  698 |     | 
     | 
  |  699 |     | 
       private void addLikeToCriteria(Criteria criteria, String propertyName, String propertyValue){ | 
  |  700 |    0 |                String[] keyValues = getCaseInsensitiveValues(propertyName, propertyValue);  | 
  |  701 |    0 |                       criteria.addLike(keyValues[0], keyValues[1]);  | 
  |  702 |    0 |        }  | 
  |  703 |     | 
     | 
  |  704 |     | 
       private void addEqualToCriteria(Criteria criteria, String propertyName, String propertyValue){ | 
  |  705 |    0 |                String[] keyValues = getCaseInsensitiveValues(propertyName, propertyValue);  | 
  |  706 |    0 |                       criteria.addEqualTo(keyValues[0], keyValues[1]);  | 
  |  707 |    0 |        }  | 
  |  708 |     | 
     | 
  |  709 |     | 
       private String[] getCaseInsensitiveValues(String propertyName, String propertyValue){ | 
  |  710 |    0 |                String[] keyValues = new String[2];  | 
  |  711 |    0 |                keyValues[0] = propertyName==null?"":getDbPlatform().getUpperCaseFunction() + "(" + propertyName + ")"; | 
  |  712 |    0 |                keyValues[1] = propertyValue==null?"":propertyValue.toUpperCase();  | 
  |  713 |    0 |                return keyValues;  | 
  |  714 |     | 
       }  | 
  |  715 |     | 
     | 
  |  716 |     | 
       @SuppressWarnings("unchecked") | 
  |  717 |     | 
           protected List<RoleMemberImpl> getRoleMemberImpls(Map<String, String> fieldValues){ | 
  |  718 |    0 |                    Criteria queryCriteria = new Criteria();  | 
  |  719 |    0 |                    List<String> memberIds = new ArrayList<String>();  | 
  |  720 |    0 |                    if(hasExtraRoleMemberCriteria(fieldValues)){ | 
  |  721 |    0 |                            String memberName = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME);  | 
  |  722 |    0 |                            String memberNamespaceCode = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE);  | 
  |  723 |     | 
                             | 
  |  724 |     | 
                             | 
  |  725 |    0 |                            List<RoleImpl> roles = getRoleMembersRoles(memberNamespaceCode, memberName);  | 
  |  726 |    0 |                            if(roles!=null){ | 
  |  727 |    0 |                                    for(RoleImpl role: roles)  | 
  |  728 |    0 |                                            memberIds.add(role.getRoleId());  | 
  |  729 |     | 
                           }  | 
  |  730 |     | 
     | 
  |  731 |    0 |                            memberIds.addAll(this.getPrincipalIdsForPrincipalName(memberName));  | 
  |  732 |     | 
     | 
  |  733 |    0 |                            memberIds.addAll(getRoleMembersGroupIds(memberNamespaceCode, memberName));  | 
  |  734 |     | 
     | 
  |  735 |    0 |                    if(memberIds!=null && !memberIds.isEmpty())  | 
  |  736 |    0 |                            queryCriteria.addIn(KIMPropertyConstants.RoleMember.MEMBER_ID, memberIds);  | 
  |  737 |     | 
                   }  | 
  |  738 |    0 |                    if(hasCoreRoleMemberCriteria(fieldValues)){ | 
  |  739 |    0 |                        String roleMemberId = fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID);  | 
  |  740 |    0 |                            String roleId = fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID);  | 
  |  741 |    0 |                            String memberId = fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID);  | 
  |  742 |    0 |                            String memberTypeCode = fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE);  | 
  |  743 |    0 |                            String activeFromDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE);  | 
  |  744 |    0 |                            String activeToDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE);  | 
  |  745 |     | 
                             | 
  |  746 |    0 |                            if(StringUtils.isNotEmpty(roleMemberId))  | 
  |  747 |    0 |                                    addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId);  | 
  |  748 |    0 |                            if(StringUtils.isNotEmpty(roleId))  | 
  |  749 |    0 |                                    addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.ROLE_ID, roleId);  | 
  |  750 |    0 |                            if(StringUtils.isNotEmpty(memberId))  | 
  |  751 |    0 |                                    addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.MEMBER_ID, memberId);  | 
  |  752 |    0 |                            if(StringUtils.isNotEmpty(memberTypeCode))  | 
  |  753 |    0 |                                    addEqualToCriteria(queryCriteria, KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE, memberTypeCode);  | 
  |  754 |    0 |                            if(StringUtils.isNotEmpty(activeFromDate))  | 
  |  755 |    0 |                                    queryCriteria.addGreaterOrEqualThan(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE, activeFromDate);  | 
  |  756 |    0 |                            if(StringUtils.isNotEmpty(activeToDate))  | 
  |  757 |    0 |                                    queryCriteria.addLessOrEqualThan(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE, activeToDate);  | 
  |  758 |     | 
                   }  | 
  |  759 |    0 |            Query q = QueryFactory.newQuery(RoleMemberImpl.class, queryCriteria);  | 
  |  760 |    0 |            return (List<RoleMemberImpl>)getPersistenceBrokerTemplate().getCollectionByQuery(q);  | 
  |  761 |     | 
       }  | 
  |  762 |     | 
     | 
  |  763 |     | 
       public List<RoleMembershipInfo> getRoleMembers(Map<String,String> fieldValues) { | 
  |  764 |    0 |                List<RoleMemberImpl> roleMembers = getRoleMemberImpls(fieldValues);  | 
  |  765 |    0 |            List<RoleMembershipInfo> roleMemberships = new ArrayList<RoleMembershipInfo>();  | 
  |  766 |     | 
           RoleMembershipInfo roleMembership;  | 
  |  767 |    0 |            for(RoleMemberImpl roleMember: roleMembers){ | 
  |  768 |    0 |                    roleMembership = new RoleMembershipInfo(roleMember.getRoleId(), roleMember.getRoleMemberId(), roleMember.getMemberId(), roleMember.getMemberTypeCode(), roleMember.getQualifier() );  | 
  |  769 |    0 |                    roleMemberships.add(roleMembership);  | 
  |  770 |     | 
           }  | 
  |  771 |    0 |            return roleMemberships;  | 
  |  772 |     | 
       }  | 
  |  773 |     | 
     | 
  |  774 |     | 
       public List<RoleMemberCompleteInfo> getRoleMembersCompleteInfo(Map<String,String> fieldValues) { | 
  |  775 |    0 |                List<RoleMemberImpl> roleMembers = getRoleMemberImpls(fieldValues);  | 
  |  776 |    0 |            List<RoleMemberCompleteInfo> roleMembersCompleteInfo = new ArrayList<RoleMemberCompleteInfo>();  | 
  |  777 |     | 
           RoleMemberCompleteInfo roleMemberCompleteInfo;  | 
  |  778 |    0 |            for(RoleMemberImpl roleMember: roleMembers){ | 
  |  779 |    0 |                    roleMemberCompleteInfo = new RoleMemberCompleteInfo(  | 
  |  780 |     | 
                                   roleMember.getRoleId(), roleMember.getRoleMemberId(), roleMember.getMemberId(),  | 
  |  781 |     | 
                                   roleMember.getMemberTypeCode(), roleMember.getActiveFromDate(), roleMember.getActiveToDate(),  | 
  |  782 |     | 
                                   roleMember.getQualifier() );  | 
  |  783 |    0 |                    roleMembersCompleteInfo.add(roleMemberCompleteInfo);  | 
  |  784 |     | 
           }  | 
  |  785 |    0 |            return roleMembersCompleteInfo;  | 
  |  786 |     | 
       }  | 
  |  787 |     | 
     | 
  |  788 |     | 
       private boolean hasCoreRoleMemberCriteria(Map<String, String> fieldValues){ | 
  |  789 |    0 |                    return StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID)) ||  | 
  |  790 |     | 
                                   StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID)) ||  | 
  |  791 |     | 
                                   StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID)) ||  | 
  |  792 |     | 
                                   StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE)) ||  | 
  |  793 |     | 
                                   StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE)) ||  | 
  |  794 |     | 
                                   StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE));  | 
  |  795 |     | 
       }  | 
  |  796 |     | 
     | 
  |  797 |     | 
       private boolean hasExtraRoleMemberCriteria(Map<String, String> fieldValues){ | 
  |  798 |    0 |                return StringUtils.isNotEmpty(fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME)) ||  | 
  |  799 |     | 
                               StringUtils.isNotEmpty(fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE));  | 
  |  800 |     | 
       }  | 
  |  801 |     | 
     | 
  |  802 |     | 
       @SuppressWarnings("unchecked") | 
  |  803 |     | 
           private List<RoleImpl> getRoleMembersRoles(String memberNamespaceCode, String memberName){ | 
  |  804 |    0 |                    Criteria queryCriteria = new Criteria();  | 
  |  805 |    0 |                    addEqualToCriteria(queryCriteria, KimConstants.UniqueKeyConstants.NAMESPACE_CODE, memberNamespaceCode);  | 
  |  806 |    0 |                    addEqualToCriteria(queryCriteria, KimConstants.UniqueKeyConstants.ROLE_NAME, memberName);  | 
  |  807 |    0 |                    Query q = QueryFactory.newQuery(RoleImpl.class, queryCriteria);  | 
  |  808 |    0 |                    return (List<RoleImpl>)getPersistenceBrokerTemplate().getCollectionByQuery(q);  | 
  |  809 |     | 
       }  | 
  |  810 |     | 
     | 
  |  811 |     | 
       private List<String> getRoleMembersGroupIds(String memberNamespaceCode, String memberName){ | 
  |  812 |     | 
     | 
  |  813 |    0 |                Map<String,String> searchCrit = new HashMap<String, String>();  | 
  |  814 |    0 |                searchCrit.put(KimConstants.AttributeConstants.GROUP_NAME, memberName);  | 
  |  815 |    0 |                searchCrit.put(KimConstants.AttributeConstants.NAMESPACE_CODE, memberNamespaceCode);  | 
  |  816 |     | 
     | 
  |  817 |    0 |                return KIMServiceLocator.getGroupService().lookupGroupIds(searchCrit);  | 
  |  818 |     | 
       }  | 
  |  819 |     | 
   }  |