2 Replies Latest reply: Jan 21, 2013 5:39 AM by 958133 RSS

    OIM11gR2 Searching Role keys from role names

    958133
      Hi Experts,

      I have roles coming in String format "Role1,Role2,Role3",

      I want to fetch their role keys: I am using search criteria function as
      criteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME,"Role1", SearchCriteria.Operator.EQUAL);
      attrNames.add(RoleManagerConstants.ROLE_KEY);
      roles = rmgr.search(criteria, attrNames, null);
      In the above code i have to iterate for each and every role one by one.


      Here if I want to use a single search criteria where i could pass this as a single string like
      criteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME,"Role1,Role2,Role3", SearchCriteria.Operator.IN);
      Is it possible? I am trying with IN operator, but it is giving outofbound exception.
      Any Thougths?
        • 1. Re: OIM11gR2 Searching Role keys from role names
          idamGod
          This code should resolve your issue

          private void SearchRoles(String RoleName1,String RoleName2,String RoleName3) {
          List<Role> roles = null;
          HashMap<String, Object> mapParams = null;
          Set<String> attrNames = null;
          RoleManager roleMgr = oimClient.getService(RoleManager.class);

          SearchCriteria searchCriteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME, RoleName1, SearchCriteria.Operator.EQUAL);
          SearchCriteria searchCriteria1 = new SearchCriteria(RoleManagerConstants.ROLE_NAME, RoleName2, SearchCriteria.Operator.EQUAL);
          SearchCriteria searchCriteria2 = new SearchCriteria(searchCriteria, searchCriteria1, SearchCriteria.Operator.OR);
          SearchCriteria searchCriteria3 = new SearchCriteria(RoleManagerConstants.ROLE_NAME,RoleName3, SearchCriteria.Operator.EQUAL);
          SearchCriteria searchCriteria4 = new SearchCriteria(searchCriteria2,searchCriteria3, SearchCriteria.Operator.OR);

          try
          {
          roles = roleMgr.search(searchCriteria4, attrNames, mapParams);

          System.out.println("Total Roles found:"+roles.size());

          for (Role role : roles)
          {

          System.out.println(role.getEntityId()+":"+role.getName()+":"+role.getDisplayName()+":"+role.getNamespace());
          }
          }
          catch(Exception e) {
          e.printStackTrace();
          }
          }
          • 2. Re: OIM11gR2 Searching Role keys from role names
            958133
            Thanks for replying,,
            I put all the role values in a set like
            Set<string> mapRoleNames= new Hashset ();
            mapRoleNames.put("Role1");
            mapRoleNames.put("Role2");
            criteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME,mapRoleNames, SearchCriteria.Operator.IN);
            this worked for me.