import at.clockwork.common.domain.*
import at.clockwork.generated.service.*
import at.clockwork.system.domain.*

import grails.util.Holders

class UpdateScriptService {

	def trigger2OperatorTypeWriteService = Holders.grailsApplication.mainContext.getBean 'trigger2OperatorTypeWriteService'
	def trigger2OperatorType2PersonWhitelistWriteService = Holders.grailsApplication.mainContext.getBean 'trigger2OperatorType2PersonWhitelistWriteService'
	def trigger2OperatorType2PersonBlacklistWriteService = Holders.grailsApplication.mainContext.getBean 'trigger2OperatorType2PersonBlacklistWriteService'
	def trigger2OperatorType2PersonCategoryWhitelistWriteService = Holders.grailsApplication.mainContext.getBean 'trigger2OperatorType2PersonCategoryWhitelistWriteService'
	def trigger2OperatorType2PersonCategoryBlacklistWriteService = Holders.grailsApplication.mainContext.getBean 'trigger2OperatorType2PersonCategoryBlacklistWriteService'

	def run(def connection, def dataSourceFields) {

        TriggerReport2OperatorType.findAll().each { triggerReport2OperatorType ->

            Trigger2OperatorType trigger2OperatorType = new Trigger2OperatorType(
                trigger:triggerReport2OperatorType.trigger,
                operatorType:triggerReport2OperatorType.operatorType,
                personCategory:triggerReport2OperatorType.personCategory,
                generalValidation:triggerReport2OperatorType.generalValidation,
                startDate:triggerReport2OperatorType.startDate,
                endDate:triggerReport2OperatorType.endDate,
                deleted:triggerReport2OperatorType.deleted
            )
            trigger2OperatorTypeWriteService.save(trigger2OperatorType)

            TriggerReport2OperatorType2PersonWhitelist.findAll().each { triggerReport2OperatorType2PersonWhitelist ->
                trigger2OperatorType2PersonWhitelistWriteService.save(
                    new Trigger2OperatorType2PersonWhitelist(
                        trigger2OperatorType:trigger2OperatorType,
                        person:triggerReport2OperatorType2PersonWhitelist.person
                    )
                )
            }

            TriggerReport2OperatorType2PersonBlacklist.findAll().each { triggerReport2OperatorType2PersonBlacklist ->
                trigger2OperatorType2PersonBlacklistWriteService.save(
                    new Trigger2OperatorType2PersonBlacklist(
                        trigger2OperatorType:trigger2OperatorType,
                        person:triggerReport2OperatorType2PersonBlacklist.person
                    )
                )
            }

            TriggerReport2OperatorType2PersonCategoryWhitelist.findAll().each { triggerReport2OperatorType2PersonCategoryWhitelist ->
                trigger2OperatorType2PersonCategoryWhitelistWriteService.save(
                    new Trigger2OperatorType2PersonCategoryWhitelist(
                        trigger2OperatorType:trigger2OperatorType,
                        personCategory:triggerReport2OperatorType2PersonCategoryWhitelist.personCategory
                    )
                )
            }

            TriggerReport2OperatorType2PersonCategoryBlacklist.findAll().each { triggerReport2OperatorType2PersonCategoryBlacklist ->
                trigger2OperatorType2PersonCategoryBlacklistWriteService.save(
                    new Trigger2OperatorType2PersonCategoryBlacklist(
                        trigger2OperatorType:trigger2OperatorType,
                        personCategory:triggerReport2OperatorType2PersonCategoryBlacklist.personCategory
                    )
                )
            }

        }

		true
	}
}