Friday, May 2, 2014

OIM 11g R2 : Populate Organization Event Handler

This post covers the populating of organization based on registration type and business unit.

It checks the values in a lookup and based on the input , sets the organization value on the user profile.

The Event Handler is post process so that it can run on all the users created in some default org after a trusted reconciliation.

Also it runs on the create as well as modify single or bulk operation on user entity.





  1 package com.dubey.deepak.iam.oim.event.handler;
  2 
  3 import java.io.Serializable;
  4 
  5 import java.util.HashMap;
  6 
  7 import java.util.Hashtable;
  8 
  9 import java.util.Map;
 10 
 11 import java.util.Set;
 12 
 13 import oracle.iam.platform.Platform;
 14 
 15 import oracle.iam.platform.context.ContextAware;
 16 
 17 import oracle.iam.platform.kernel.spi.PostProcessHandler;
 18 
 19 import oracle.iam.platform.kernel.vo.AbstractGenericOrchestration;
 20 
 21 import oracle.iam.platform.kernel.vo.BulkEventResult;
 22 
 23 import oracle.iam.platform.kernel.vo.BulkOrchestration;
 24 
 25 import oracle.iam.platform.kernel.vo.EventResult;
 26 
 27 import oracle.iam.platform.kernel.vo.Orchestration;
 28 
 29 import Thor.API.tcResultSet;
 30 
 31 import Thor.API.Exceptions.tcAPIException;
 32 
 33 import Thor.API.Exceptions.tcColumnNotFoundException;
 34 
 35 import Thor.API.Exceptions.tcStaleDataUpdateException;
 36 
 37 import Thor.API.Exceptions.tcUserNotFoundException;
 38 
 39 import Thor.API.Operations.tcLookupOperationsIntf;
 40 
 41 import Thor.API.Operations.tcOrganizationOperationsIntf;
 42 
 43 import Thor.API.Operations.tcUserOperationsIntf;
 44 
 45 public class PopulateOrg implements PostProcessHandler {
 46 
 47       public EventResult execute(long processId, long eventId,
 48 
 49                   Orchestration orchestration) {
 50 
 51             System.out.println("Entering  EventResult->");
 52 
 53             System.out.println("Exiting  EventResult->");
 54 
 55             return new EventResult();
 56 
 57       }
 58 
 59       public BulkEventResult execute(long processId, long eventId,
 60 
 61                   BulkOrchestration bulkOrchestration) {
 62 
 63             System.out
 64 
 65                         .println("Entering  BulkEventResult of PopulateOrg ");
 66 
 67             System.out.println("bulkOrchestration.getOperation()--->"
 68 
 69                         + bulkOrchestration.getOperation());
 70 
 71             HashMap<String, Serializable>[] bulkParams = bulkOrchestration
 72 
 73                         .getBulkParameters();
 74 
 75             tcUserOperationsIntf tcUserOp = ((tcUserOperationsIntf) Platform
 76 
 77                         .getService(tcUserOperationsIntf.class));
 78 
 79             for (HashMap<String, Serializable> bulkParam : bulkParams) {
 80 
 81                   Set<String> bulkKeySet = bulkParam.keySet();
 82 
 83                   String regtypeps = null;
 84 
 85                   String role = null;
 86 
 87                   String businessunit = null;
 88 
 89                   String usrLogin = null;
 90 
 91                   for (String key : bulkKeySet) {
 92 
 93                         Serializable serializable = bulkParam.get(key);
 94 
 95                         if (key.equalsIgnoreCase("REGTEMPPS")) {
 96 
 97                               regtypeps = serializable.toString();
 98 
 99                               System.out.println("regtypeps ->" + regtypeps);
100 
101                               if (regtypeps.equalsIgnoreCase("T")) {
102 
103                                     role = "Contractor";
104 
105                               }
106 
107                         }
108 
109                         if (key.equalsIgnoreCase("BUSINESSUNITPS")) {
110 
111                               businessunit = serializable.toString();
112 
113                               System.out.println("businessunit ->" + businessunit);
114 
115                         }
116 
117                         if (key.equalsIgnoreCase("User Login")) {
118 
119                               usrLogin = serializable.toString();
120 
121                         }
122 
123                   }
124 
125                   String orgKey = null;
126 
127                   if (((regtypeps != null) && (!regtypeps.trim()
128 
129                               .equalsIgnoreCase("")))
130 
131                               || ((businessunit != null) && (!businessunit.trim()
132 
133                                           .equalsIgnoreCase("")))) {
134 
135                         orgKey = getOrgKey(regtypeps, businessunit);
136 
137                   }
138 
139                   Map<String, String> phAttributeList = new HashMap<String, String>();
140 
141                   phAttributeList.put("Users.User ID", usrLogin);
142 
143                   tcResultSet resultSet = null;
144 
145                   try {
146 
147                         resultSet = tcUserOp.findUsers(phAttributeList);
148 
149                   } catch (tcAPIException e) {
150 
151                         e.printStackTrace();
152 
153                   }
154 
155                   int count = 0;
156 
157                   try {
158 
159                         count = resultSet.getRowCount();
160 
161                   } catch (tcAPIException e) {
162 
163                         e.printStackTrace();
164 
165                   }
166 
167                   try {
168 
169                         for (int i = 0; i < resultSet.getRowCount(); i++) {
170 
171                               resultSet.goToRow(i);
172 
173                               Map<String, String> updateUser = null;
174 
175                               if (orgKey != null) {
176 
177                                     if (updateUser == null) {
178 
179                                           updateUser = new HashMap<String, String>();
180 
181                                     }
182 
183                                     updateUser.put("Organizations.Key", orgKey);
184 
185                               }
186 
187                               if (role != null) {
188 
189                                     if (updateUser == null) {
190 
191                                           updateUser = new HashMap<String, String>();
192 
193                                     }
194 
195                                     updateUser.put("Users.Role", role);
196 
197                               }
198 
199                               if (updateUser != null) {
200 
201                                     tcUserOp.updateUser(resultSet, updateUser);
202 
203                               }
204 
205                         }
206 
207                   } catch (tcAPIException e) {
208 
209                         // TODO Auto-generated catch block
210 
211                         e.printStackTrace();
212 
213                   } catch (tcUserNotFoundException e) {
214 
215                         // TODO Auto-generated catch block
216 
217                         e.printStackTrace();
218 
219                   } catch (tcStaleDataUpdateException e) {
220 
221                         // TODO Auto-generated catch block
222 
223                         e.printStackTrace();
224 
225                   }
226 
227             }
228 
229             if (tcUserOp != null) {
230 
231                   tcUserOp.close();
232 
233             }
234 
235             System.out
236 
237                         .println("Exiting  BulkEventResult of PopulateOrg ");
238 
239             return new BulkEventResult();
240 
241       }
242 
243       private String getOrgKey(String empltypeps, String businessunit) {
244 
245             System.out.println("Entering  getOrgKey");
246 
247             String orgkey = null;
248 
249             if (((empltypeps != null) && (!empltypeps.trim()
250 
251                         .equalsIgnoreCase("")))
252 
253                         || ((businessunit != null) && (!businessunit.trim()
254 
255                                     .equalsIgnoreCase("")))) {
256 
257                   String codeKey = businessunit + "_" + empltypeps;
258 
259                   System.out.println("codeKey ->" + codeKey);
260 
261                   tcLookupOperationsIntf lookupOperationsIntf = null;
262 
263                   lookupOperationsIntf = (tcLookupOperationsIntf) Platform
264 
265                               .getService(tcLookupOperationsIntf.class);
266 
267                   String decodeKey = null;
268 
269                   try {
270 
271                         decodeKey = lookupOperationsIntf
272 
273                                     .getDecodedValueForEncodedValue(
274 
275                                                 "Lookup.BusUnit.EmplType.Org.Mapping", codeKey);
276 
277                         System.out.println("decodeKey ->" + decodeKey);
278 
279                         Hashtable orgHash = new Hashtable();
280 
281                         tcOrganizationOperationsIntf orgIntf = (tcOrganizationOperationsIntf) Platform
282 
283                                     .getService(tcOrganizationOperationsIntf.class);
284 
285                         orgHash.put("Organizations.Organization Name", decodeKey);
286 
287                         tcResultSet orgSet = orgIntf.findOrganizations(orgHash);
288 
289                         long lorgKey = 0;
290 
291                         try {
292 
293                               lorgKey = orgSet.getLongValue("Organizations.Key");
294 
295                               System.out.println("orgKey ->" + lorgKey);
296 
297                         } catch (tcColumnNotFoundException e) {
298 
299                               System.out
300 
301                                           .println("tcColumnNotFoundException exception ocurred "
302 
303                                                       + e);
304 
305                               System.out
306 
307                                           .println("tcColumnNotFoundException exception ocurred "
308 
309                                                       + e.getMessage());
310 
311                               // TODO Auto-generated catch block
312 
313                               e.printStackTrace();
314 
315                         }
316 
317                         orgkey = String.valueOf(lorgKey);
318 
319                         System.out.println("orgkey ->" + orgkey);
320 
321                   } catch (tcAPIException e) {
322 
323                         System.out
324 
325                                     .println("Exception in  getOrgKey->" + e.getMessage());
326 
327                         e.printStackTrace();
328 
329                   }
330 
331             }
332 
333             System.out.println("Exiting  getOrgKey");
334 
335             return orgkey;
336 
337       }
338 
339       public void compensate(long l, long l1,
340 
341                   AbstractGenericOrchestration abstractGenericOrchestration) {
342 
343       }
344 
345       public boolean cancel(long l, long l1,
346 
347                   AbstractGenericOrchestration abstractGenericOrchestration) {
348 
349             return false;
350 
351       }
352 
353       public void initialize(HashMap<String, String> hashMap) {
354 
355       }
356 
357       private String getParameterValue(HashMap<String, Serializable> parameters,
358 
359                   String key) {
360 
361             String value = (parameters.get(key) instanceof ContextAware) ? (String) ((ContextAware) parameters
362 
363                         .get(key)).getObjectValue()
364 
365                         : (String) parameters.get(key);
366 
367             return value;
368 
369       }
370 
371       private boolean isNullOrEmpty(String str) {
372 
373             return str == null || str.isEmpty();
374 
375       }
376 
377 }




 Plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>
  <plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
    <plugin pluginclass=
        "com.dubey.deepak.iam.oim.event.handler.PopulateOrg"
         version="1.0"
         name="PopulateOrg
">
    </plugin>
 </plugins>
</oimplugins>
Go to OIM_HOME/plugin_utility/ to register the plugin

ant -f  pluginregistration.xml register
 
 
Package the plugin in a zip file for it to be registered correctly.