SearchScript.groovy revision 4b3769ce483ece06f60f983193712492b920144f
/*
*
* Copyright (c) 2010-2014 ForgeRock Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at OpenIDM/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted 2010 [name of copyright owner]"
*
* $Id$
*/
// Parameters:
// The connector sends the following:
// connection: handler to the SQL connection
// objectClass: a String describing the Object class (__ACCOUNT__ / __GROUP__ / other)
// action: a string describing the action ("SEARCH" here)
// log: a handler to the Log facility
// options: a handler to the OperationOptions Map
// query: a handler to the Query Map
//
// The Query map describes the filter used.
//
// query = null : then we assume we fetch everything
//
// query = [ operation: "AND", left: query1, right: query2 ]
// query = [ operation: "OR", left: query1, right: query2 ]
//
// Returns: A list of Maps. Each map describing one row.
// !!!! Each Map must contain a '__UID__' and '__NAME__' attribute.
// This is required to build a ConnectorObject.
//Need to handle the __UID__ and __NAME__ in queries - this map has entries for each objectType,
//and is used to translate fields that might exist in the query object from the ICF identifier
//back to the real property name.
"organization": [
"__UID__": "name",
"__NAME__": "name"
],
"__ACCOUNT__": [
"__UID__": "uid",
"__NAME__": "uid"
],
"__GROUP__": [
"__UID__": "name",
"__NAME__": "name"
]
]
def whereTemplates = [
CONTAINS:'$left ${not ? "NOT " : ""}LIKE ?',
ENDSWITH:'$left ${not ? "NOT " : ""}LIKE ?',
STARTSWITH:'$left ${not ? "NOT " : ""}LIKE ?',
EQUALS:'$left ${not ? "<>" : "="} ?',
GREATERTHAN:'$left ${not ? "<=" : ">"} ?',
GREATERTHANOREQUAL:'$left ${not ? "<" : ">="} ?',
LESSTHAN:'$left ${not ? ">=" : "<"} ?',
LESSTHANOREQUAL:'$left ${not ? ">" : "<="} ?'
];
def whereParams = []
// this closure function recurses through the (potentially complex) query object in order to build an equivalent SQL 'where' expression
queryParser = { queryObj ->
return "(" + queryParser(queryObj.right) + " " + queryObj.operation + " " + queryParser(queryObj.left) + ")";
} else {
}
} else {
}
}
}
// We can use Groovy template engine to generate our custom SQL queries
}
switch ( objectClass ) {
case "__ACCOUNT__":
])
}
break
case "__GROUP__":
])
}
break
case "organization":
])
}
break
default:
}
return result;