Saturday, June 16, 2012

OIM11G + Java: entity adapters vs event handlers


Today I will talk about entity adapter detailed and provide you a link that have a great explanation about event handler too.
Some definitions:
Adapter:Primarily used to automatically complete provisioning tasks.
Event handler:A resource object’s provisioning process contains tasks that must be completed automatically. Once this happened, you have to assign an event handler or an adapter to the RO. Basically an event handler is a software routine and it will process a specific information
Details:
–> It looks like the entity adapter is going to be deprecated. What will replace entity adapter? Probably Entity adapter will be replaced by Event handler. So, why I am writing an article related of entity adapter?Because there are specific cases that event handler can not apply yet. And for this specific case(Child table) pre-insert into OIM 11G.You have to use it to pre-insert entity adapter for a childform.
Starting: Basically my code example will check if the value of one variable column is unique or not. If yes, it will create a record into child form table. If not, it will raise an exception as I will show below:
First item: Java Code.
Using tcDataProviderObj
 Fig1: Using tcDataProviderObj
Fig2: Main method. Check uniqueness. Using only OIM API.
 
 Fig3: This method is another way to do same check, but now using SQL and OIM DataSet API.
Second Item: Screenshots of OIM configuration.
 Fig5: Adapter conditions.
Fig6- Adapter variables.
 Fig7: DataObject manager pre-insert handler.
 Fig8: Testing|provisioning a resource to an organization.
 Fig9: Value to test(Andrea).
 Fig10: Log results when value into that specific field and specific object exists.
 
 Fig11: Logs when value does not exist and the Resource will be added with that child table value successfully.
The complete java class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
 
* Check ||| Collect unique information from ParentFormID
 
* @param object --> process form table name
 
* @param field  --> field that should be unique
 
* @param value  --> that need to be checked
 
* @param orckey --> process Instace Key
 
* @return
 
* @throws Exception
 
*/
 
public boolean checkParentID(String object, String field, String value,long orckey) throws Exception {
 
tcResultSet parentFormDef;
 
List list = new ArrayList();
 
try {
 
logger.info("Part1:Running CHECKPARENtID Object:"+object+" FIELD:"+field+" VALUE:"+value+" ORCKEY:"+orckey);
 
f = Platform.getService(tcFormInstanceOperationsIntf.class);
 
poIntf = Platform.getService(tcProvisioningOperationsIntf.class);
 
//Check if LIST contains this specfic value
 
logger.info( "Part1:BOOLEAN VALUE:"+list.contains(value));
 
//this call should be changed to OIMUtils.getOrgKey because I don't have all classes here.After that pls remove the method below.
 
String orgKey = getOrgKey(Constants.ORG_ENTS);
 
// Get all object assigned to the above Organization that have the given MD name as prefix in descriptive field
 
logger.info("|||================BEFORE NEW SEARCH CRITERIA=================|||");
 
Map<String, String> searchCriteria = new HashMap<String, String>();
 
logger.info( "Part1:"+searchCriteria);
 
//Provide SearchCriteria
 
searchCriteria.put("Process Instance.Descriptive Data", "*");//Organizations.Field.Parameter Value
 
logger.info("Part1:"+searchCriteria+"  X="+orgKey+" OrgKey:"+orgKey);
 
tcResultSet rsltSet = poIntf.findObjects("Revoke", new String[] { orgKey }, "O", searchCriteria);
 
logger.info("Part1:"+searchCriteria+" ResultSet:  "+rsltSet);
 
System.out.println("TOTAL VALUE NEW RESULTSET:"+rsltSet.getTotalRowCount());
 
for (int i=0; i<rsltSet.getRowCount(); i++){
 
rsltSet.goToRow(i);
 
logger.info("Part1:"+i);
 
//list.add(rsltSet.getStringValue(field));
 
logger.info("Part1:Process Instance.Descriptive Data:"+rsltSet.getStringValue("Process Instance.Descriptive Data"));
 
logger.info("Part1:Objects.Name:"+rsltSet.getStringValue("Objects.Name"));
 
logger.info("Part1:Process Instance.Key:"+rsltSet.getStringValue("Process Instance.Key"));
 
if(checkIfFormExists(rsltSet.getLongValue("Process Instance.Key"))){
 
parentFormDef = f.getProcessFormData(rsltSet.getLongValue("Process Instance.Key"));
 
logger.info( "Part2:COUNT TOTAL:"+parentFormDef.getTotalRowCount());
 
parentFormDef.goToRow (0);
 
list.add(parentFormDef.getStringValue(field));
 
logger.info("Part2:VALUE ADDED INTO LIST(Collections):"+parentFormDef.getStringValue(field));
 
}
 
}
 
parentFormDef = f.getProcessFormData(orckey);
 
logger.info("===============================================================================================");
 
logger.info("============COLUMNS===============");
 
String columns[]= parentFormDef.getColumnNames();
 
logger.info("============CHILD DATA FORM===============");
 
for( String column : columns ) {
 
logger.info( "COLUMN NAME:"+column );
 
}
 
logger.info("===============================================================================================");
 
//Check if the value is not unique.
 
if(list.contains(value))
 
uniqueCheck=true;
 
//throw new Exception(OIMConstants.ENT_ASSINGMENT_ERROR);
 
logger.info("HAVE MORE RECORDS:"+uniqueCheck);
 
logger.info("END");
 
}catch (Exception e) {
 
e.printStackTrace();
 
System.out.println("XX:ERROR E:"+e);
 
}finally {
 
f.close();
 
}
 
return uniqueCheck;
 
}
 
