Created
August 8, 2014 09:50
-
-
Save asyd/d618fa3b234b759ab6ee to your computer and use it in GitHub Desktop.
Use groovy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GroovyShell groovyShell = new GroovyShell(getClass().getClassLoader()); | |
Script groovyScript = null; | |
if (paramsImport.getGroovyScript() == null ) { | |
String groovyScriptName = "defaultUserMapping.groovy"; | |
groovyScript = groovyShell.parse(new InputStreamReader(this.getClass().getResourceAsStream("/" + groovyScriptName))); | |
} else { | |
try { | |
groovyScript = groovyShell.parse(new File(paramsImport.getGroovyScript())); | |
} catch (IOException exception) { | |
logger.error("Error while loading groovy script from {}: {}", paramsImport.getGroovyScript(), exception); | |
} | |
} | |
for (SearchResultEntry entry : users) { | |
ADUser currentUser = new ADUser(entry); | |
Binding groovyBinding = new Binding(); | |
groovyBinding.setVariable("jsonUsers", jsonUsers); | |
groovyBinding.setVariable("user", currentUser); | |
groovyBinding.setVariable("logger", logger); | |
try { | |
groovyScript.setBinding(groovyBinding); | |
Boolean isSuccess = (Boolean) groovyScript.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment