355e5661379644c081271b23fa8b966a098a42d2Jon Branch/*
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Copyright (c) 2015 ForgeRock AS. All Rights Reserved
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * The contents of this file are subject to the terms
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * of the Common Development and Distribution License
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * (the License). You may not use this file except in
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * compliance with the License.
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * You can obtain a copy of the License at
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * http://forgerock.org/license/CDDLv1.0.html
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * See the License for the specific language governing
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * permission and limitations under the License.
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * When distributing Covered Code, include this CDDL
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Header Notice in each file and include the License file
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * at http://forgerock.org/license/CDDLv1.0.html
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * If applicable, add the following below the CDDL Header,
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * with the fields enclosed by brackets [] replaced by
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * your own identifying information:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * "Portions Copyrighted [year] [name of copyright owner]"
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Version {{version}}
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Author {{author}}
355e5661379644c081271b23fa8b966a098a42d2Jon Branch */
355e5661379644c081271b23fa8b966a098a42d2Jon Branchpackage org.forgerock.openicf.connectors.{{lower packageName}}
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.forgerock.openicf.connectors.{{lower packageName}}.{{packageName}}Configuration
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.forgerock.openicf.misc.scriptedcommon.OperationType
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.common.logging.Log
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.framework.common.objects.Uid
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.framework.common.objects.ObjectClass
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.framework.common.objects.OperationOptions
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.framework.common.exceptions.ConnectorException
355e5661379644c081271b23fa8b966a098a42d2Jon Branchimport org.identityconnectors.framework.common.objects.SyncToken
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch/**
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Built-in accessible objects
355e5661379644c081271b23fa8b966a098a42d2Jon Branch **/
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch// OperationType is SYNC or GET_LATEST_SYNC_TOKEN for this script
355e5661379644c081271b23fa8b966a098a42d2Jon Branchdef operation = operation as OperationType
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch// The configuration class created specifically for this connector
355e5661379644c081271b23fa8b966a098a42d2Jon Branchdef configuration = configuration as {{packageName}}Configuration
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch// Default logging facility
355e5661379644c081271b23fa8b966a098a42d2Jon Branchdef log = log as Log
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch// The objectClass of the object to be created, e.g. ACCOUNT or GROUP
355e5661379644c081271b23fa8b966a098a42d2Jon Branchdef objectClass = objectClass as ObjectClass
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
5478b1943fbf08b87ba05fb6bf14117049ed20e6Jon Branch// The handler for the result set is named 'handler' and does not need to be defined. Its formal type
5478b1943fbf08b87ba05fb6bf14117049ed20e6Jon Branch// is Closure<Boolean>.
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch/**
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Script action - Customizable
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * Retrieve all objects in the external source updated since token
355e5661379644c081271b23fa8b966a098a42d2Jon Branch *
355e5661379644c081271b23fa8b966a098a42d2Jon Branch * This script should use the handler to process the result set
355e5661379644c081271b23fa8b966a098a42d2Jon Branch **/
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch/* Log something to demonstrate this script executed */
355e5661379644c081271b23fa8b966a098a42d2Jon Branchlog.info("Sync script, operation = " + operation.toString());
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branchswitch (operation) {
355e5661379644c081271b23fa8b966a098a42d2Jon Branch case OperationType.SYNC:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch // A token representing the last modified time since which we should retrieve newer objects
355e5661379644c081271b23fa8b966a098a42d2Jon Branch def token = token as SyncToken
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch def tstamp = null
355e5661379644c081271b23fa8b966a098a42d2Jon Branch if (token != null) {
355e5661379644c081271b23fa8b966a098a42d2Jon Branch tstamp = new java.sql.Timestamp(token)
355e5661379644c081271b23fa8b966a098a42d2Jon Branch } else {
355e5661379644c081271b23fa8b966a098a42d2Jon Branch def today = new Date()
355e5661379644c081271b23fa8b966a098a42d2Jon Branch tstamp = new java.sql.Timestamp(today.time)
355e5661379644c081271b23fa8b966a098a42d2Jon Branch }
355e5661379644c081271b23fa8b966a098a42d2Jon Branch switch (objectClass) {
355e5661379644c081271b23fa8b966a098a42d2Jon Branch {{#objectTypes}}case {{objectClass}}:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch // Read all updated objects
355e5661379644c081271b23fa8b966a098a42d2Jon Branch break
355e5661379644c081271b23fa8b966a098a42d2Jon Branch {{/objectTypes}}
355e5661379644c081271b23fa8b966a098a42d2Jon Branch default:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch log.error("Sync script: objectClass " + objectClass + " is not handled by the Sync script")
355e5661379644c081271b23fa8b966a098a42d2Jon Branch throw new UnsupportedOperationException(operation.name() + " operation of type:" +
355e5661379644c081271b23fa8b966a098a42d2Jon Branch objectClass.objectClassValue + " is not supported.")
355e5661379644c081271b23fa8b966a098a42d2Jon Branch }
355e5661379644c081271b23fa8b966a098a42d2Jon Branch break;
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch case OperationType.GET_LATEST_SYNC_TOKEN:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch switch (objectClass) {
355e5661379644c081271b23fa8b966a098a42d2Jon Branch {{#objectTypes}}case {{objectClass}}:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch // Identify the most recent timestamp for this object type
355e5661379644c081271b23fa8b966a098a42d2Jon Branch break
355e5661379644c081271b23fa8b966a098a42d2Jon Branch {{/objectTypes}}
355e5661379644c081271b23fa8b966a098a42d2Jon Branch default:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch throw new UnsupportedOperationException(operation.name() + " operation of type:" +
355e5661379644c081271b23fa8b966a098a42d2Jon Branch objectClass.objectClassValue + " is not supported.")
355e5661379644c081271b23fa8b966a098a42d2Jon Branch }
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch // We don't want to return the java.sql.Timestamp, it is not a supported data type
355e5661379644c081271b23fa8b966a098a42d2Jon Branch // Get the 'long' version
355e5661379644c081271b23fa8b966a098a42d2Jon Branch return new java.sql.Timestamp(today.time).getTime();
355e5661379644c081271b23fa8b966a098a42d2Jon Branch
355e5661379644c081271b23fa8b966a098a42d2Jon Branch default:
355e5661379644c081271b23fa8b966a098a42d2Jon Branch throw new ConnectorException("SyncScript can not handle operation:" + operation.name())
355e5661379644c081271b23fa8b966a098a42d2Jon Branch}