次に、更新プロビジョニング操作を実行するためのサンプルのgroovyスクリプトを示します。
次のように更新スクリプトを登録します。
import org.identityconnectors.framework.common.objects.*; import java.text.*; import org.identityconnectors.framework.common.exceptions.*; System.out.println("[Update-Groovy] Atrributes::"+ attributes); /** During an Update operation,OIM sends the UID attribute along with updated attributes. Get all the values of attributes **/ String id = attributes.get("__UID__")!=null? attributes.get("__UID__").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; status = attributes.get("STATUS")!=null? attributes.get("STATUS").getValue().get(0):null; enableValue = attributes.get("__ENABLE__")!=null? attributes.get("__ENABLE__").getValue().get(0):true; //Throw exception if uid is null if(id==null) throw new ConnectorException("UID Cannot be Null"); stmt = null; try { //Create prepare statement to update the USERINFO table stmt = conn.prepareStatement("UPDATE USERINFO SET FIRSTNAME=COALESCE(?, FIRSTNAME),LASTNAME =COALESCE(?, LASTNAME), EMAIL= COALESCE(?, EMAIL),DESCRIPTION=COALESCE(?, DESCRIPTION),SALARY=COALESCE(?, SALARY),JOININGDATE=COALESCE(to_date(?,'dd-Mon-yy'), JOININGDATE),STATUS=COALESCE(?, STATUS) WHERE USERID =?"); //Set sql input parameters stmt.setString(1, firstName); stmt.setString(2, lastName); stmt.setString(3, email); stmt.setString(4, description); stmt.setBigDecimal(5, 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); } stmt.setString(6,dateStr); if(enableValue) stmt.setString(7,"Enabled"); else stmt.setString(7,"Disabled"); stmt.setString(8, id); stmt.executeUpdate(); } finally { if (stmt != null) stmt.close(); }; System.out.println("[Update] Updated user::"+ id); return new Uid(id);