import com.thortech.xl.client.events.tcTriggerUserProcesses; import com.thortech.xl.dataaccess.tcDataSetException; import com.thortech.xl.dataobj.tcDataSet; import java.io.IOException; import java.io.InputStream; import java.util.HashMap import java.util.Properties; import java.util.Vector; /** * Event handler to trigger User process task when the associated Organization is updated. * * Background: * <p> * OIM has two process triggers USR_PROCESS_TRIGGERS and ACT_PROCESS_TRIGGERS * that invokes a process task when a user attribute or an organization * attribute is changed. * <p> * For example if user's first name is updated, OIM can invoke * process task "Change First Name" on each of the user's resource. * <p> * Similarly OIM can invoke process task "Change Organization Name" on each * of the organization's resource when the name changes. * <p> * However there is no process trigger to invoke a * a _user_ process task when an _organization_ attribute changes. * Deploying this event handler will allow OIM to do this. * <p> * !! IMPORTANT !! * An Organization can have hundreds of users, * and each users can have many resources. So thousands of * process tasks might get triggered, potentially slowing down OIM to a crawl. * <p> * To prevent that narrow down as much as possible the organization and * the users that can trigger the process tasks. * <p> * In the implementation below, only organizations of type "Location" will * trigger the process tasks for users whose login start with "LOCATION". * <p> * To deploy: * <p> * Review which organization and which users you want to trigger processes * and update constants <code>ORGANIZATION_TYPE_FILTER</code> and <code>USER_FILTER</code> accordingly. * <p> * Create a lookup Lookup.ACT_USR_PROCESS_TRIGGERS and enter the organization * attributes and the process tasks to trigger * (modeled on Lookup.USR_PROCESS_TRIGGERS and Lookup.ACT_PROCESS_TRIGGERS) * <p> * Add a new event handler in Event Handler Manager. * <p> * In Data Object Manager, find the Organization object. Add * the event handler created in previous step as a Post-Update. * <p> * Add process tasks in the desired process definition * (e.g. in process AD User add task "Change Organization Telephone") * <p> * Created 2010-04-09 * * @author Vinh-An Trinh vinhant@zerointech.com */ public class TriggerOrganizationUserProcesses extends tcTriggerUserProcesses { // You can modify these constants // Only organization of this type will trigger the user process tasks // in order to prevent firing too many process tasks // Modify the organization type according to your specifications final String ORGANIZATION_TYPE_FILTER = "Location"; // Only users in this select query will trigger the users process tasks // in order to prevent firing too many process tasks // Modify the WHERE clause to your specifications final String USER_FILTER = "SELECT usr_login, usr_key, act_key " + "FROM usr " + "WHERE usr_first_name = 'LOCATION'"; // Do not modify code below // The Organization to User processes are stored in this lookup final String PROCESS_TRIGGERS_LOOKUP_NAME = "Lookup.ACT_USR_PROCESS_TRIGGERS"; private String isActKey = ""; private boolean ibCheckCancelled = true; public TriggerOrganizationUserProcesses() { setEventName("TriggerOrganizationUserProcesses"); } protected void implementation() throws Exception { String newOrganizationType = getDataObject().getString( "ACT_CUST_TYPE"); if (ORGANIZATION_TYPE_FILTER.equalsIgnoreCase( newOrganizationType)) { initActKey(); Vector localVector = getMilNamesNeedTrigger( PROCESS_TRIGGERS_LOOKUP_NAME); for (int i = 0; i < localVector.size(); ++i) { String str = (String) localVector.elementAt(i); trigger(str, this.ibCheckCancelled, PROCESS_TRIGGERS_LOOKUP_NAME); } } } private void initActKey() { this.isActKey = getDataObject().getString("act_key"); } protected void initOrcTosMap(boolean paramBoolean) { int i; this.ioOrcTosMap = new HashMap(); try { String queryOrcTos = "SELECT usr_login, pkg_name, orc_key, tos_key " + "FROM orc, pkg, (${trigger_process_users}) organization_users " + "WHERE orc.pkg_key = pkg.pkg_key " + "AND orc.usr_key = organization_users.usr_key " + "AND orc.act_key = organization_users.act_key " + "AND orc.act_key = ${isActKey} " + "AND Nvl(pkg_system,0) <> 1 "; if (paramBoolean) queryOrcTos = queryOrcTos + " and orc_status not in ('X', 'PX')"; queryOrcTos = queryOrcTos.replaceAll( "//$//{trigger_process_users//}", USER_FILTER); queryOrcTos = queryOrcTos.replaceAll("//$//{isActKey//}", isActKey); tcDataSet localtcDataSet = new tcDataSet(); localtcDataSet.setQuery(getDataBase(), queryOrcTos); localtcDataSet.executeQuery(); for (i = 0; i < localtcDataSet.getRowCount(); ++i) { localtcDataSet.goToRow(i); String usr_login = localtcDataSet.getString("usr_login"); String pkg_name = localtcDataSet.getString("pkg_name"); String orc = localtcDataSet.getString("orc_key"); String tos = localtcDataSet.getString("tos_key"); System.out.println("Found user/process: " + usr_login + "/" + pkg_name); this.ioOrcTosMap.put(orc, tos); } } catch (tcDataSetException localtcDataSetException) { localtcDataSetException.printStackTrace(); } } }