From e57c21bde03d1f64fdb403bffc1bee2e04d0b07d Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 30 Aug 2019 15:57:20 +0200 Subject: [PATCH] Fix SIS Persons search script It failed with bucketed imports. --- .../res/sis-persons/SearchScript.groovy | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy b/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy index 1226bdf..1adcfad 100644 --- a/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy +++ b/demo/complex2s/midpoint_server/container_files/mp-home/res/sis-persons/SearchScript.groovy @@ -60,12 +60,11 @@ log.info("Entering "+action+" Script"); def sql = new Sql(connection); def result = [] def where = ""; +def sqlParams = null switch ( objectClass ) { case "__ACCOUNT__": - sqlParams = [:] - uidColumn = 'uid' nameColumn = 'uid' @@ -94,6 +93,7 @@ switch ( objectClass ) { break; } + sqlParams = [:] sqlParams.put(left, right) right = ":" + left @@ -111,25 +111,39 @@ switch ( objectClass ) { ] def wt = whereTemplates.get(operation) - def binding = [left: left, right: right, not: query.get("not")] - def template = engine.createTemplate(wt).make(binding) - where = ' where ' + template.toString() - - log.info("Where clause: {0}, with parameters {1}", where, sqlParams) + if (wt != null) { + def binding = [left: left, right: right, not: query.get("not")] + def template = engine.createTemplate(wt).make(binding) + where = ' where ' + template.toString() + log.info("Where clause: {0}, with parameters {1}", where, sqlParams) + } else { + log.warn('Unsupported query: {0}, continuing without WHERE clause (worsening the performance)', query) + sqlParams = null + where = '' + } } q = 'select uid, surname, givenName, fullName, mail from SIS_PERSONS' + where log.info('query = {0}', query) log.info('sql = {0}', q) - sql.eachRow(sqlParams, q, {result.add([ - __UID__:it.uid, - __NAME__:it.uid, - uid:it.uid, - surname:it.surname, - givenName:it.givenName, - fullName:it.fullName, - mail:it.mail])} ); + log.info('sqlParams = {0}', sqlParams) + + def processRow = { row -> result.add([ + __UID__:row.uid, + __NAME__:row.uid, + uid:row.uid, + surname:row.surname, + givenName:row.givenName, + fullName:row.fullName, + mail:row.mail]) + } + + if (sqlParams != null) { + sql.eachRow(sqlParams, q, processRow) + } else { + sql.eachRow(q, processRow) + } break default: