DeleteScript.groovy revision ad2ac0328cdf934b6e71d53b83823393bb72e669
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington/*
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington *
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * Copyright (c) 2010 ForgeRock Inc. All Rights Reserved
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington *
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * The contents of this file are subject to the terms
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * of the Common Development and Distribution License
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * (the License). You may not use this file except in
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * compliance with the License.
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington *
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * You can obtain a copy of the License at
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * http://www.opensource.org/licenses/cddl1.php or
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * OpenIDM/legal/CDDLv1.0.txt
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * See the License for the specific language governing
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * permission and limitations under the License.
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington *
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * When distributing Covered Code, include this CDDL
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * Header Notice in each file and include the License file
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * at OpenIDM/legal/CDDLv1.0.txt.
716579c1eaca460b012b046afe7c50107eff7081David Luna * If applicable, add the following below the CDDL Header,
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * with the fields enclosed by brackets [] replaced by
716579c1eaca460b012b046afe7c50107eff7081David Luna * your own identifying information:
716579c1eaca460b012b046afe7c50107eff7081David Luna * "Portions Copyrighted 2010 [name of copyright owner]"
716579c1eaca460b012b046afe7c50107eff7081David Luna *
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington * $Id$
8d75f7fba11e555d87ff0f6f2a7504681c482e0bNeil Madden */
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunningtonimport groovy.sql.Sql;
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunningtonimport groovy.sql.DataSet;
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// Parameters:
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// The connector sends the following:
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// connection: handler to the SQL connection
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// action: a string describing the action ("DELETE" here)
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// log: a handler to the Log facility
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// objectClass: a String describing the Object class (__ACCOUNT__ / __GROUP__ / other)
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// options: a handler to the OperationOptions Map
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington// uid: String for the unique id that specifies the object to delete
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
716579c1eaca460b012b046afe7c50107eff7081David Lunalog.info("Entering "+action+" Script");
716579c1eaca460b012b046afe7c50107eff7081David Lunadef sql = new Sql(connection);
716579c1eaca460b012b046afe7c50107eff7081David Luna
716579c1eaca460b012b046afe7c50107eff7081David Lunaassert uid != null
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunningtonswitch ( objectClass ) {
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington case "__ACCOUNT__":
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington sql.execute("DELETE FROM Users where uid= ?",[uid])
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington break
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni case "__GROUP__":
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington sql.execute("DELETE FROM Groups where name= ?",[uid])
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington break
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington case "organization":
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington sql.execute("DELETE FROM Organizations where name= ?",[uid])
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington break
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington
8774cade81dfa90b972d8b855eb249ca2568b4ddPhill Cunnington default:
8774cade81dfa90b972d8b855eb249ca2568b4ddPhill Cunnington uid;
adc14d0be45af50dbde99eb71c21de3bc1ddb1c6Phill Cunnington}