<commit_before>package fedreg.workflow

/* Used Quartz jobs here so we can take advantange of serialization and possibly even clustering in the future */
class ExecuteJob {
    static triggers = {}
	def sessionRequired = true
	def grailsApplication

    def execute(def context) {		
        def serviceID = context.mergedJobDataMap.get('service')
		def method = context.mergedJobDataMap.get('method')
		def scriptID = context.mergedJobDataMap.get('script')
		def env = context.mergedJobDataMap.get('env')
		
		// We're invoking a prebuilt service
		if(serviceID) {
			def service = grailsApplication.mainContext.getBean(serviceID);
			
			if(service)
				service."$method"(env)
			else
				log.error "Attempt to execute workflow that references service named $serviceID. Unable to locate service, no execution has taken place"
		}
		else {
			// We're invoking a script
			def workflowScript = WorkflowScript.findByName(scriptID)
			
			if(workflowScript) {
				Binding binding = new Binding();
				binding.setVariable("env", env);
				binding.setVariable("grailsApplication", grailsApplication);
			
				def script = new GroovyShell().parse(workflowScript.definition)
				script.binding = binding
				script.run()
			}
			else
				log.error "Attempt to execute workflow that references script named $scriptID. Unable to locate script, no execution has taken place"
		}
		<commit_msg>Switched GroovyShell instance to use Grails classloader to ensure dynamic methods such as save on domain objects etc are available for use<commit_after>package fedreg.workflow

/* Used Quartz jobs here so we can take advantange of serialization and possibly even clustering in the future */
class ExecuteJob {
    static triggers = {}
	def sessionRequired = true
	def grailsApplication

    def execute(def context) {		
        def serviceID = context.mergedJobDataMap.get('service')
		def method = context.mergedJobDataMap.get('method')
		def scriptID = context.mergedJobDataMap.get('script')
		def env = context.mergedJobDataMap.get('env')
		
		// We're invoking a prebuilt service
		if(serviceID) {
			def service = grailsApplication.mainContext.getBean(serviceID);
			
			if(service)
				service."$method"(env)
			else
				log.error "Attempt to execute workflow that references service named $serviceID. Unable to locate service, no execution has taken place"
		}
		else {
			// We're invoking a script
			def workflowScript = WorkflowScript.findByName(scriptID)
			
			if(workflowScript) {
				Binding binding = new Binding()
				binding.setVariable("env", env)
				binding.setVariable("grailsApplication", grailsApplication)
				binding.setVariable("ctx", grailsApplication.mainContext)
				
				def script = new GroovyShell(grailsApplication.classLoader, binding).parse(workflowScript.definition)
				script.binding = binding
				script.run()
			}
			else
				log.error "Attempt to execute workflow that references script named $scriptID. Unable to locate script, no execution has taken place"
		}
		
{'fraction_non_alphanumeric': 0.08224674022066199, 'fraction_numerical': 0.0, 'mean_word_length': 3.929159802306425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5012827', 'n_tokens_mistral': 975, 'n_tokens_neox': 794, 'n_words': 262}