SyncScript.groovy revision 27729d5a6fae13e145aa4829793bd240ff10373a
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (c) 2010 ForgeRock Inc. All Rights Reserved
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file are subject to the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (the License). You may not use this file except in
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * compliance with the License.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You can obtain a copy of the License at
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * See the License for the specific language governing
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * permission and limitations under the License.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * When distributing Covered Code, include this CDDL
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Header Notice in each file and include the License file
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * If applicable, add the following below the CDDL Header,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * with the fields enclosed by brackets [] replaced by
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * your own identifying information:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * "Portions Copyrighted 2010 [name of copyright owner]"
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// Parameters:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// The connector sends the following:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// connection: handler to the SQL connection
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// objectClass: a String describing the Object class (__ACCOUNT__ / __GROUP__ / other)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// action: a string describing the action ("SYNC" or "GET_LATEST_SYNC_TOKEN" here)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// log: a handler to the Log facility
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// options: a handler to the OperationOptions Map (null if action = "GET_LATEST_SYNC_TOKEN")
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// token: a handler to an Object representing the sync token (null if action = "GET_LATEST_SYNC_TOKEN")
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// if action = "GET_LATEST_SYNC_TOKEN", it must return an object representing the last known
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// sync token for the corresponding ObjectClass
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// if action = "SYNC":
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// A list of Maps . Each map describing one update:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// Map should look like the following:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "token": <Object> token object (could be Integer, Date, String) , [!! could be null]
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "operation":<String> ("CREATE_OR_UPDATE"|"DELETE"),
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "uid":<String> uid (uid of the entry) ,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "previousUid":<String> prevuid (This is for rename ops) ,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "password":<String> password (optional... allows to pass clear text password if needed),
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync// "attributes":Map<String,List> of attributes name/values
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncif (action.equalsIgnoreCase("GET_LATEST_SYNC_TOKEN")) {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync row = sql.firstRow("select timestamp from Users order by timestamp desc")
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync log.ok("Get Latest Sync Token script: last token is: "+row["timestamp"])
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync // We don't wanna return the java.sql.Timestamp, it is not a supported data type
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync // Get the 'long' version
{result.add([operation:"CREATE_OR_UPDATE", uid:it.uid, token:it.timestamp.getTime(), attributes:[firstname:it.firstname, lastname:it.lastname, email:it.email]])}
return result;
return null;