- Copy the following code into a java file and then export it to the OIM-HOME\xellerate\evenhandler folder.
- Now open the Development Tools -> Business Rule Definition -> Event Handler Manager in the design console.
- Create a new Event Handler and specify:
Event Handler Name: tcGenerateRandomPassword - In the package name give the package in which the class is present.
- Select the pre-insert checkbox and then save the event handler.
- Now Goto Development Tools -> Business Rule Definition -> Data Object Manager
- Search for "Users" and add the event handler to the Pre-Insert list.
- Save it.
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();
}
}
No comments:
Post a Comment