SearchScript.groovy revision db4f02cbee52b92fd37a39aeee44dcd2272bc99c
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2015 ForgeRock AS. 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
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Version 1.0
* Author ForgeRock
*/
/**
* Built-in accessible objects
**/
// OperationType is SEARCH for this script
// The configuration class created specifically for this connector
// Default logging facility
// The objectClass of the object to be searched, e.g. ACCOUNT or GROUP
// The search filter for this operation
// Additional options for this operation
def whereParams = []
// Set where and whereParams if they have been passed in the request for paging
// The timestamp and id are for this example only.
// The user can use their own properties to sort on.
// For paging it is important that the properties that you use must identify
// a distinct set of pages for each iteration of the
// pagedResultsCookie, which can be decided by last record of the previous set.
where = " WHERE timestamp >= ? AND id > ? "
}
// Determine what properties will be used to sort the query
} else {
}
}
} else {
orderBy = ""
}
}
// keep track of lastTimestamp and lastId so we can
// use it for the next request to do paging
//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__" : "id",
"__NAME__": "name"
],
"__ACCOUNT__" : [
"__UID__" : "id",
"__NAME__": "uid"
],
"__GROUP__" : [
"__UID__" : "id",
"__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 ? ">" : "<="} ?'
];
// 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 {
if (fieldMap[objectClass.objectClassValue] && fieldMap[objectClass.objectClassValue][queryObj.get("left")]) {
}
} else {
}
}
}
}
switch (objectClass) {
case ObjectClass.ACCOUNT:
handler {
}
}
}
SELECT
u.id,
u.uid,
u.fullname,
u.firstname,
u.lastname,
u.email,
u.organization,
u.timestamp,
c.year,
c.make,
c.model
FROM
users u
LEFT OUTER JOIN
car c
ON c.users_id = u.id
${where}
${orderBy}
${limit}
"""
// new user row, process what we've collected
dataCollector = [
cars : [ ]
]
}
])
}
});
break
case ObjectClass.GROUP:
handler {
}
}
}
SELECT
g.id,
g.gid,
g.name,
g.description,
g.timestamp,
u.users_id
FROM
groups g
LEFT OUTER JOIN
groups_users u
ON
u.groups_id = g.id
${where}
${orderBy}
${limit}
// new user row, process what we've collected
dataCollector = [
users : [ ]
]
}
])
}
});
break
case ORG:
SELECT
id,
uid,
description,
timestamp
FROM
organizations
${where}
${orderBy}
${limit}
handler {
}
});
break
default:
}
// If paging is not wanted just return the default SearchResult object
return new SearchResult();
}