<commit_before>package au.org.ala.taxonoverflow

import grails.converters.JSON
import grails.converters.XML

class WebServiceController {

    def userService
    def grailsApplication
    def questionService

    def index() {
        render([success: "true", version: grailsApplication.metadata['app.version']])
    }

    def createQuestionFromExternal(){
        def body = request.JSON

        if(body.source == 'ecodata'){
          createQuestionFromEcodata()
        }

        if(body.source == 'biocache'){
            createQuestionFromBiocache()
        }
    }

    def createQuestionFromEcodata(){

        def results = [success:true]
        def body = request.JSON
        if (body) {
            def tags = body.getAggregatedTagsWithCount instanceof String ? body.getAggregatedTagsWithCount.split(",")?.toList() : body.getAggregatedTagsWithCount as List<String>
            def user = userService.getUserFromUserId(body.userId)
            def occurrenceId = body.occurrenceId as String
            def questionType = (body.questionType as QuestionType) ?: QuestionType.IDENTIFICATION
            def serviceResult = questionService.createQuestionFromEcodataService(occurrenceId, questionType, tags, user)

            if (serviceResult) {
                results.success = true
                results.questionId = serviceResult.result?.id
            } else {
                results.success = false
                results.message = serviceResult.combinedMessages
            }
        }
        renderResults(results)
    }

    def createQuestionFromBiocache() {

        def results = [success:true]
        def body = request.JSON
        if (body) {
            def tags = body.getAggregatedTagsWithCount instanceof String ? body.getAggregatedTagsWithCount.split(",")?.toList() : body.getAggregatedTagsWithCount as List<String>
            def occurrenceId = body.occurrenceId as String
            def user = userService.getUserFromUserId(body.userId)
            def questionType = (body.questionType as QuestionType) ?: QuestionType.IDENTIFICATION
            def serviceResult = questionService.createQuestionFromOccurrence(occurrenceId, questionType, tags, user)

            if (serviceResult) {
                results.success = true
                results.questionId = serviceResult.result?.id
            } else {<commit_msg>Fixes some regression introduced by automatic refactoring<commit_after>package au.org.ala.taxonoverflow

import grails.converters.JSON
import grails.converters.XML

class WebServiceController {

    def userService
    def grailsApplication
    def questionService

    def index() {
        render([success: "true", version: grailsApplication.metadata['app.version']])
    }

    def createQuestionFromExternal(){
        def body = request.JSON

        if(body.source == 'ecodata'){
          createQuestionFromEcodata()
        }

        if(body.source == 'biocache'){
            createQuestionFromBiocache()
        }
    }

    def createQuestionFromEcodata(){

        def results = [success:true]
        def body = request.JSON
        if (body) {
            def tags = body.tags instanceof String ? body.tags.split(",")?.toList() : body.tags as List<String>
            def user = userService.getUserFromUserId(body.userId)
            def occurrenceId = body.occurrenceId as String
            def questionType = (body.questionType as QuestionType) ?: QuestionType.IDENTIFICATION
            def serviceResult = questionService.createQuestionFromEcodataService(occurrenceId, questionType, tags, user)

            if (serviceResult) {
                results.success = true
                results.questionId = serviceResult.result?.id
            } else {
                results.success = false
                results.message = serviceResult.combinedMessages
            }
        }
        renderResults(results)
    }

    def createQuestionFromBiocache() {

        def results = [success:true]
        def body = request.JSON
        if (body) {
            def tags = body.tags instanceof String ? body.tags.split(",")?.toList() : body.tags as List<String>
            def occurrenceId = body.occurrenceId as String
            def user = userService.getUserFromUserId(body.userId)
            def questionType = (body.questionType as QuestionType) ?: QuestionType.IDENTIFICATION
            def serviceResult = questionService.createQuestionFromOccurrence(occurrenceId, questionType, tags, user)

            if (serviceResult) {
                results.success = true
                results.questionId = serviceResult.result?.id
            } else {
{'fraction_non_alphanumeric': 0.08369283865401209, 'fraction_numerical': 0.0, 'mean_word_length': 2.3723636363636365, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2146005', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1175, 'n_words': 262}