Guest User

Untitled

a guest
Nov 14th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
  3. <Rule created="1542034161131" id="2c94229866c37b6101670865fdeb66ad" language="beanshell" modified="1542206003376" name="Unit Testing Misc v2">
  4. <Source>
  5. import sailpoint.api.Workflower;
  6. import sailpoint.object.Attributes;
  7. import sailpoint.object.Identity;
  8. import sailpoint.object.ProvisioningPlan;
  9. import sailpoint.object.ProvisioningPlan.AccountRequest;
  10. import sailpoint.object.ProvisioningPlan.AttributeRequest;
  11. import sailpoint.object.Workflow;
  12. import sailpoint.object.WorkflowLaunch;
  13. import sailpoint.tools.GeneralException;
  14. import sailpoint.tools.RFC4180LineParser;
  15. import sailpoint.workflow.StandardWorkflowHandler;
  16.  
  17.  
  18. String dlm = ",";
  19. String csvFileName = "E:\\users\\bulkUserTest.csv";
  20.  
  21. File testFile = new File(csvFileName);
  22. if ((!testFile.exists()) || (testFile.isDirectory())) {
  23. System.out.println("Unable to find file: " + csvFileName);
  24. return;
  25. }
  26.  
  27. System.out.println("Importing Roles from: '" + csvFileName + "' ...");
  28.  
  29. // Open the CSV file for reading.
  30. BufferedReader fileIn = new BufferedReader(new FileReader(csvFileName));
  31.  
  32. RFC4180LineParser parser = new RFC4180LineParser(dlm);
  33.  
  34. int lineCounter = 0;
  35. ArrayList<String> headerStrings = new ArrayList();
  36. String thisLine = null;
  37.  
  38. while (null != (thisLine = fileIn.readLine())) {
  39.  
  40. List<String> tokens = parser.parseLine(thisLine);
  41.  
  42. if (lineCounter == 0) {
  43. // Header Line.
  44. // Assign indexes to each position.
  45. for (int i=0; i < tokens.size(); i++) {
  46. headerStrings.add(tokens.get(i).trim());
  47. }
  48. }
  49. else {
  50. // Data Line. Read the data elements out.
  51. HashMap lineHash = new HashMap();
  52.  
  53. for (int i=0; i < tokens.size(); i++) {
  54. String headerString = headerStrings.get(i);
  55. String valueString = tokens.get(i);
  56. if (null != valueString) { valueString = valueString.trim(); }
  57. System.out.println ("header " + headerString + " == " + valueString);
  58. lineHash.put(headerString, valueString);
  59. }
  60.  
  61. System.out.println(lineHash);
  62.  
  63. ArrayList<String> requiredFields = new ArrayList();
  64. requiredFields.add("firstname");
  65. requiredFields.add("lastname");
  66. requiredFields.add("manager");
  67. requiredFields.add("jobTitle");
  68. requiredFields.add("nativeFirstName");
  69. requiredFields.add("lastname");
  70. requiredFields.add("jobTitleJV");
  71. requiredFields.add("department");
  72. requiredFields.add("startDate");
  73. requiredFields.add("nativeLastName");
  74.  
  75. boolean missingRequiredField = false;
  76.  
  77. for(String field : requiredFields) {
  78. if (lineHash.get(field) == null) {
  79. missingRequiredField = true;
  80. }
  81. }
  82.  
  83. if(missingRequiredField) {
  84. continue;
  85. }
  86. else {
  87. //prep
  88. ProvisioningPlan pp = new ProvisioningPlan();
  89. AccountRequest acct = new AccountRequest();
  90.  
  91. acct.setOperation(ProvisioningPlan.AccountRequest.Operation.Create);
  92. acct.setApplication("IIQ");
  93.  
  94. lineHash.put("adOU", "OU=Contractors,OU=ExternalUserAccounts,OU=ISI_AccountsAndGroups");
  95. lineHash.put("adOUChinaJV", "OU=InternalUserAccounts,OU=AccountsAndGroups");
  96. lineHash.put("cubeType", "Contingent Worker");
  97. lineHash.put("employeeType", "JV-CN");
  98. lineHash.put("company", "ISFMT");
  99. lineHash.put("isuAccountRequired","Yes");
  100.  
  101. //NEED TO ADD ADDITIONAL LOGIC FOR MANAGER HERE
  102. lineHash.put("manager","MAXP");
  103.  
  104. //calculate displayName
  105. String displayName = lineHash.get("firstname") + " " + lineHash.get("lastname");
  106. lineHash.put("displayName", displayName);
  107.  
  108. //calc costCenter
  109. String costCenter = "";
  110. String[] bits = lineHash.get("department").split("-");
  111. if (bits != null) {
  112. if (bits.length > 1) {
  113. costCenter = bits[0];
  114. lineHash.put("costCenter", costCenter);
  115. }
  116. }
  117.  
  118. //calculate userID and name
  119. boolean useDisplayName = false;
  120. String prefix = "";
  121.  
  122. sailpoint.object.Rule generator = context.getObject(sailpoint.object.Rule.class, "ISRG Generic UserID Generation");
  123. java.util.HashMap map = new java.util.HashMap();
  124.  
  125. String localFirstName = lineHash.get("firstname");
  126. localFirstName = localFirstName.substring(0, 1).toUpperCase() + localFirstName.substring(1);
  127.  
  128. String localLastName = lineHash.get("lastname");
  129. localLastName = localLastName.substring(0, 1).toUpperCase() + localLastName.substring(1);
  130.  
  131. map.put("firstname",localFirstName);
  132. map.put("lastname",localLastName);
  133. map.put("prefix",prefix);
  134. map.put("displayName",displayName);
  135. map.put("useDisplayName",useDisplayName);
  136.  
  137. String userID = context.runRule(generator, map);
  138.  
  139. acct.setNativeIdentity(userID);
  140.  
  141. lineHash.put("userID", userID);
  142. lineHash.put("name", userID);
  143.  
  144.  
  145. //build plan
  146. Iterator it = lineHash.entrySet().iterator();
  147. while (it.hasNext()) {
  148. Map.Entry pair = (Map.Entry)it.next();
  149. if(pair.getValue() != null) {
  150. AttributeRequest attr = new AttributeRequest();
  151. attr.setName(pair.getKey().toString());
  152. attr.setValue(pair.getValue().toString());
  153. attr.setOperation(ProvisioningPlan.Operation.Set);
  154. acct.add(attr);
  155. }
  156. }
  157. pp.add(acct);
  158.  
  159. //provision
  160. System.out.println("provisioning " + userID + " now...");
  161.  
  162. String workflowName = "LCM Create and Update";
  163. String caseName = "Create Identity Rule for : " + userID;
  164. String requesterId = "apieper";
  165.  
  166. Workflow eventWorkflow = context.getObject(Workflow.class, workflowName);
  167. Identity id = context.getObjectByName(Identity.class, requesterId);
  168.  
  169. long launchTime = System.currentTimeMillis() + 1000;
  170. caseName = caseName + "(" + launchTime + ")";
  171.  
  172. Attributes reqArgs = new Attributes();
  173. //reqArgs.put(StandardWorkflowHandler.ARG_REQUEST_DEFINITION, sailpoint.request.WorkflowRequestExecutor.DEFINITION_NAME);
  174. //reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_WORKFLOW, workflowName);
  175. //reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_REQUEST_NAME, caseName);
  176. //reqArgs.put( "requestName", caseName);
  177.  
  178. Attributes wfArgs = new Attributes();
  179. wfArgs.put("identityName", null);
  180. wfArgs.put("identityName", userID);
  181. wfArgs.put("plan", pp);
  182. wfArgs.put("launcher", id);
  183. wfArgs.put("flow", "IdentityCreateRequest");
  184. wfArgs.put("workflow", eventWorkflow.getId());
  185. wfArgs.put("approvalScheme", "none");
  186. //reqArgs.putAll(wfArgs);
  187.  
  188. WorkflowLaunch wflaunch = new WorkflowLaunch();
  189. Workflow wf = (Workflow) context.getObjectByName(Workflow.class,"LCM Create and Update");
  190. wflaunch.setWorkflowName(wf.getName());
  191. wflaunch.setWorkflowRef(wf.getName());
  192. wflaunch.setCaseName("Create Identity Rule for : " + userID);
  193. wflaunch.setVariables(wfArgs);
  194. Workflower workflower = new Workflower(context);
  195. WorkflowLaunch launch = workflower.launch(wflaunch);
  196.  
  197. }
  198.  
  199. }
  200.  
  201. lineCounter++;
  202.  
  203. // Don't let objects accrue in memory, flush them out every so often.
  204. if ((lineCounter % 20) == 0) { context.decache(); }
  205.  
  206. }
  207.  
  208. fileIn.close();
  209.  
  210. System.out.println("User import complete");
  211.  
  212. return;
  213. </Source>
  214. </Rule>
Add Comment
Please, Sign In to add comment