次に、作成プロビジョニング操作を実行するためのサンプルのgroovyスクリプトを示します。
次のように作成スクリプトを登録します。
import java.sql.PreparedStatement; import org.identityconnectors.framework.common.objects.*; import java.text.*; // START HERE System.out.println("[Create-Groovy] Attributes::"+attributes); //Get all the attributes from script argument String uid = attributes.get("__NAME__")!=null? attributes.get("__NAME__").getValue().get(0):null; String firstName=attributes.get("FIRSTNAME")!=null? attributes.get("FIRSTNAME").getValue().get(0):null; String lastName=attributes.get("LASTNAME")!=null? attributes.get("LASTNAME").getValue().get(0):null; String email=attributes.get("EMAIL")!=null? attributes.get("EMAIL").getValue().get(0):null; String description=attributes.get("DESCRIPTION")!=null? attributes.get("DESCRIPTION").getValue().get(0):null; salary=attributes.get("SALARY")!=null? attributes.get("SALARY").getValue().get(0):null; joindate = attributes.get("JOININGDATE")!=null? attributes.get("JOININGDATE").getValue().get(0):null; enableValue = attributes.get("__ENABLE__")!=null? attributes.get("__ENABLE__").getValue().get(0):true; PreparedStatement createStmt = null; try { //Initialize the prepare statement to insert the data into database table createStmt = conn.prepareStatement("INSERT INTO USERINFO(USERID,FIRSTNAME,LASTNAME,EMAIL,DESCRIPTION,SALARY,JOININGDATE,STATUS) VALUES(?,?,?,?,?,?,?,?)"); //Set the input parameters createStmt.setString(1, uid); createStmt.setString(2, firstName); createStmt.setString(3, lastName); createStmt.setString(4, email); createStmt.setString(5, description); createStmt.setBigDecimal(6, salary); dateStr = null; //Convert the joindate into oracle date format if( joindate != null) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S"); java.util.Date date= df.parse(joindate); DateFormat targetFormat = new SimpleDateFormat("dd-MMM-yy"); dateStr = targetFormat.format(date); } createStmt.setString(7,dateStr); if(enableValue) createStmt.setString(8,"Enabled"); else createStmt.setString(8,"Disabled"); //Execute sql statement createStmt.executeUpdate(); } finally { //close the sql statements if (createStmt != null) createStmt.close(); } System.out.println("[Create] Created User::"+uid); //Return Uid from the script return new Uid(uid);