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.defaultProjectCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultProjects = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultOrderCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultOrders = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultOrderItemCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultOrderItems = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultCostUnitCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultCostUnits = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultMachineCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultMachines = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultWorkplaceCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultWorkplaces = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultWorkprocessCategories = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultWorkprocesses = ReportDefaultItemsEnum.NO_ITEM

            it.defaultWorkTimeTypes = ReportDefaultItemsEnum.NO_ITEM
//            it.defaultArticles = ReportDefaultItemsEnum.NO_ITEM

            if (it.selectTerminal)
                it.defaultTerminals = ReportDefaultItemsEnum.ALL_ITEMS
            else
                it.defaultTerminals = ReportDefaultItemsEnum.NO_ITEM

            it.defaultEventTypes = ReportDefaultItemsEnum.NO_ITEM

            if (it.selectUser)
                it.defaultUsers = ReportDefaultItemsEnum.ALL_ITEMS
            else
                it.defaultUsers = ReportDefaultItemsEnum.NO_ITEM

            it.defaultOperatorTypes = ReportDefaultItemsEnum.NO_ITEM

            it.defaultOperationRoles = ReportDefaultItemsEnum.NO_ITEM

            it.defaultReportRoles = ReportDefaultItemsEnum.NO_ITEM

            reportRoleWriteService.save(it)

        }

		true

	}
}