import at.clockwork.common.domain.*
import at.clockwork.common.generalValidation.domain.*

import grails.util.Holders

class UpdateScriptService {

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

	def run(def connection, def dataSourceFields) {

        GeneralValidation.findAllWhere(deleted:false).each { GeneralValidation itGeneralValidation ->

            if (
                itGeneralValidation.allTerminals ||
                GeneralValidation2TerminalWhitelist.findAllWhere( generalValidation : itGeneralValidation ).size() > 0 ||
                GeneralValidation2TerminalCategoryWhitelist.findAllWhere( generalValidation : itGeneralValidation ).size() > 0 ||
                GeneralValidation2TerminalCategoryBlacklist.findAllWhere( generalValidation : itGeneralValidation ).size() > 0
            ) {

                itGeneralValidation.allDatafoxPersonAccessSchedules = true
                itGeneralValidation.allDatafoxDoorAccessSchedules = true

                itGeneralValidation.allKeyflexPersonAccessSchedules = true
                itGeneralValidation.allKeyflexDoorAccessSchedules = true

                itGeneralValidation.allGantnerPersonAccessSchedules = true
                itGeneralValidation.allGantnerDoorAccessSchedules = true

                itGeneralValidation.allChiploxPersonAccessSchedules = true
                itGeneralValidation.allChiploxDoorAccessSchedules = true

                itGeneralValidation.allSeccorPersonAccessSchedules = true
                itGeneralValidation.allSeccorDoorAccessSchedules = true

                generalValidationWriteService.save(itGeneralValidation)

            }

        }

		true

	}
}