Friday, 24 August 2012

OIM Code to get the userlist Assocaiated with a resource

public String associatedUsersResource(String resource,String status){


//Pass the resource name as input
//status will be either provisioedor provisioning or disabled
//If we pass * in the status ,it will return all the users assocaited with the resource with all status

HashMap status1=new HashMap();
status1.put("Objects.Object Status.Status", status);
try {
tcResultSet result=prov.getAssociatedUsers(getObjectKey(resource), status1);
for(int i=0;i<=result.getRowCount()-1;i++){
result.goToRow(i);
System.out.println(result.getStringValue("Users.User ID"));
}
} catch (tcAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcObjectNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcColumnNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return status;
}

Monday, 13 August 2012

Error while updating user



Normally when we update a user ,we used to call findusers and then call a update

tcResultSet moResultSet = moUserUtility.findUsers(userMap);
hmUser.put("Users.User ID", UID);
hmUser.put("Users.Password", pwd);
moUserUtility.updateUser(moResultSet, hmUser);

now if you call a second update like

hmUser.put("Users.User ID", UID);
 hmUser.put("Users.First Name", FN);
moUserUtility.updateUser(moResultSet, hmUser);

it will throw exception like threw Exception Thor.API.Exceptions.tcStaleDataUpdateException which is caused because for the second update it did not call the find users.It should be like

tcResultSet moResultSet = moUserUtility.findUsers(userMap);
hmUser.put("Users.User ID", UID);
 hmUser.put("Users.First Name", FN);
moUserUtility.updateUser(moResultSet, hmUser);

Now the update works fine.


Thursday, 31 May 2012

code to trigger a particular task of a resource

In this code,The API uses the method addProcessTaskInstance which takes the taskKey and the processinstancekey as input

I have written a seperate blogs to get the taskKey and getting the processInstance key

public void executeTask(String resourceName,String taskName,String userId){

try{
//pass the Task Key and thProcess instance key
moOperations.addProcessTaskInstance(taskKey(taskName,resourceName),getProcessInstKeyOfRes(resourceName,getUserKey(userId)));
System.out.println("executed");
}catch(Exception e){
}
}

Code to get the processInstanceKey of a resource provisioned to a user

private long getProcessInstKeyOfRes(String res_Name,long userkey) {
long longProcessInstanceKey = 0;
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");
System.out.println("---------Object name"+objetcName);
if(res_Name.equalsIgnoreCase(objetcName)) {
String status = resultGetObjects.getStringValue("Objects.Object Status.Status");
status = status.toLowerCase();
System.out.println(status);
longProcessInstanceKey = resultGetObjects.getLongValue("Process Instance.Key");
System.out.println("Process Instance Key"+ longProcessInstanceKey);
}
}

}catch (Exception e) {
}
return longProcessInstanceKey;
}

code to get the task Key of a Resource

public long taskKey(String taskname,String resourceName){
long ret=0;
try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
  String url = "jdbc:oracle:thin:@localhost1:siddb";
  Connection conn = DriverManager.getConnection(url,"adm","password");
System.out.println("connected");
Statement stmt = conn.createStatement();
ResultSet rset =
stmt.executeQuery("SELECT m.mil_key,m.MIL_NAME FROM mil m, pkg p, tos t WHERE m.mil_name = '"+taskname+"' AND m.TOS_KEY = t.TOS_KEY AND t.PKG_KEY = p.PKG_KEY AND p.pkg_name='"+resourceName+"'");


while (rset.next()) {
String convertret=rset.getString(1);
long longKey = Long.parseLong(convertret);
System.out.println ("TaskKey-->"+longKey);
System.out.println ("TaskName-->"+rset.getString(2));
return longKey;

}
stmt.close();
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
return ret;


}

Provision a resource to a user

public void provisionResource(String resourcetobeProvisioned,String UserID){
try{
long moResultSet = moUserUtility.provisionObject(getUserKey(UserID),getObjectKey(resourcetobeProvisioned));
System.out.println("Added");

}catch(Exception e){

}
}

Monday, 28 May 2012


Create a table in DB

CREATE TABLE "XLADM(DBUSERNAME)"."USER_DATA(TABLENAME)" ( "USER_ID" VARCHAR2(20 BYTE) NOT NULL ENABLE, "FIRSTNAME" VARCHAR2(20 BYTE), "LASTNAME" VARCHAR2(20 BYTE), "ORGANIZATION" VARCHAR2(20 BYTE), "PASSWORD" VARCHAR2(20 BYTE), "EMAIL" VARCHAR2(20 BYTE), "COMPANY" VARCHAR2(20 BYTE), CONSTRAINT "USER_DATA_PK" PRIMARY KEY ("USER_ID") )

Provisioning to a DB table

Download DBAT_91050

IN GTC connector, select provisioning
Connector Name DB APP
Transport Provider (Provisioning) DBProvisioningTransport
Format Provider (Provisioning) DBProvisioningFormat

Database Driver: oracle.jdbc.driver.OracleDriver
Database URL: jdbc:oracle:thin:@locahost:1521:oimsr
Database User ID: xladm
Database Password: password

Parent Table/View Name: USER_DATA(Table Name)
No need to make changes to to the Mappings shown in GTC..

Thats it you are done.Now select the resource from resource object and follow the normal provisioning to a user.