Wednesday, 13 February 2013

Update OIM Form Details

public void updatehannel(String procInstKey, String Channel) {
  HashMap map = new HashMap();
  map.put("UD_SB_TYPE",Channel);
  try {
   moform.setProcessFormData(Long.parseLong(procInstKey), map);
  } catch (tcAPIException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (NumberFormatException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcInvalidValueException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcNotAtomicProcessException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcFormNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcRequiredDataMissingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcProcessNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

Getting OIM Form Details

public void getFormDetails(String userID, String resName) {
  HashMap map = new HashMap();
  System.out.println("Getting Proc Inst Key");
  long processInstKey = 0;
  ArrayList getlist = getProcessInstKeyOfResources(resName,
    getUserKey(userID));
  try {
   Iterator<Long> procinstKey = getlist.iterator();
   while (procinstKey.hasNext()) {
    long prockey = procinstKey.next();
    System.out.println("Keys--->" + prockey);
    tcResultSet resultset = moform.getProcessFormData(prockey);
    String[] values = resultset.getColumnNames();
    for (String name : values) {
     for (int i = 0; i < resultset.getRowCount(); i++) {
      resultset.goToRow(i);
      String value = resultset.getStringValue(name);
      map.put(name, value);
      map.remove("UD_OID_P_NOTE");
      map.remove("UD_ACC_PROV_NOTE");
      map.remove("UD_WAT_NOTE");
      map.remove("UD_STRM_NOTE");
      map.remove("UD_SBL_P_NOTE");
      map.remove("UD_ADUSER_NOTE");
      map.remove("UD_APR_NOTE");
     }
    }
    System.out.println(map.toString());
   }
  } catch (tcAPIException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcNotAtomicProcessException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcFormNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcProcessNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcColumnNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

private ArrayList getProcessInstKeyOfResources(String res_Name, long userkey) {
  long longProcessInstanceKey = 0;
  ArrayList list = new ArrayList();
  try {
   tcResultSet resultGetObjects = moUserUtility.getObjects(userkey);
   int countResultGetObjects = resultGetObjects.getRowCount();
   for (int i = 0; i < countResultGetObjects; i++) {
    resultGetObjects.goToRow(i);
    String objetcName = resultGetObjects
      .getStringValue("Objects.Name");
    String status = resultGetObjects
      .getStringValue("Objects.Object Status.Status");
    longProcessInstanceKey = resultGetObjects
      .getLongValue("Process Instance.Key");
    System.out.println("OBJ-->" + objetcName + "---->" + status
      + "---->" + longProcessInstanceKey);
    list.add(longProcessInstanceKey);
   }
   System.out.println(list);
  } catch (Exception e) {
  }
  return list;
 }

OIM Requests

public void createRequest(String Uid, String Object, String Admin) {
  HashMap map = new HashMap();
  map.put("Requests.Object Request Type", "Add");
  map.put("Requests.Target Type", "U");
  map.put("Requests.Type", "U");
  // map.put("Requests.Considated Data Value",
  // "<Data><Users><User><UserLogin>TestUser</UserLogin><FirstName>Test</FirstName><LastName>User</LastName></User></Users><Resources><Resource Key=\"109\"><ResourceName>iPlanet User</ResourceName></Resource></Resources></Data>"
  // );
  long userKey = getUserKey(Uid);
  System.out.println("UserKey--->" + userKey);
  try {
   long reqKey = moreq.createRequest(map);// THIS INITIATES THE rEQUEST
             // TO THE
             // rEQUESTER(xelsysadm)
   System.out.println("ReqKey=" + reqKey);
   System.out.println("Request INITIATED");
   moreq.addRequestUser(reqKey, userKey);
   System.out.println("Added the request user"); // Add the request to
               // the User
   moreq.addRequestObject(reqKey, getObjectKey(Object), false);
   System.out.println("Object Added the request user"); // Add the
                 // request
                 // to the
                 // Object
   moreq.completeRequestCreation(reqKey);
   System.out.println("Completed and submitted the request"); // Completes
                  // the
                  // request
                  // creation
                  // and
                  // waits
                  // for
                  // approval
   // Approve the request
   Thread.sleep(10000);
   approveRequest(reqKey, Admin);
   System.out.println("Admin has approved the request");
  } catch (tcAPIException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcAttributeMissingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcInvalidAttributeException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcRequestInvalidException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcRequestNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcRequestUserInvalidException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcRequestObjectInvalidException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 public void approveRequest(long reqKey, String Uid) {
  HashMap map = new HashMap();
  map.put("Requests.Object Request Type", "Add");
  map.put("Requests.Target Type", "U");
  map.put("Requests.Type", "U");
  long userKey = getUserKey(Uid);// Admin user has to be passed
          // (requester---xelsysadm)
  try {
   moreq.setRequestResponse(reqKey, userKey, "Approve");
   System.out.println("completed");
  } catch (tcAPIException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcInvalidResponseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcAwaitingObjectDataCompletionException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (tcAwaitingApprovalDataCompletionException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  /*
   * try { tcResultSet set;
   * set=moreq.getApprovalTasksAssignedToUser(userKey, map); String[]
   * coumnName=set.getColumnNames();
   *
   * for(String cName : coumnName){
   *
   * System.out.println(cName); System.out.println(set.getRowCount());
   *
   * for (int i = 0; i < set.getRowCount(); i++) { set.goToRow(i); String
   * value = set.getStringValue(cName);
   * System.out.println(cName+"---->"+value);
   *
   * } }
   *
   * System.out.println("Request Approval Initiated...");
   *
   * } catch (tcAPIException e) { // TODO Auto-generated catch block
   * e.printStackTrace(); }catch (tcUserNotFoundException e) { // TODO
   * Auto-generated catch block e.printStackTrace(); } catch
   * (tcAttributeNotFoundException e) { // TODO Auto-generated catch block
   * e.printStackTrace(); } catch (tcColumnNotFoundException e) { // TODO
   * Auto-generated catch block e.printStackTrace(); }
   */
 }

Writing OIM Details to Excel

 public void WriteToExcel(String UserID) {
  XSSFWorkbook wb = new XSSFWorkbook();
 
  String Id = "";
  String Fn = "";
  String Ln = "";
  String Org = "";
  String Status = "";
  String Cdate="";
  try {
   System.out.println("Creating File...");
   FileOutputStream finalOutput = new FileOutputStream(
     "D:/Newfolder/AD.xls");
   int rowCount = 0;
   XSSFRow outputRow = null;
   XSSFCell cell;
   XSSFSheet reportSheet = wb.createSheet("User Details");
  
   System.out.println("Writing Records...");
  
   XSSFRow headerRow = reportSheet.createRow(rowCount++);
   cell = headerRow.createCell(0, Cell.CELL_TYPE_STRING);
   cell.setCellValue("UserId");
   cell = headerRow.createCell(1, Cell.CELL_TYPE_STRING);
   cell.setCellValue("First Name");
   cell = headerRow.createCell(2, Cell.CELL_TYPE_STRING);
   cell.setCellValue("Last Name");
   cell = headerRow.createCell(3, Cell.CELL_TYPE_STRING);
   cell.setCellValue("Organization");
   cell = headerRow.createCell(4, Cell.CELL_TYPE_STRING);
   cell.setCellValue("Status");
   cell = headerRow.createCell(5, Cell.CELL_TYPE_STRING);
   cell.setCellValue("Created Date");
  
  
   ArrayList getuserMap=getDetails(UserID);
  
  
   Iterator<HashMap> listval = getuserMap.iterator();
   while (listval.hasNext()) {
    HashMap values = listval.next();
    System.out.println("Keys--->" + values);
   
    Id=(String) values.get("Users.User ID");
    Fn=(String) values.get("Users.First Name");
    Ln=(String) values.get("Users.Last Name");
    Org=(String) values.get("Users.Xellerate Type");
    Status=(String) values.get("Users.Status");
    Cdate=(String) values.get("Users.Creation Date");   
  
  
  
  
   outputRow = reportSheet.createRow(rowCount++);
   cell = outputRow.createCell(0, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Id);
   cell = outputRow.createCell(1, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Fn);
   cell = outputRow.createCell(2, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Ln);
   cell = outputRow.createCell(3, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Org);
   cell = outputRow.createCell(4, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Status);
   cell = outputRow.createCell(5, Cell.CELL_TYPE_STRING);
   cell.setCellValue(Cdate);
  
  
  
   }
  
   wb.write(finalOutput);
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 public ArrayList getDetails(String userID) {
 
  System.out.println("Getting the details of the user"+userID);
  ArrayList<HashMap> list=new ArrayList<HashMap>();
 
  String Fn = "";
  String Ln = "";
  String Org = "";
  String Status = "";
  String Cdate="";
  HashMap userMap = new HashMap();
  HashMap resultMap;
  try {
   userMap.put("Users.User ID", userID);
   tcResultSet moResultSet = moUserUtility.findUsers(userMap);
   for (int i = 0; i < moResultSet.getRowCount(); i++) {
    moResultSet.goToRow(i);
    userID = moResultSet.getStringValue("Users.User ID");
    Fn = moResultSet.getStringValue("Users.First Name");
    Ln = moResultSet.getStringValue("Users.Last Name");
    Org = moResultSet.getStringValue("Users.Xellerate Type");
    Status = moResultSet.getStringValue("Users.Status");
    Cdate = moResultSet.getStringValue("Users.Creation Date");
    resultMap = new HashMap();
    resultMap.put("Users.User ID", userID);
    resultMap.put("Users.First Name", Fn);
    resultMap.put("Users.Last Name", Ln);
    resultMap.put("Users.Xellerate Type", Org);
    resultMap.put("Users.Status", Status);
    resultMap.put("Users.Creation Date", Cdate);
    list.add(resultMap);
    //System.out.println(list);
   }
  
  
  
   System.out.println("Returning HashMap");
  
  } catch (Exception e) {
   e.printStackTrace();
  }
  return list;
 }

Getting Column Names OIM

public void getColumnNames(String UserID){
 
  HashMap userMap = new HashMap();
  try {
   userMap.put("Users.User ID", UserID);
   tcResultSet moResultSet = moUserUtility.findUsers(userMap);
   String[] CName=moResultSet.getColumnNames();
  
   for(String cname :CName){
    System.out.println(cname);
   }
  
  } catch (Exception e) {
   e.printStackTrace();
  }
 
 }