2 Replies Latest reply on May 26, 2013 4:40 AM by 942393

    Sample code to create a role along with its category

    942393
      Friends,

      I am looking for sample code snippet to create a role along with its category.

      Can you please help.
        • 1. Re: Sample code to create a role along with its category
          idamGod
          Try this.

          private String getCategoryKey(String CategoryName) {
          RoleCategoryManager categoryManager = oimClient.getService(RoleCategoryManager.class);
          RoleCategory str=null;
          try {
          str =categoryManager.getDetails("Role Category Name", CategoryName,null);
          } catch (SearchKeyNotUniqueException e) {
          e.printStackTrace();
          } catch (NoSuchRoleCategoryException e) {
          e.printStackTrace();
          } catch (RoleCategoryLookupException e) {
          e.printStackTrace();
          }
          System.out.println("CreateCategory.process() "+str.getEntityId());
          String categoryKey=str.getEntityId();
          return categoryKey;
          }

          private void createRoleWithCategory(String RoleName,String CategoryName) {
          HashMap<String, Object> mapAttrs = null;
          RoleManager roleManager = oimClient.getService(RoleManager.class);
          RoleManagerResult result = null;
          Role role = null;
          int categoryKey = Integer.parseInt(getCategoryKey(CategoryName));

          mapAttrs = new HashMap<String, Object>();
          mapAttrs.put(RoleManagerConstants.ROLE_NAME, RoleName);
          mapAttrs.put(RoleManagerConstants.ROLE_CATEGORY_KEY, categoryKey);
          mapAttrs.put(RoleManagerConstants.ROLE_DISPLAY_NAME,"TESTROLE2 test");
          mapAttrs.put(RoleManagerConstants.ROLE_DESCRIPTION,"testMigration from OIMClient API");
          role = new Role(mapAttrs);
          try {
          result = roleManager.create(role);
          } catch (ValidationFailedException e) {
          e.printStackTrace();
          } catch (RoleAlreadyExistsException e) {
          e.printStackTrace();
          } catch (RoleCreateException e) {
          e.printStackTrace();
          }
          System.out.println("Creation status: '" + result.getStatus() + "'");
          }
          • 2. Re: Sample code to create a role along with its category
            942393
            Thanks srini. it worked.