/**
 
* Check if FormData exists
 
* @param prInstanceKey --> process instance key
 
* @return true of false
 
* @throws Thor.API.Exceptions.tcFormNotFoundException || Exception
 
*/
 
public boolean checkIfFormExists(long prInstanceKey){
 
tcResultSet dataFormDef;
 
f = Platform.getService(tcFormInstanceOperationsIntf.class);
 
try{
 
dataFormDef = f.getProcessFormData(prInstanceKey);
 
}catch(Thor.API.Exceptions.tcFormNotFoundException s){
 
return false;
 
}catch(Exception e){
 
e.printStackTrace();
 
System.out.println("XX:ERROR E:"+e);
 
return false;
 
}
 
return true;
 
}
 
/**
 
* Contigence plan if first method using APIS did not work properly
 
* Check ||| Collect information from ParentID or childID
 
* @param object --> process form table name
 
* @param field  --> field that should be unique
 
* @param value  --> that need to be checked
 
* @return
 
* @throws Exception
 
*/
 
public boolean checkUniqueValue(String object, String field, String value) throws Exception {
 
try {
 
logger.info( "Running checkUniqueValue Object:"+object+" FIELD:"+field+" VALUE:"+value);
 
//writing a SQL to check(count) how many values are into the object(table) requested
 
String SQL_CHECK_IF_VALUE_EXISTS =
 
"select count("+field+
 
") as count from "+object+
 
" where "+field+
 
"='"+value+"'";
 
tcDataSet dataSet = new tcDataSet();
 
//tcDataProvider = dataSet.getDataBase();
 
System.out.println("CHECK count SQL:"+SQL_CHECK_IF_VALUE_EXISTS);
 
System.out.println("tcDataProvider:"+tcDataProviderObj);
 
logger.debug(" Sql Query is : "+SQL_CHECK_IF_VALUE_EXISTS);
 
dataSet.setQuery(tcDataProviderObj, SQL_CHECK_IF_VALUE_EXISTS);
 
System.out.println("1:SETQUERY");
 
dataSet.executeQuery();
 
System.out.println("2:EXECUTEQUERY");
 
//String columnValues = dataSet.getColumnValues();
 
dataSet.next();
 
System.out.println("3:GETTING COUNT VALUE");
 
countValue = dataSet.getInt("count");
 
System.out.println("4:COLUMN VALUE count SQL:"+countValue);
 
if(countValue>=1){
 
uniqueCheck=true;
 
System.out.println("NOT UNIQUE VALUE ||| RAISE AN EXCEPTION");
 
throw new Exception(OIMConstants.ENT_ASSINGMENT_ERROR);
 
}
 
}catch (Exception e) {
 
e.printStackTrace();
 
System.out.println("XX:ERROR E:"+e);
 
}finally {
 
f.close();
 
}
 
return uniqueCheck;
 
}
You can also see an example of Event Handler that my friend Daniel did on this site:
http://fusionsecurity.blogspot.com/2011/09/oim-11g-event-handler-example.html
Just be careful when you develop an event handler because if you do some bad coding it could be a disaster into OIM performance.
I hope this helps,
Thiago Leoncio