<commit_before>package com.jpmec.done

import grails.converters.JSON
import grails.plugins.springsecurity.Secured




class TaskController {

    def beforeInterceptor = {
        log.trace("Executing action $actionName with params $params")
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def show = {
      if (params.uuid) {
        def instance = Task.findByUuid(params.uuid)
        if (instance) {
          render instance as JSON
        }
        else {
          render(status:404, text:'{}')
        }
      }
      else {
        render(status:400, text:'{}')
      }
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def update = {
      if (params.uuid) {
        def instance = Task.findByUuid(params.uuid)
        if (instance) {
          instance.properties = params
          if (instance.save()) {
            render instance as JSON
          }
          else {
            render(status:500, text:'{}')
          }
        }
        else {
          render(status:404, text:'{}')
        }
      }
      else {
        render(status:400, text:'{}')
      }
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def save = {
      def new_instance = new Task(params)

      // if a uuid was passed in,
      // then make a copy and add given params
      if (new_instance.uuid) {
        def existing_instance = Task.findByUuid(new_instance.uuid)
        if (existing_instance) {
          new_instance = new Task(existing_instance.properties + params)
        }
        new_instance.uuid = null
      }

      if (new_instance.save()) {
        render new_instance as JSON
      }
      else {
        // return an empty object if there was an error
        render(status: 500, text:'{}')
      }
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def delete = {
      if (params.uuid) {
        def instance = Task.findByUuid(params.uuid)
        if (instance) {
          def copy = new Task(instance.properties)
          instance.delete()
          render copy as JSON
        }
        else {
          render(status:404, text:'{}')
        }
      }
      else {
        render(status:400, text:'{}')
      }
    }

    def afterInterceptor = { model ->
        log.trace("Executed $actionName which resulted in model: $model")
    }
}<commit_msg>grails inverted TaskController logic to return quickly<commit_after>package com.jpmec.done

import grails.converters.JSON
import grails.plugins.springsecurity.Secured




class TaskController {

    def beforeInterceptor = {
        log.trace("Executing action $actionName with params $params")
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def show = {
      if (!params.uuid) {
        render(status:400, text:'{}')
        return
      }

      def instance = Task.findByUuid(params.uuid)

      if (!instance) {
        render(status:404, text:'{}')
        return
      }

      render instance as JSON
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def update = {
      if (!params.uuid) {
        render(status:400, text:'{}')
        return
      }

      def instance = Task.findByUuid(params.uuid)
      if (!instance) {
        render(status:404, text:'{}')
        return
      }

      instance.properties = params
      if (!instance.save()) {
        render(status:500, text:'{}')
        return
      }

      render instance as JSON
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def save = {
      def new_instance = new Task(params)

      // if a uuid was passed in,
      // then make a copy and add given params
      if (new_instance.uuid) {
        def existing_instance = Task.findByUuid(new_instance.uuid)
        if (existing_instance) {
          new_instance = new Task(existing_instance.properties + params)
        }
        new_instance.uuid = null
      }

      if (!new_instance.save()) {
        render(status: 500, text:'{}')
        return
      }

      render new_instance as JSON
    }

//    @Secured(['ROLE_USER', 'IS_AUTHENTICATED_REMEMBERED'])
    def delete = {

      if (!params.uuid) {
        render(status:400, text:'{}')
        return
      }

      def instance = Task.findByUuid(params.uuid)
      if (!instance) {
        render(status:404, text:'{}')
        return
      }

      def copy = new Task(instance.properties)
      instance.delete()
      render copy as JSON
    }

    def afterInterceptor = { model ->
        log.trace("Executed $actionName which resulted in model: $model")
    }
}
{'fraction_non_alphanumeric': 0.11936397299063385, 'fraction_numerical': 0.010455238510128513, 'mean_word_length': 1.972168284789644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3230195', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1379, 'n_words': 307}