<commit_before>package ie.festivals

import grails.converters.JSON
import grails.plugin.cache.CacheEvict
import grails.plugin.cache.Cacheable
import grails.plugin.geocode.GeocodingException
import grails.plugin.geocode.Point
import grails.plugins.springsecurity.Secured
import grails.util.GrailsUtil
import grails.web.JSONBuilder
import ie.festivals.command.AddRatingCommand
import ie.festivals.command.CalendarEventCommand
import ie.festivals.command.FestivalFilterCommand
import ie.festivals.enums.FestivalSource
import ie.festivals.enums.FestivalType
import ie.festivals.enums.Priority
import ie.festivals.enums.RatingType
import ie.festivals.map.MapFocalPoint
import ie.festivals.notify.FestivalSubscription
import ie.festivals.notify.NotificationService
import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.plugin.geocode.GeocodingService

import javax.servlet.http.HttpServletResponse

class FestivalController extends AbstractController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    static defaultAction = "map"

    private static final MAX_REMINDER_DAYS = 10
    private static final DEFAULT_ZOOM_LEVEL = 7

    @Lazy
    private String dateFormat = grailsApplication.config.festival.dateFormat

    def springSecurityService

    ArtistService artistService
    FestivalService festivalService
    GeocodingService geocodingService
    GrailsApplication grailsApplication
    UserRegistrationService userRegistrationService
    NotificationService notificationService

    def list(FestivalFilterCommand command) {

        def festivals = festivalService.findAll(
                freeOnly: command.freeOnly,
                futureOnly: command.futureOnly,
                countryCode: command.location.countryCode,
                types: command.types)

        [festivalInstanceList: festivals, command: command]
    }

    @Secured(['ROLE_USER', 'ROLE_ADMIN'])
    def create() {
        [festivalInstance: new Festival()]
    }

    private guessLocationIfNecessary(Festival festival) {

        // To determine if lat/long were provided, read the values from params rather than festival, because
        // if non-numeric values are provided, the binding to festival will have failed
        boolean locationMissing = !params.latitude && !params.longitude
        String fullAddress = festival.fullAddress

        if (fullAddress && locationMissing) {
            try {
                Point location = geocodingService.getPoint(fullAddress)
                if (location) {
                    festival.latitude = location.latitude
                    festival.longitude = location.longitude
                } else {
                    log.warn "failed to guess lat/long coordinates of address '$fullAddress'"
                }<commit_msg>fixes #19<commit_after>package ie.festivals

import grails.converters.JSON
import grails.plugin.cache.CacheEvict
import grails.plugin.cache.Cacheable
import grails.plugin.geocode.GeocodingException
import grails.plugin.geocode.Point
import grails.plugins.springsecurity.Secured
import grails.util.GrailsUtil
import grails.web.JSONBuilder
import ie.festivals.command.AddRatingCommand
import ie.festivals.command.CalendarEventCommand
import ie.festivals.command.FestivalFilterCommand
import ie.festivals.enums.FestivalSource
import ie.festivals.enums.FestivalType
import ie.festivals.enums.Priority
import ie.festivals.enums.RatingType
import ie.festivals.map.MapFocalPoint
import ie.festivals.notify.FestivalSubscription
import ie.festivals.notify.NotificationService
import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.plugin.geocode.GeocodingService

import javax.servlet.http.HttpServletResponse

class FestivalController extends AbstractController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    static defaultAction = "map"

    private static final MAX_REMINDER_DAYS = 10
    private static final DEFAULT_ZOOM_LEVEL = 7

    @Lazy
    private String dateFormat = grailsApplication.config.festival.dateFormat

    def springSecurityService

    ArtistService artistService
    FestivalService festivalService
    GeocodingService geocodingService
    GrailsApplication grailsApplication
    UserRegistrationService userRegistrationService
    NotificationService notificationService

    def list(FestivalFilterCommand command) {

        def festivals = festivalService.findAll(
                freeOnly: command.freeOnly,
                futureOnly: command.futureOnly,
                countryCode: command.location.countryCode,
                types: command.types)

        // If command.types is bound to null by a URL such as /festival/list, the query will include all festival types.
        // Set command.types to all types to ensure that the selected types in the filter match the query's defaults
        command.types = command.types ?: FestivalType.values()
        [festivalInstanceList: festivals, command: command]
    }

    @Secured(['ROLE_USER', 'ROLE_ADMIN'])
    def create() {
        [festivalInstance: new Festival()]
    }

    private guessLocationIfNecessary(Festival festival) {

        // To determine if lat/long were provided, read the values from params rather than festival, because
        // if non-numeric values are provided, the binding to festival will have failed
        boolean locationMissing = !params.latitude && !params.longitude
        String fullAddress = festival.fullAddress

        if (fullAddress && locationMissing) {
            try {
                Point location = geocodingService.getPoint(fullAddress)
                if (location) {
                    festival.latitude = location.latitude
                    festival.longitude = location.longitude
                } else {
                    log.warn "failed to guess lat/long coordinates of address '$fullAddress'"
                }
{'fraction_non_alphanumeric': 0.06582278481012659, 'fraction_numerical': 0.001350210970464135, 'mean_word_length': 3.33187134502924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7248236', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1482, 'n_words': 387}