
import at.clockwork.system.service.SystemConfigurationService
import at.clockwork.system.domain.*
import at.clockwork.singleton.*
import at.clockwork.common.enumeration.*
import at.clockwork.system.enumeration.*
import at.clockwork.transfer.gwtTransfer.client.enumeration.TriggerTypeEnum
import at.clockwork.transfer.gwtTransfer.client.enumeration.JobStartTypeEnum

import grails.util.Holders



class UpdateScriptService {

	def systemConfigurationService = Holders.grailsApplication.mainContext.getBean 'systemConfigurationService'
	def triggerWriteService = Holders.grailsApplication.mainContext.getBean 'triggerWriteService'

	def run(def connection, def dataSourceFields) {

		def systemConfigurations = SystemConfigurations.getInstance()

		if (systemConfigurations.getItem(53, "booleanValue") == true) {
			triggerWriteService.save(
				new Trigger(
					name:"SYNCHRONIZE_WITH_CLOCKWORK_FOXPRO",
					description:"SYNCHRONIZE_WITH_CLOCKWORK_FOXPRO",
					triggerTypeEnum:TriggerTypeEnum.SYNCHRONIZE_WITH_CLOCKWORK_FOXPRO,
					jobStartTypeEnum:JobStartTypeEnum.AUTOMATIC,
					cronDefinition:"0/10 * * * * ?"
				)
			)
		}
		systemConfigurationService.deleteByCwID(53)

		true
	}
}
