OIM Create Bulk Organizations API


  1. package com.oimacademy.org;
  2. import java.util.Calendar;
  3. import oracle.iam.identity.orgmgmt.api.OrganizationManager;
  4. import oracle.iam.identity.orgmgmt.vo.Organization;
  5. import com.oimacademy.connection.Platform;
  6. import oracle.iam.platform.authopss.vo.AdminRole;
  7. import oracle.iam.platform.authopss.vo.AdminRoleMembership;
  8. import oracle.iam.platformservice.api.AdminRoleService;
  9. public class CreateOrganizations { 
  10.  protected static OrganizationManager m_orgManagerService ;
  11.   public static int getRandomNumber() {
  12.          java.util.Random r = new java.util.Random(Calendar.getInstance()
  13.                  .getTimeInMillis());
  14.          int randint = Math.abs(r.nextInt()) % 1000;     
  15.          return randint;
  16.      }
  17.  public static String createorg() throws Exception {
  18.   m_orgManagerService = (OrganizationManager) Platform.getService(OrganizationManager.class);
  19.   String result=null;
  20.   Organization org = new Organization();
  21.   for(int i=1; i< 1000;i++){
  22.   org.setAttribute("Organization Name", "TEST_ORG_"+i);
  23.   org.setAttribute("Organization Customer Type", "System");
  24.   org.setAttribute("Organization Status", "Active");  
  25.   result = m_orgManagerService.create(org);     
  26.   System.out.println("Organization   Key : " + result);   
  27.         AdminRoleService arsi = Platform.getService(AdminRoleService.class);  
  28.   AdminRole ar= arsi.getAdminRole("OrclOIMUserViewer");
  29.         AdminRoleMembership arm = new AdminRoleMembership("5", ar, result, true);
  30.         arsi.addAdminRoleMembership(arm);
  31.         AdminRole ar1= arsi.getAdminRole("OrclOIMOrgAdministrator");
  32.         AdminRoleMembership arm1 = new AdminRoleMembership("5", ar1, result, true);
  33.         arsi.addAdminRoleMembership(arm1);
  34.         System.out.println("done"+i);                
  35.   }
  36.   System.out.println("Done");
  37.   //System.out.println("Updated Password with key "+updateOrgPasswordPolicy(result));
  38.   return result; 
  39.  } 
  40.  public static void main(String[] args) throws Exception {
  41.   CreateOrganizations createorgObj = new CreateOrganizations();
  42.   createorgObj.createorg();  
  43.   //createorgObj.deleteOrganizations();  
  44.  }
  45. }

No comments:

Post a Comment