import grails.util.Holders

class UpdateScriptService {

    /*
        z.B. Domainklasse AbsencePlanning wurde geaendert
        -------------------------------------------------
        folgendes Statement wurde aus der Domainklasse Absenceplanning geloescht
            static hasMany = [absencePlanningDetails: AbsencePlanningDetail]
        somit ist folgender Code nicht mehr gueltig: absencePlanning.absencePlanningDetails

        1) absencePlanning.absencePlanningDetails aendern auf
           absencePlanning.absencePlanningDetails -> AbsencePlanningDetail.findAllWhere( absencePlanning: absencePlanning, deleted: false )
        2) import at.clockwork.time.domain.AbsencePlanning
           import at.clockwork.time.domain.AbsencePlanningDetail

    */

	def scriptNotTransactionalService = Holders.grailsApplication.mainContext.getBean 'scriptNotTransactionalService'
	def informationTransactionalService = Holders.grailsApplication.mainContext.getBean 'informationTransactionalService'

	def run(def connection, def dataSourceFields) {

        [
            "absencePlanningDetails",
            "timeSpecificationDetails",
            "areas",
            "favorites",
            "doorStateDefinitionDetails",
            "doorStateVisualisationDetails",
            "doorStates",
            "negatedDoorStates",
            "additionalInfos",
            "negatedAdditionalInfos",
            "blacklistAreaCategories",
            "whitelistAreaCategories",
            "whitelistAreas",
            "groupDefinitionDetails",
            "sortDefinitionDetails"
//            "timeTimeTypeDefinitionDetails"
        ].each { String itSearchedText ->

            scriptNotTransactionalService.searchTextWithinScriptCode(itSearchedText).each { Map map ->

                informationTransactionalService.add( map.text ?: "text", map.date ?: (new Date()), "hasMany: " + (map.comment ?: "") )

            }

		}

		true

	}

}