import at.clockwork.security.domain.*

import at.clockwork.transfer.gwtTransfer.client.enumeration.ReportDefaultItemsEnum
import at.clockwork.transfer.gwtTransfer.client.enumeration.ReportDefaultStartEndDateEnum
import at.clockwork.transfer.gwtTransfer.client.enumeration.ReportDefaultStartEndTimeEnum

import at.clockwork.transfer.gwtTransfer.client.constants.ReportRoleConstant

import grails.util.Holders

class UpdateScriptService {

	def reportRoleWriteService = Holders.grailsApplication.mainContext.getBean 'reportRoleWriteService'

	def run(def connection, def dataSourceFields) {

        int counter = 0
        ReportRole.findAllWhere(deleted:false).each { ReportRole it ->

            it.defaultDate = ReportDefaultStartEndDateEnum.TODAY
            it.defaultTime = ReportDefaultStartEndTimeEnum.NO_TIME
            it.defaultDateTime = ReportDefaultStartEndDateEnum.TODAY

            if (it.selectTimeInterval)
                it.defaultTimeInterval = 60
            else
                it.defaultTimeInterval = 0

            if (it.selectPersonCategory)
                it.defaultPersonCategories = ReportDefaultItemsEnum.ALL_ITEMS
            else
                it.defaultPersonCategories = ReportDefaultItemsEnum.NO_ITEM

            if (it.selectPerson)
                it.defaultPersons = ReportDefaultItemsEnum.ALL_ITEMS
            else
                it.defaultPersons = ReportDefaultItemsEnum.NO_ITEM

            if (it.selectDeactivatedPerson)
                it.defaultDeactivatedPersons = ReportDefaultItemsEnum.ALL_ITEMS
            else
                it.defaultDeactivatedPersons = ReportDefaultItemsEnum.NO_ITEM

            it.defaultTimeTimeTypes = ReportDefaultItemsEnum.NO_ITEM

            it.defaultPersonTypes = ReportDefaultItemsEnum.NO_ITEM

            reportRoleWriteService.save(it)

        }

		true

	}
}