CreateScript.groovy revision 185941104719f48494a107996e17a23aad237c7d
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * Copyright (c) 2014 ForgeRock AS. All Rights Reserved
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * The contents of this file are subject to the terms
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * of the Common Development and Distribution License
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * (the License). You may not use this file except in
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * compliance with the License.
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * You can obtain a copy of the License at
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * See the License for the specific language governing
ccf9d4a5c6453fa9f8b839baeee25147865fbb7dJames Phillpotts * permission and limitations under the License.
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * When distributing Covered Code, include this CDDL
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste * Header Notice in each file and include the License file
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * at http://forgerock.org/license/CDDLv1.0.html
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * If applicable, add the following below the CDDL Header,
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * with the fields enclosed by brackets [] replaced by
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * your own identifying information:
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * "Portions Copyrighted [year] [name of copyright owner]"
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts * @author Gael Allioux <gael.allioux@forgerock.com>
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.forgerock.openicf.connectors.scriptedsql.ScriptedSQLConfiguration
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.forgerock.openicf.misc.scriptedcommon.OperationType
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.common.logging.Log
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.framework.common.objects.Attribute
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.framework.common.objects.AttributesAccessor
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.framework.common.objects.ObjectClass
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.framework.common.objects.OperationOptions
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsimport org.identityconnectors.framework.common.objects.Uid
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsdef createAttributes = new AttributesAccessor(attributes as Set<Attribute>)
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottsdef configuration = configuration as ScriptedSQLConfiguration
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpottslog.info("Entering " + operation + " Script");
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts "INSERT INTO users (uid,password,firstname,lastname,fullname,email,organization) values (?,sha1(?),?,?,?,?,?)",
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste createAttributes.hasAttribute("password") ? createAttributes.findString("firstname") : "",
7197110fbdb6deb7868581c455516161cbcf7e0fJaco Jooste createAttributes.hasAttribute("firstname") ? createAttributes.findString("firstname") : "",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts createAttributes.hasAttribute("lastname") ? createAttributes.findString("lastname") : "",
7197110fbdb6deb7868581c455516161cbcf7e0fJaco Jooste createAttributes.hasAttribute("fullname") ? createAttributes.findString("fullname") : "",
b9e697e180c323785bf1cb8a29f5ec6288da8ec4Jaco Jooste createAttributes.hasAttribute("email") ? createAttributes.findString("email") : "",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts createAttributes.hasAttribute("organization") ? createAttributes.findString("organization") : ""
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts retUid = new Uid(generatedKeys[0][0] as String)
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts "INSERT INTO car (users_id,year,make,model) VALUES (?,?,?,?)",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts "INSERT INTO groups (name,gid,description) values (?,?,?)",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts createAttributes.hasAttribute("gid") ? createAttributes.findString("gid") : "",
7197110fbdb6deb7868581c455516161cbcf7e0fJaco Jooste createAttributes.hasAttribute("description") ? createAttributes.findString("description") : "",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts retUid = new Uid(generatedKeys[0][0] as String)
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts "INSERT INTO groups_users (users_id,groups_id) SELECT id,? FROM users WHERE uid=?",
7197110fbdb6deb7868581c455516161cbcf7e0fJaco Jooste "INSERT INTO organizations (name ,description) values (?,?)",
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts createAttributes.hasAttribute("description") ? createAttributes.findString("description") : ""
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts return new Uid(generatedKeys[0][0] as String)
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts throw new UnsupportedOperationException(operation.name() + " operation of type:" +
ca7a323358dc50374d5f281355842fb7edb3983eJames Phillpotts objectClass.objectClassValue + " is not supported.")