Go to main content
|
|
The following is a sample groovy script for performing lookup field synchronization.
The Lookup field procedures are called as follows:
st = conn.prepareCall("{call GET_ROLES(?)}");
st = conn.prepareCall("{call GET_GROUPS(?)}");
The procedure for GET_ROLES is as follows:
create or replace PROCEDURE GET_ROLES ( user_cursor OUT TYPES.cursorType ) AS BEGIN OPEN user_cursor FOR SELECT ROLENAME,ROLEID from ROLES; END GET_ROLES;
The procedure for GET_GROUPS is as follows:
create or replace PROCEDURE GET_GROUPS ( user_cursor OUT TYPES.cursorType ) AS BEGIN OPEN user_cursor FOR SELECT GROUPNAME,GROUPID from GROUPS; END GET_GROUPS;
Register the lookup field synchronization script as follows:
import org.identityconnectors.framework.common.objects.*;
rs = null;
st = null;
try {
System.out.println("[Lookup] Lookup Recon timing::"+ timing);
System.out.println("[Lookup] Attributes to Get::"+ ATTRS_TO_GET);
// This script is common for all lookups. Read the timing ( input) and return the data accordingly
// The format of timing is : executeQuery:<objectclass>
String codekey = ATTRS_TO_GET[0];
String decodekey = ATTRS_TO_GET[1];
if( timing.equals("executeQuery:Role"))
{
System.out.println("[Lookup] Getting Roles.");
st = conn.prepareCall("{call GET_ROLES(?)}");
}
else
{
System.out.println("[Lookup] Getting Groups.");
st = conn.prepareCall("{call GET_GROUPS(?)}"); }
st.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
st.execute();
rs = st.getObject(1);
while (rs.next()) {
cob = new ConnectorObjectBuilder();
Attribute codeattr= AttributeBuilder.build(decodekey,rs.getString(2));
Attribute decodeattr= AttributeBuilder.build(codekey,rs.getString(1));
cob.addAttribute(codeattr);
cob.addAttribute(decodeattr);
cob.setUid(rs.getString(2));
cob.setName(rs.getString(2));
handler.handle(cob.build());
} } finally {
if( null != rs)
rs.close();
if( null != st)
st.close();
}