2 Replies Latest reply: May 25, 2013 11:43 PM by 942393 RSS

    Code to searh multiple roles

    942393
      I am trying to use IN operator to search for a more than one role but not successful.

      Can you please provide some sample code snippet to search for multiple roles using IN operator in the search criteria.
        • 1. Re: Code to searh multiple roles
          idamGod
          Try the below code.

          private void searchroles(String role1,String role2, String role3) {
          Set<String> mapRoleNames= new HashSet<String>();
          mapRoleNames.add(role1);
          mapRoleNames.add(role2);
          mapRoleNames.add(role3);
          SearchCriteria criteria = new SearchCriteria(RoleManagerConstants.ROLE_NAME,mapRoleNames, SearchCriteria.Operator.IN);
          List<Role> roles = null;
          HashMap<String, Object> mapParams = null;
          Set<String> attrNames = null;
          RoleManager roleMgr = oimClient.getService(RoleManager.class);
          try
          {
          roles = roleMgr.search(criteria, attrNames, mapParams);

          System.out.println("Size:"+roles.size());

          for (Role role : roles)
          {
          HashMap<String, Object> roleData = new HashMap<String, Object>();

          roleData=role.getAttributes();

          Iterator iterator = roleData.keySet().iterator();

          while (iterator.hasNext()) {  
          String key = iterator.next().toString();
          String value = roleData.get(key).toString();

          System.out.println(key + " " + value);
          }

          System.out.println(role.getEntityId()+":"+role.getName()+":"+role.getDisplayName()+":"+role.getNamespace());
          }
          }
          catch(Exception e) {
          e.printStackTrace();
          }
          }
          • 2. Re: Code to searh multiple roles
            942393
            Thanks Srini.