Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version='1.0' encoding='UTF-8'?>
- <!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
- <Rule created="1542034161131" id="2c94229866c37b6101670865fdeb66ad" language="beanshell" modified="1542206003376" name="Unit Testing Misc v2">
- <Source>
- import sailpoint.api.Workflower;
- import sailpoint.object.Attributes;
- import sailpoint.object.Identity;
- import sailpoint.object.ProvisioningPlan;
- import sailpoint.object.ProvisioningPlan.AccountRequest;
- import sailpoint.object.ProvisioningPlan.AttributeRequest;
- import sailpoint.object.Workflow;
- import sailpoint.object.WorkflowLaunch;
- import sailpoint.tools.GeneralException;
- import sailpoint.tools.RFC4180LineParser;
- import sailpoint.workflow.StandardWorkflowHandler;
- String dlm = ",";
- String csvFileName = "E:\\users\\bulkUserTest.csv";
- File testFile = new File(csvFileName);
- if ((!testFile.exists()) || (testFile.isDirectory())) {
- System.out.println("Unable to find file: " + csvFileName);
- return;
- }
- System.out.println("Importing Roles from: '" + csvFileName + "' ...");
- // Open the CSV file for reading.
- BufferedReader fileIn = new BufferedReader(new FileReader(csvFileName));
- RFC4180LineParser parser = new RFC4180LineParser(dlm);
- int lineCounter = 0;
- ArrayList<String> headerStrings = new ArrayList();
- String thisLine = null;
- while (null != (thisLine = fileIn.readLine())) {
- List<String> tokens = parser.parseLine(thisLine);
- if (lineCounter == 0) {
- // Header Line.
- // Assign indexes to each position.
- for (int i=0; i < tokens.size(); i++) {
- headerStrings.add(tokens.get(i).trim());
- }
- }
- else {
- // Data Line. Read the data elements out.
- HashMap lineHash = new HashMap();
- for (int i=0; i < tokens.size(); i++) {
- String headerString = headerStrings.get(i);
- String valueString = tokens.get(i);
- if (null != valueString) { valueString = valueString.trim(); }
- System.out.println ("header " + headerString + " == " + valueString);
- lineHash.put(headerString, valueString);
- }
- System.out.println(lineHash);
- ArrayList<String> requiredFields = new ArrayList();
- requiredFields.add("firstname");
- requiredFields.add("lastname");
- requiredFields.add("manager");
- requiredFields.add("jobTitle");
- requiredFields.add("nativeFirstName");
- requiredFields.add("lastname");
- requiredFields.add("jobTitleJV");
- requiredFields.add("department");
- requiredFields.add("startDate");
- requiredFields.add("nativeLastName");
- boolean missingRequiredField = false;
- for(String field : requiredFields) {
- if (lineHash.get(field) == null) {
- missingRequiredField = true;
- }
- }
- if(missingRequiredField) {
- continue;
- }
- else {
- //prep
- ProvisioningPlan pp = new ProvisioningPlan();
- AccountRequest acct = new AccountRequest();
- acct.setOperation(ProvisioningPlan.AccountRequest.Operation.Create);
- acct.setApplication("IIQ");
- lineHash.put("adOU", "OU=Contractors,OU=ExternalUserAccounts,OU=ISI_AccountsAndGroups");
- lineHash.put("adOUChinaJV", "OU=InternalUserAccounts,OU=AccountsAndGroups");
- lineHash.put("cubeType", "Contingent Worker");
- lineHash.put("employeeType", "JV-CN");
- lineHash.put("company", "ISFMT");
- lineHash.put("isuAccountRequired","Yes");
- //NEED TO ADD ADDITIONAL LOGIC FOR MANAGER HERE
- lineHash.put("manager","MAXP");
- //calculate displayName
- String displayName = lineHash.get("firstname") + " " + lineHash.get("lastname");
- lineHash.put("displayName", displayName);
- //calc costCenter
- String costCenter = "";
- String[] bits = lineHash.get("department").split("-");
- if (bits != null) {
- if (bits.length > 1) {
- costCenter = bits[0];
- lineHash.put("costCenter", costCenter);
- }
- }
- //calculate userID and name
- boolean useDisplayName = false;
- String prefix = "";
- sailpoint.object.Rule generator = context.getObject(sailpoint.object.Rule.class, "ISRG Generic UserID Generation");
- java.util.HashMap map = new java.util.HashMap();
- String localFirstName = lineHash.get("firstname");
- localFirstName = localFirstName.substring(0, 1).toUpperCase() + localFirstName.substring(1);
- String localLastName = lineHash.get("lastname");
- localLastName = localLastName.substring(0, 1).toUpperCase() + localLastName.substring(1);
- map.put("firstname",localFirstName);
- map.put("lastname",localLastName);
- map.put("prefix",prefix);
- map.put("displayName",displayName);
- map.put("useDisplayName",useDisplayName);
- String userID = context.runRule(generator, map);
- acct.setNativeIdentity(userID);
- lineHash.put("userID", userID);
- lineHash.put("name", userID);
- //build plan
- Iterator it = lineHash.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry pair = (Map.Entry)it.next();
- if(pair.getValue() != null) {
- AttributeRequest attr = new AttributeRequest();
- attr.setName(pair.getKey().toString());
- attr.setValue(pair.getValue().toString());
- attr.setOperation(ProvisioningPlan.Operation.Set);
- acct.add(attr);
- }
- }
- pp.add(acct);
- //provision
- System.out.println("provisioning " + userID + " now...");
- String workflowName = "LCM Create and Update";
- String caseName = "Create Identity Rule for : " + userID;
- String requesterId = "apieper";
- Workflow eventWorkflow = context.getObject(Workflow.class, workflowName);
- Identity id = context.getObjectByName(Identity.class, requesterId);
- long launchTime = System.currentTimeMillis() + 1000;
- caseName = caseName + "(" + launchTime + ")";
- Attributes reqArgs = new Attributes();
- //reqArgs.put(StandardWorkflowHandler.ARG_REQUEST_DEFINITION, sailpoint.request.WorkflowRequestExecutor.DEFINITION_NAME);
- //reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_WORKFLOW, workflowName);
- //reqArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_REQUEST_NAME, caseName);
- //reqArgs.put( "requestName", caseName);
- Attributes wfArgs = new Attributes();
- wfArgs.put("identityName", null);
- wfArgs.put("identityName", userID);
- wfArgs.put("plan", pp);
- wfArgs.put("launcher", id);
- wfArgs.put("flow", "IdentityCreateRequest");
- wfArgs.put("workflow", eventWorkflow.getId());
- wfArgs.put("approvalScheme", "none");
- //reqArgs.putAll(wfArgs);
- WorkflowLaunch wflaunch = new WorkflowLaunch();
- Workflow wf = (Workflow) context.getObjectByName(Workflow.class,"LCM Create and Update");
- wflaunch.setWorkflowName(wf.getName());
- wflaunch.setWorkflowRef(wf.getName());
- wflaunch.setCaseName("Create Identity Rule for : " + userID);
- wflaunch.setVariables(wfArgs);
- Workflower workflower = new Workflower(context);
- WorkflowLaunch launch = workflower.launch(wflaunch);
- }
- }
- lineCounter++;
- // Don't let objects accrue in memory, flush them out every so often.
- if ((lineCounter % 20) == 0) { context.decache(); }
- }
- fileIn.close();
- System.out.println("User import complete");
- return;
- </Source>
- </Rule>
Add Comment
Please, Sign In to add comment