Friday, December 10, 2010

Updating the Scheduled task attribute in OIM


public void updateSchedulerTimeStamp(String currentTime)
    {
        String methodName = "updateSchedulerTimeStamp";
      //  logger.setMethodStartLog(sClassName, s1);
        String s2 = "Enterprise User Target Recon";
        try
        {
            HashMap hashmap = new HashMap();
            hashmap.put("Task Scheduler.Name", s2);
            tcSchedulerOperationsIntf tcSchOper = (tcSchedulerOperationsIntf) getUtility("Thor.API.Operations.tcSchedulerOperationsIntf");
            tcResultSet tcresultset = tcSchOper.findScheduleTasks(hashmap);
            if(tcresultset != null && tcresultset.getRowCount() > 0)
            {
                 
                   logger.debug(className, methodName, "UPDATE TIME STAMP---->Result set has values");
                tcresultset.goToRow(0);
                long l = tcresultset.getLongValue("Task Scheduler.Key");
                logger.debug(className, methodName, "UPDATE TIME STAMP---->Result set has values");
                String s3 = String.valueOf(l);
                //Task Scheduler.Task Attributes.Key logger.debug(className, methodName, "UPDATE TIME STAMP----->Task Scheduler key"+s3);
                hashmap.clear();

                hashmap.put("Task Scheduler.Key", s3);
            
                hashmap.put("Task Scheduler.Task Attributes.Name", "LastRunDate");
                logger.debug(className, methodName, "UPDATE TIME STAMP-----> HashMap is "+hashmap);
                tcResultSet tcresultset1 = tcSchOper.findScheduleTaskAttributes(hashmap);
                if(tcresultset1 != null && tcresultset1.getRowCount()>0){
                  tcresultset1.goToRow(0);
                    long l1 = tcresultset1.getLongValue("Task Scheduler.Task Attributes.Key");
                    logger.debug(className, methodName, "UPDATE TIME STAMP----->Task Scheduler Attribute key "+l1);
                    hashmap.put("Task Scheduler.Task Attributes.Value", currentTime);
                    logger.debug(className, methodName, "UPDATE TIME STAMP----->Current Time is "+currentTime);
                    tcSchOper.updateScheduleTaskAttribute(l, l1, hashmap);   
                }
                else{
                  logger.debug(className, methodName, "UPDATE TIME STAMP----->Could not find any values for the scheduler attributes");
                }
               
            }
        }
        catch(tcAPIException tcapiexception)
        {
            logger.error(className, methodName, tcapiexception.getMessage());
            logger.setStackTrace(tcapiexception, className, methodName, tcapiexception.getMessage());
        }
        catch(tcColumnNotFoundException tccolumnnotfoundexception)
        {
            logger.error(className, methodName, tccolumnnotfoundexception.getMessage());
            logger.setStackTrace(tccolumnnotfoundexception, className, methodName, tccolumnnotfoundexception.getMessage());
        }
        catch(tcScheduledTaskNotFoundException tcscheduledtasknotfoundexception)
        {
            logger.error(className, methodName, tcscheduledtasknotfoundexception.getMessage());
            logger.setStackTrace(tcscheduledtasknotfoundexception, className, methodName, tcscheduledtasknotfoundexception.getMessage());
        }
        catch(tcNoSuchTaskAttributeException tcnosuchtaskattributeexception)
        {
            logger.error(className, methodName, tcnosuchtaskattributeexception.getMessage());
            logger.setStackTrace(tcnosuchtaskattributeexception, className, methodName, tcnosuchtaskattributeexception.getMessage());
        }
        logger.setMethodFinishLog(className, methodName);
    }
     

Tuesday, December 7, 2010

Creating an Event Handler in OIM

  1.  Copy the following code into a java file and then export it to the  OIM-HOME\xellerate\evenhandler folder.
  2.  Now open the Development Tools -> Business Rule Definition -> Event Handler Manager in the design console.
  3. Create a new Event Handler and specify:
    Event Handler Name: tcGenerateRandomPassword
  4. In the package name give the package in which the class is present.
  5. Select the pre-insert checkbox and then save the event handler.
  6. Now Goto Development Tools -> Business Rule Definition -> Data Object Manager
  7. Search for "Users" and add the event handler to the Pre-Insert list.
  8. Save it.
Now once you create a user in xellerate it will generate a random password for the user. Try logging in with the password generated and you should be able to login successfully.




import java.util.Random;
import com.thortech.xl.dataobj.tcDataSet;
import com.thortech.xl.util.logging.LoggerMessages; import com.thortech.xl.util.logging.LoggerModules;
import com.thortech.util.logging.Logger;

public class tcGenerateRandomPassword extends com.thortech.xl.client.events.tcBaseEvent

{


public tcGenerateRandomPassword()
{
setEventName("Generating a random password for a User.");
}

protected void implementation() throws Exception

{

if (getDataObject().isDeleting())

{

return;

}

if (getDataObject().isUpdating())

{

return;

}

String randomPassword = getRandomPassword();

getDataObject().setString("usr_password",randomPassword);

System.out.println("The Random Password generated is -----" +randomPassword);

return;

}

private String getRandomPassword()

{

StringBuffer buffer = new StringBuffer();

Random random = new Random();

for ( int i = 0; i < 10; i++ ) {

buffer.append(((char)

('a'+random.nextInt(20))));

}

return buffer.toString();

}

}

Wednesday, December 1, 2010

Setup Eclipse Environment for OIM API debugging

  1. OIM Design Console must be installed.  This setup uses the files installed by the OIM Design Console.
  2. Add the Design Console JAR files to Eclipse:
    1. Select your project, then select Windows -> Preferences (Eclipse -> Properties on a Mac).
    2. Select Java, Build Path, User Libraries from the menu items on the left.
    3. Click the New button, and enter a library name (OIM API Library), then click OK.
    4. Click the Add Jars button, navigate to the "lib" directory where your OIM Design Console is installed (OIMDesignHome/xlclient/lib), and select all the jar files.  It is left as an exorcise to set the javadoc location -- these might be located somewhere in OIMDesignHome/documentation/SDK/javadocs.  If you find them, please update this page.
  3. Add the User Library created in 2 to your Eclipses project:
    1. Select your project, then select Project -> Properties.
    2. Select Java Build Path from the menu items on the left.
    3. Select the Libraries tab.
    4. Click on the Add Library button, select User Library from the list, then Next.
    5. Select OIM API Library from the list, then click Finish.
  4. Add the files in the Design Consoles "ext" directory to the class path, and set the VM Arguments:
    1. Select your project, then select Project -> Properties.
    2. Select Run/Debug Settings form the menu items on the left.
    3. If a launch configuration has not already been setup for your project, click on the New button and select Java Application as the type.  Otherwise, select your configuration and press the Edit button.
    4. On the Main tab, ensure that your Main class is set to the correct class file.
    5. On the Arguments tab, enter the following:
      -DXL.HomeDir=.
      -Djava.security.policy=config/xl.policy
      -Djava.security.auth.login.config=config/auth.conf
      -Dlog4j.configuration=config/log.properties
    6. Change the working directory to OIMDesignHome/xlclient.
    7. On the JRE tab, make sure that a 1.4.2 JVM is selected.  Otherwise you run the risk of using features not available to OIM.
    8. On the Classpath tab, select User Entries, then click on the Add External JARs button.
    9. Navigate to OIMDesignHome/xlclient/ext and select all the JAR files.
  5. Eclipse is now configured to run and debug your code that uses the OIM API.